Files
gaokao/高考志愿管理.ipynb
512song ad0d0a5396 jupyterlab
jupyterlab项目
2021-03-07 19:16:41 +08:00

5.3 KiB

高考志愿管理

2020年高考录取信息导入MongoDB

In [7]:
import pymysql
import pymongo
import decimal

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["gaokao"]
mycol = mydb["college"]
mycol1 = mydb["admission_2020"]

m_col = {}
m_spe = {}
m_xx = {}
for x in mycol.find({"code":{'$exists': 'true'}},{"_id": 0, "code": 1, "name": 1}):
    m_col[x['code']] = x['name']


db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "gaokao" )
cursor = db.cursor()
sql = 'SELECT a.code,a.college,a.name FROM speciality AS a WHERE a.nian="2020"'
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
    m_spe.setdefault(result[1],{})    
    m_spe[result[1]][result[0]] = result[2]
sql = 'SELECT * FROM admission_2020 AS a ORDER BY a.rank_min'
cursor.execute(sql)
results = cursor.fetchall()
i = 0
m_min = 0
ii = 0
for result in results:
    m_xx.clear()
    if result[6] == m_min:
        ii = ii
        i = i+1
    else:
        i = i+1
        ii = i
        m_min = result[6]
    m_xx['pos'] = ii
    m_xx['col_code'] = result[1]
    m_xx['col_name'] = m_col[result[1]]
    m_xx['spe_code'] = result[2]
    m_xx['spe_name'] = m_spe[result[1]][result[2]]
    m_xx['plan'] = result[3]
    m_xx['dispense'] = result[5]
    m_xx['num_min'] = result[6]
    m_xx['num_avg'] = int(result[7])
    m_xx['rank_min'] = result[8]
    m_xx['nian'] = '2020'    
    mycol1.insert_one(m_xx)
#print(m_spe)

计算志愿分数概率

In [17]:
import random

array2 = []
for i in range(10000):
    array1 = []
    s = 0
    for ii in range(12):
        m1 = random.randint(633,639)
        array1.append(m1)
        s = s + m1    
    m_avg = round(s/12,2)
    if m_avg == 635.5 and (633 in array1) and (639 in array1):
        #print(array1)
        array2.extend(array1)
        
#print(array2)
m_set = set(array2)
for m in m_set:
    print(m,array2.count(m))
633 619
634 556
635 450
636 397
637 328
638 275
639 351
In [18]:
import openpyxl
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["gaokao"]
mycol = mydb["admission_college"]
wb = openpyxl.load_workbook('./data/shandongdaxue.xlsx')
sheet = wb.active
#sheets = wb.sheetnames
code = 'A422'
name = '山东大学'
new_col = []
dict1 = {}

new_code = []
dict1['code'] = code
dict1['name'] = name
for n in range(1,sheet.max_row+1):
    nian = str(sheet.cell(n,1).value)
    dict2 = {}
    
    dict1.setdefault(nian,[])
    if sheet.cell(n,2).value =='理工':
        m_lb = 'l'
    elif sheet.cell(n,2).value =='文史':
        m_lb = 'w'
    else:
        m_lb = 'z'    
    dict2['type'] = m_lb
    dict2['spe_name'] = sheet.cell(n,4).value
    dict2['max_score'] = sheet.cell(n,5).value
    dict2['min_score'] = sheet.cell(n,6).value
    dict2['avg_score'] = sheet.cell(n,7).value
    dict2['dispense'] = sheet.cell(n,8).value
    dict1[nian].append(dict2)
mycol.insert_one(dict1)
Out [18]:
<pymongo.results.InsertOneResult at 0x7fbebaa57e80>
In [ ]: