This commit is contained in:
512song@sina.com committed 2022-08-05 14:19:59 +08:00
1 parent 34c948fb58
commit 268fd87e95
6 files changed
+733 -118

No files matched your search

+434 -18
View File
@@ -286,26 +286,11 @@
},
{
"cell_type": "code",
"execution_count": 112,
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-06-15T09:08:30.396155Z",
"iopub.status.busy": "2022-06-15T09:08:30.395636Z",
"iopub.status.idle": "2022-06-15T09:08:39.230104Z",
"shell.execute_reply": "2022-06-15T09:08:39.228838Z",
"shell.execute_reply.started": "2022-06-15T09:08:30.396108Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"outputs": [],
"source": [
"import pymysql\n",
"import pymongo\n",
@@ -751,7 +736,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"## 导入2021年录取数据"
]
@@ -1005,6 +992,390 @@
"db.close() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 导入2022年录取数据"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 导出2022年录取数据并生成分数"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"filename = 'data/17-22年一分一段表.json'\n",
"with open(filename,'r') as fl:\n",
" m_xx = json.load(fl)\n",
"data = m_xx['2022']['z']\n",
"yfyd = {}\n",
"for k, v in data.items():\n",
" list1 = []\n",
" list1 = (v['min_rank'],v['max_rank'])\n",
" yfyd[k] = list1\n",
"dict1 = {}\n",
"filename = 'data/山东省2022年普通类常规批第一次志愿投档情况表.xlsx'\n",
"wb = openpyxl.load_workbook(filename)\n",
"sheet = wb.active\n",
"data1 =list(sheet.values)\n",
"del data1[0:2]\n",
"m_num = 1\n",
"i = 1\n",
"for items in data1:\n",
" m_rank = items[3] \n",
" list1 = []\n",
" for k, v in yfyd.items():\n",
" if m_rank >=v[1] and m_rank <=v[0]:\n",
" m_num = int(k)\n",
" break\n",
" list1 = (items[0],items[1],items[2],items[3],m_num)\n",
" dict1[i] = list1\n",
" i += 1 \n",
"with open('data/2022.json','w') as fl2:\n",
" json.dump(dict1,fl2) \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2022年录取数据导入mysql数据库"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pymysql\n",
"import json\n",
"\n",
"l_code = []\n",
"l_new = []\n",
"l_data = []\n",
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"\n",
"sql = 'select code from college'\n",
"cursor.execute(sql)\n",
"results = cursor.fetchall()\n",
"for result in results:\n",
" l_code.append(result[0])\n",
"\n",
"with open('data/2022.json','r') as fl:\n",
" m_xx = json.load(fl)\n",
"for k, v in m_xx.items():\n",
" #code = v[1][:4]\n",
" l_data.append([v[1][:4],v[0][:2],v[2],v[4],v[3]])\n",
"\n",
"sql = \"insert into admission_2022 (college,speciality,plan,num_min,rank_min,nian) values(%s,%s,%s,%s,%s,'2022')\"\n",
"try:\n",
" cursor.executemany(sql,l_data)\n",
" db.commit()\n",
" print(\"已添加!\")\n",
"except:\n",
" # 如果发生错误则回滚\n",
" print(\"error!\")\n",
" db.rollback() \n",
"db.close() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 整理2022年招生学校"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"import json\n",
"\n",
"l_code = []\n",
"l_new = []\n",
"l_data = []\n",
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"\n",
"sql = 'select code from college'\n",
"cursor.execute(sql)\n",
"results = cursor.fetchall()\n",
"for result in results:\n",
" l_code.append(result[0])\n",
"\n",
"with open('data/2022.json','r') as fl:\n",
" m_xx = json.load(fl)\n",
"for k, v in m_xx.items():\n",
" code = v[1][:4]\n",
" if code not in l_code:\n",
" l_code.append(code)\n",
" l_new.append([v[1][0:4],v[1][4:]])\n",
" #l_data.append([v[1][:4],v[0][:2],v[2],v[4],v[3]])\n",
"sql = \"insert into college (code,name) values(%s,%s)\"\n",
"try:\n",
" cursor.executemany(sql,l_new)\n",
" db.commit()\n",
" print(\"已添加!\")\n",
"except:\n",
" # 如果发生错误则回滚\n",
" print(\"error!\")\n",
" db.rollback() \n",
"db.close() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 整理2022年新增招生学校"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pymongo\n",
"import decimal\n",
"import json\n",
"\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"gaokao\"]\n",
"mycol = mydb[\"college_2021\"]\n",
"mycol1 = mydb[\"admission_2021\"]\n",
"\n",
"m_col = {}\n",
"m_xx = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"for x in mycol.find({\"code\":{'$exists': 'true'}},{\"_id\": 0, \"code\": 1, \"name\": 1}):\n",
" m_col[x['code']] = x['name']\n",
"\n",
"with open('data/2022.json','r') as fl:\n",
" m_xx = json.load(fl)\n",
"for k, v in m_xx.items():\n",
" #code = v[1][:4]\n",
" dict1[v[1][:4]]= v[1][4:]\n",
"for code in dict1.keys():\n",
" if code not in m_col.keys():\n",
" #print(dict1[code])\n",
" \n",
" if dict1[code] not in m_col.values():\n",
" list1.append(code)\n",
"print(list1)\n",
"for x in mycol.find({\"id_code\":{'$exists': 'true'}},{\"_id\": 0, \"id_code\": 1, \"name\": 1}):\n",
" m_col[x['id_code']] = x['name']\n",
"for code in list1:\n",
" if dict1[code] in m_col.values():\n",
" myquery = {'name':dict1[code]}\n",
" m_new = {\"$set\":{'code':code}}\n",
" mycol.update_one(myquery,m_new)\n",
" print(dict1[code])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 汇总2022年学校录取情况"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pymysql\n",
"import pymongo\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"gaokao\"]\n",
"mycol = mydb[\"college_2021\"]\n",
"m_xx = {}\n",
"m_data = {}\n",
"m_mongo = {}\n",
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"sql = 'SELECT college,SUM(plan),min(num_min),max(RANK_min) FROM admission_2022 GROUP BY college'\n",
"cursor.execute(sql)\n",
"results = cursor.fetchall()\n",
"i = 1\n",
"for result in results:\n",
" #m_xx.clear()\n",
" m_code = result[0]\n",
" m_nian ='2022'\n",
" m_lb = 'z'\n",
" m_xx.setdefault(m_code,{})\n",
" m_xx[m_code].setdefault(m_nian,{})\n",
" m_xx[m_code][m_nian].setdefault(m_lb,{})\n",
" m_xx[m_code][m_nian][m_lb] ['name']= '综合'\n",
" m_xx[m_code][m_nian][m_lb] ['dispense']= int(result[1])\n",
" m_xx[m_code][m_nian][m_lb] ['num_min']= result[2]\n",
" m_xx[m_code][m_nian][m_lb] ['rank_min']= result[3] \n",
" myquery = {'code':m_code}\n",
" colleges = mycol.find(myquery,{ \"_id\": 0, \"admission\": 1 })\n",
" for x in colleges:\n",
" for k, v in x.items():\n",
" for k1, v1 in v.items():\n",
" m_xx[m_code][k1] = v1\n",
"for k,v in m_xx.items():\n",
" #m_item ='admission.'+m_nian\n",
" m_mongo.clear() \n",
" myquery = {'code':k}\n",
" m_new = {\"$set\":{'admission':v}}\n",
" mycol.update_one(myquery,m_new)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 整理2022年新增专业"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"import json\n",
"\n",
"l_data = []\n",
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"\n",
"with open('data/2022.json','r') as fl:\n",
" m_xx = json.load(fl)\n",
"for k, v in m_xx.items():\n",
" l_data.append([v[0][:2],v[0][2:],v[1][0:4],'2022'])\n",
"sql = \"insert into speciality (code,name,college,nian) values(%s,%s,%s,%s)\"\n",
"try:\n",
" cursor.executemany(sql,l_data)\n",
" db.commit()\n",
" print(\"已添加!\")\n",
"except:\n",
" # 如果发生错误则回滚\n",
" print(\"error!\")\n",
" db.rollback() \n",
"db.close() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2022年专业录取分数及位次"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-04T03:53:00.735786Z",
"iopub.status.busy": "2022-08-04T03:53:00.735257Z",
"iopub.status.idle": "2022-08-04T03:53:10.194351Z",
"shell.execute_reply": "2022-08-04T03:53:10.192776Z",
"shell.execute_reply.started": "2022-08-04T03:53:00.735737Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import pymysql\n",
"import pymongo\n",
"import decimal\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"gaokao\"]\n",
"mycol = mydb[\"college_2021\"]\n",
"mycol1 = mydb[\"admission_2022\"]\n",
"\n",
"m_col = {}\n",
"m_spe = {}\n",
"m_xx = {}\n",
"for x in mycol.find({\"code\":{'$exists': 'true'}},{\"_id\": 0, \"code\": 1, \"name\": 1}):\n",
" m_col[x['code']] = x['name']\n",
"\n",
"\n",
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"sql = 'SELECT a.code,a.college,a.name FROM speciality AS a WHERE a.nian=\"2022\"'\n",
"cursor.execute(sql)\n",
"results = cursor.fetchall()\n",
"for result in results:\n",
" m_spe.setdefault(result[1],{}) \n",
" m_spe[result[1]][result[0]] = result[2]\n",
"#print(m_spe)\n",
"sql = 'SELECT * FROM admission_2022 AS a where college not in (\"D628\",\"D440\",\"Y010\",\"D245\",\"D597\",\"D641\",\"D501\",\"D659\") ORDER BY a.rank_min'\n",
"#sql = 'SELECT * FROM admission_2022 AS a ORDER BY a.rank_min'\n",
"cursor.execute(sql)\n",
"results = cursor.fetchall()\n",
"i = 0\n",
"m_min = 0\n",
"ii = 0\n",
"for result in results:\n",
" m_xx.clear()\n",
" if result[4] == m_min:\n",
" ii = ii\n",
" i = i+1\n",
" else:\n",
" i = i+1\n",
" ii = i\n",
" m_min = result[6]\n",
" \n",
" m_xx['pos'] = ii\n",
" m_xx['col_code'] = result[1]\n",
" m_xx['col_name'] = m_col[result[1]]\n",
" m_xx['spe_code'] = result[2]\n",
" m_xx['spe_name'] = m_spe[result[1]][result[2]]\n",
" m_xx['plan'] = result[3]\n",
" m_xx['num_min'] = result[4] \n",
" m_xx['rank_min'] = result[5]\n",
" m_xx['nian'] = '2022' \n",
" mycol1.insert_one(m_xx)\n",
" #print(m_xx)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1161,6 +1532,51 @@
"db.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 导入2022年一分一段表"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import pymysql\n",
"import json\n",
"\n",
"m_xx = []\n",
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
"cursor = db.cursor()\n",
"wb = openpyxl.load_workbook('./data/2022一分一段表.xlsx')\n",
"sheet = wb.active\n",
"i = 1\n",
"for n in range(4,sheet.max_row):\n",
" m_score = sheet.cell(n,1).value\n",
" m_num = sheet.cell(n,2).value\n",
" m_sum = sheet.cell(n,3).value\n",
" m_max = m_sum - m_num + 1\n",
" m_xx.append((m_score,m_num,m_max,m_sum,'z','2022'))\n",
"#print(m_xx)\n",
"sql = 'insert into fenduan(score,per_num,max_rank,min_rank,category,nian) values (%s,%s,%s,%s,%s,%s)'\n",
"try:\n",
" cursor.executemany(sql,m_xx)\n",
" db.commit()\n",
" print(\"ok!\")\n",
"except:\n",
" # 如果发生错误则回滚\n",
" print(\"error!\")\n",
" db.rollback() \n",
"\n",
"db.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},