diff --git a/.ipynb_checkpoints/中医体质管理-checkpoint.ipynb b/.ipynb_checkpoints/中医体质管理-checkpoint.ipynb new file mode 100644 index 0000000..966a03e --- /dev/null +++ b/.ipynb_checkpoints/中医体质管理-checkpoint.ipynb @@ -0,0 +1,100 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "86c59eaa-b1fd-47f3-aa0d-3ad3626df3bf", + "metadata": {}, + "source": [ + "# 中医体质管理" + ] + }, + { + "cell_type": "markdown", + "id": "e791846d-699f-4803-b898-bda8f1a30dd2", + "metadata": {}, + "source": [ + "## 中医体质数据管理" + ] + }, + { + "cell_type": "markdown", + "id": "19cd094e-8228-4f21-9897-9e8bef990d4e", + "metadata": {}, + "source": [ + "### 体质监测数据生成" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "1f58bd08-d20b-4a76-a841-ac7e132a54b7", + "metadata": { + "execution": { + "iopub.execute_input": "2022-08-05T05:39:03.670486Z", + "iopub.status.busy": "2022-08-05T05:39:03.669966Z", + "iopub.status.idle": "2022-08-05T05:39:03.705022Z", + "shell.execute_reply": "2022-08-05T05:39:03.703508Z", + "shell.execute_reply.started": "2022-08-05T05:39:03.670438Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "import re\n", + "import json\n", + "\n", + "file_name = 'data/132.txt'\n", + "list1 =[]\n", + "dict1 = {}\n", + "with open(file_name,'r') as fl:\n", + " for l in fl:\n", + " list2 = []\n", + " l = re.sub('[\\r\\n\\f ]{1,}', '', l)\n", + " list2 = l.split(',')\n", + " if list2[0] != '' and list2[5] != '':\n", + " dict1[list2[0]] = [list2[1],list2[2],list2[3],list2[4],list2[5]+list2[6]]\n", + "filename = 'data/132中医体质.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl) \n", + "print('ok')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "400f6c4b-8a67-4872-a912-a0aad86e923c", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/体质检测管理.ipynb b/体质检测管理.ipynb index d6dc0da..3cbfc32 100644 --- a/体质检测管理.ipynb +++ b/体质检测管理.ipynb @@ -14,6 +14,8 @@ "cell_type": "markdown", "id": "2a85feec-695b-4ea8-8093-91a59ed34c7f", "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [], "toc-hr-collapsed": true }, "source": [ @@ -528,7 +530,10 @@ { "cell_type": "markdown", "id": "54d4790d-973f-4ee6-abff-3d5ff962de23", - "metadata": {}, + "metadata": { + "tags": [], + "toc-hr-collapsed": true + }, "source": [ "## 获取测试人员名单导入数据库" ] @@ -1442,12 +1447,24 @@ "#print(dict1)\n" ] }, + { + "cell_type": "markdown", + "id": "3711130b-59e3-4844-ac31-234ba77cd46c", + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [], + "toc-hr-collapsed": true + }, + "source": [ + "## 脊柱症状统计" + ] + }, { "cell_type": "markdown", "id": "c67fc14e-ccf8-41c5-a0f8-0c3a664eb484", "metadata": {}, "source": [ - "## 脊椎代码表导入" + "### 脊椎代码表导入" ] }, { @@ -1479,7 +1496,7 @@ "id": "36717021-5c0e-40d6-8988-dfe8ec309275", "metadata": {}, "source": [ - "## 脊椎症状自我诊断表导入" + "### 脊椎症状自我诊断表导入" ] }, { @@ -1522,16 +1539,6 @@ "print('ok')" ] }, - { - "cell_type": "markdown", - "id": "3711130b-59e3-4844-ac31-234ba77cd46c", - "metadata": { - "tags": [] - }, - "source": [ - "## 脊柱症状统计" - ] - }, { "cell_type": "markdown", "id": "ae25fffb-4682-49b1-90aa-218504ac88d7", @@ -2281,7 +2288,9 @@ { "cell_type": "markdown", "id": "f9e61ba9-38f8-4b61-bf1e-4e7bbde4f32c", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ "## 心理健康量表统计导入" ] @@ -2323,7 +2332,7 @@ "id": "f400d470-d51e-4226-a1c4-54ac711c7f38", "metadata": {}, "source": [ - "## 查询心理健康量表编号重复" + "### 查询心理健康量表编号重复" ] }, { @@ -2357,7 +2366,7 @@ "id": "641cc9a9-45b2-4b81-953c-75d3a27e35d5", "metadata": {}, "source": [ - "## 统计导入JSON文件记录数" + "### 统计导入JSON文件记录数" ] }, { diff --git a/文件操作.ipynb b/文件操作.ipynb index 622c1bb..04900c6 100644 --- a/文件操作.ipynb +++ b/文件操作.ipynb @@ -17,16 +17,18 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import os,sys,shutil\n", "import openpyxl\n", "import math\n", "\n", - "fi_xls = os.getcwd()+'/file/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx'\n", + "fi_xls = os.getcwd()+'/file/高新区.xlsx'\n", "fi_name = {}\n", - "fi_path = os.getcwd()+'/file/210924'\n", + "fi_path = os.getcwd()+'/file/220720'\n", "old = []\n", "new = []\n", "dict1 = {}\n", @@ -35,19 +37,20 @@ "sheet = wb.active\n", "depart = []\n", "for n in range(2,sheet.max_row+1):\n", - " \n", - " m_name = sheet.cell(n,1).value.strip()\n", - " m_depart = sheet.cell(n,5).value\n", - " if m_depart not in depart:\n", - " depart.append(sheet.cell(n,5).value)\n", - " dict1[int(m_name.split('.')[0])] = [sheet.cell(n,2).value.strip(),sheet.cell(n,5).value.strip()]\n", + " if sheet.cell(n,3).value is not None: \n", + " m_name = sheet.cell(n,6).value.strip()\n", + " m_depart = sheet.cell(n,3).value.strip() \n", + " depart.append(m_depart) \n", + " dict1[int(sheet.cell(n,4).value)] = [m_name,m_depart]\n", " #print()\n", "# 创建部门办公室 \n", - "#m_path = fi_path = os.getcwd()+'/file/210924/new'\n", - "#for pn in depart:\n", - "# if not os.path.exists(m_path + '/' + pn):\n", - "# os.mkdir(m_path + '/' + pn)\n", + "m_path = os.getcwd()+'/file/220720/new'\n", + "for pn in depart:\n", + " if not os.path.exists(m_path + '/' + pn):\n", + " os.mkdir(m_path + '/' + pn)\n", "#print(dict1)\n", + "\n", + "\n", "fl=os.listdir(fi_path)\n", "for fn in fl:\n", " if os.path.isfile(fi_path + '/' + fn):\n", @@ -56,17 +59,17 @@ " #print(fn)\n", "old.sort()\n", " #print(str(nfn)+'.pdf')\n", - "'''\n", + "\n", "for n in old:\n", " \n", " o_name = f'{fi_path}/{n}.pdf'\n", - " n_name = f'{fi_path}/new/{dict1[n][1]}/{dict1[n][0]}.pdf'\n", + " n_name = f'{fi_path}/new/{dict1[n][1]}/{str(n).rjust(5,\"0\")}-{dict1[n][0]}.pdf'\n", " if not os.path.exists(n_name):\n", " shutil.copyfile(o_name,n_name)\n", " print(n_name)\n", "#print(old)\n", - "'''\n", - "print(dict1)" + "\n", + "#print(dict1)" ] }, { diff --git a/文件管理1.ipynb b/文件管理1.ipynb index 7e0e53c..28632d0 100755 --- a/文件管理1.ipynb +++ b/文件管理1.ipynb @@ -29,8 +29,8 @@ "import openpyxl\n", "import math\n", "\n", - "fi_xls = os.getcwd() + '/data/岳阳兴长.xlsx'\n", - "fi_path = os.getcwd() + '/file/220427'\n", + "fi_xls = os.getcwd() + '/data/高新区.xlsx'\n", + "fi_path = os.getcwd() + '/file/220720'\n", "old = []\n", "dict1 = {}\n", "\n", @@ -126,9 +126,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "a34c9f6b-4ef3-4678-89bb-8b692e183968", "metadata": { + "execution": { + "iopub.execute_input": "2022-07-31T13:49:49.854261Z", + "iopub.status.busy": "2022-07-31T13:49:49.853622Z", + "iopub.status.idle": "2022-07-31T13:49:50.369847Z", + "shell.execute_reply": "2022-07-31T13:49:50.368685Z", + "shell.execute_reply.started": "2022-07-31T13:49:49.854177Z" + }, "tags": [] }, "outputs": [], diff --git a/高考志愿管理.ipynb b/高考志愿管理.ipynb index e1c5622..8a34a3e 100644 --- a/高考志愿管理.ipynb +++ b/高考志愿管理.ipynb @@ -95,15 +95,8 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": { - "execution": { - "iopub.execute_input": "2022-06-15T07:00:27.890983Z", - "iopub.status.busy": "2022-06-15T07:00:27.890444Z", - "iopub.status.idle": "2022-06-15T07:00:28.430955Z", - "shell.execute_reply": "2022-06-15T07:00:28.429949Z", - "shell.execute_reply.started": "2022-06-15T07:00:27.890936Z" - }, "tags": [] }, "outputs": [], @@ -135,65 +128,11 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": { - "execution": { - "iopub.execute_input": "2022-06-15T08:26:50.903511Z", - "iopub.status.busy": "2022-06-15T08:26:50.902972Z", - "iopub.status.idle": "2022-06-15T08:26:50.972239Z", - "shell.execute_reply": "2022-06-15T08:26:50.971224Z", - "shell.execute_reply.started": "2022-06-15T08:26:50.903463Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "河北工业职业技术大学导入成功!\n", - "河北科技工程职业技术大学导入成功!\n", - "河北石油职业技术大学导入成功!\n", - "邢台应用技术职业学院导入成功!\n", - "山西工程科技职业大学导入成功!\n", - "吉林通用航空职业技术学院导入成功!\n", - "通化医药健康职业学院导入成功!\n", - "上海南湖职业技术学院导入成功!\n", - "浙江药科职业大学导入成功!\n", - "浙江金华科贸职业技术学院导入成功!\n", - "宿州航空职业学院导入成功!\n", - "和君职业学院导入成功!\n", - "滨州科技职业学院导入成功!\n", - "洛阳文化旅游职业学院导入成功!\n", - "周口文理职业学院导入成功!\n", - "信阳艺术职业学院导入成功!\n", - "郑州城建职业学院导入成功!\n", - "郑州医药健康职业学院导入成功!\n", - "湖北孝感美珈职业学院导入成功!\n", - "广州幼儿师范高等专科学校导入成功!\n", - "广东汕头幼儿师范高等专科学校导入成功!\n", - "广东梅州职业技术学院导入成功!\n", - "广东潮州卫生健康职业学院导入成功!\n", - "广东云浮中医药职业学院导入成功!\n", - "广东肇庆航空职业学院导入成功!\n", - "广西农业职业技术大学导入成功!\n", - "防城港职业技术学院导入成功!\n", - "广西信息职业技术学院导入成功!\n", - "广西农业工程职业技术学院导入成功!\n", - "北海康养职业学院导入成功!\n", - "重庆工信职业学院导入成功!\n", - "甘孜职业学院导入成功!\n", - "自贡职业技术学院导入成功!\n", - "贵阳康养职业大学导入成功!\n", - "贵州文化旅游职业学院导入成功!\n", - "宝鸡中北职业学院导入成功!\n", - "兰州石化职业技术大学导入成功!\n", - "兰州资源环境职业技术大学导入成功!\n", - "兰州航空职业技术学院导入成功!\n", - "白银希望职业技术学院导入成功!\n" - ] - } - ], + "outputs": [], "source": [ "import openpyxl\n", "import json\n", @@ -548,6 +487,147 @@ "print(list2)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2022年高考选科数据分析" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2022年选科数据导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import json\n", + "import pymongo\n", + "\n", + "filename = 'data/2022招生计划(汇总).json'\n", + "with open(filename,'r') as fl:\n", + " m_xx = json.load(fl)\n", + "#print(m_xx)\n", + "xuanke = []\n", + "dict1 = {}\n", + "dict2 = {}\n", + "dict2['0'] = '不限'\n", + "dict2['1'] = '物理和化学和生物'\n", + "dict2['2'] = '思想政治和历史和地理'\n", + "dict3 = {}\n", + "for k, v in m_xx.items():\n", + " col_code = k\n", + " col_name = v['学校名称']\n", + " for item in v['专业']:\n", + " m_code = col_code+'-'+item['unit_code']\n", + " m_name = item['unit_name']\n", + " m_xuanke = item['xuanke'].strip()\n", + " if m_xuanke not in xuanke:\n", + " xuanke.append(m_xuanke)\n", + " dict1[m_code] = [m_name,m_xuanke]\n", + "fl_name = 'data/2022年选科分析表.json'\n", + "with open(fl_name,'w') as fl:\n", + " json.dump(dict1,fl)\n", + "xuanke.remove('不限')\n", + "xuanke.remove('物理和化学和生物')\n", + "xuanke.remove('思想政治和历史和地理')\n", + "print(xuanke)\n", + "dict3['不限'] = [1,'0',['物理','化学','生物','思想政治','历史','地理']]\n", + "dict3['物理和化学和生物'] = [2,'1',['物理','化学','生物']]\n", + "dict3['思想政治和历史和地理'] = [3,'1',['思想政治','历史','地理']]\n", + "i = 4\n", + "for item in xuanke:\n", + " #dict3[str(i)].setdault({})\n", + " if '和' in item:\n", + " mx = item.split('和')\n", + " dict3[item] = [i,'1',mx]\n", + " elif '或' in item:\n", + " mx = item.split('或')\n", + " dict3[item] = [i,'0',mx]\n", + " else:\n", + " dict3[item] = [i,'0',[item]]\n", + " i+=1\n", + "fl_name = 'data/选科代码表.json'\n", + "with open(fl_name,'w') as fl:\n", + " json.dump(dict3,fl)\n", + "print('ok!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 选科数据导入Mysql" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "execution": { + "iopub.execute_input": "2022-08-04T06:47:19.617840Z", + "iopub.status.busy": "2022-08-04T06:47:19.617316Z", + "iopub.status.idle": "2022-08-04T06:47:20.416287Z", + "shell.execute_reply": "2022-08-04T06:47:20.414857Z", + "shell.execute_reply.started": "2022-08-04T06:47:19.617790Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok!\n" + ] + } + ], + "source": [ + "import pymysql\n", + "import json\n", + "\n", + "filename = 'data/选科代码表.json'\n", + "with open(filename,'r') as fl:\n", + " dmb = json.load(fl)\n", + "\n", + "filename = 'data/2022年选科分析表.json'\n", + "with open(filename,'r') as fl:\n", + " jhb = json.load(fl) \n", + "list1 = []\n", + "db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n", + "cursor = db.cursor()\n", + "\n", + "sql = 'select college,speciality,rank_min from admission_2022 order by rank_min'\n", + "cursor.execute(sql)\n", + "results = cursor.fetchall()\n", + "for result in results:\n", + " m_dm = result[0]+'-'+result[1]\n", + " if m_dm in jhb.keys():\n", + " m_xk = jhb[m_dm][1].strip()\n", + " m_item = ','.join(dmb[m_xk][2])\n", + " list1.append((result[0],result[1],str(dmb[m_xk][0]),m_item))\n", + "\n", + "sql = 'insert into zhiyuanfenxi (col_code,spe_code,zy_code,item) values (%s,%s,%s,%s)'\n", + "try:\n", + " cursor.executemany(sql,list1)\n", + " db.commit()\n", + " print(\"ok!\")\n", + "except:\n", + " # 如果发生错误则回滚\n", + " print(\"error!\")\n", + " db.rollback() \n", + "\n", + "db.close()" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/高考数据导入.ipynb b/高考数据导入.ipynb index 45aa074..e81b3a9 100644 --- a/高考数据导入.ipynb +++ b/高考数据导入.ipynb @@ -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": {},