577 lines
16 KiB
Plaintext
577 lines
16 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4925cb3a-bea3-4a4d-9590-6b91b62ca5b4",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 体质检测管理"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2a85feec-695b-4ea8-8093-91a59ed34c7f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 体测单位信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c5a0568c-3833-4335-a4b9-600310e1a541",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"unit\"]\n",
|
|
"\n",
|
|
"name = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
|
"short_name = '安庆炼化'\n",
|
|
"myquery = { \"name\": name}\n",
|
|
"if mycol.find_one(myquery) is None: \n",
|
|
" wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n",
|
|
" sheet = wb.active\n",
|
|
" #sheets = wb.sheetnames\n",
|
|
" depart = []\n",
|
|
" dict1 = {}\n",
|
|
" new_code = []\n",
|
|
" for n in range(2,sheet.max_row+1):\n",
|
|
" m_depart = sheet.cell(n,5).value\n",
|
|
" if m_depart not in depart:\n",
|
|
" depart.append(sheet.cell(n,5).value)\n",
|
|
" #print(sheet.cell(n,5).value)\n",
|
|
"\n",
|
|
" dict1['name'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
|
" dict1['short_name'] = '安庆炼化'\n",
|
|
" dict1['depart'] = depart\n",
|
|
" mycol.insert_one(dict1)\n",
|
|
" print('ok!')\n",
|
|
"else:\n",
|
|
" print('该单位已存在!') \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "bf42e8af-a506-4e60-a661-b4281e3fef54",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 录入体测信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 77,
|
|
"id": "91a8f4f4-c417-4db7-94ba-2d3404e5c2c9",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-18T02:34:07.188682Z",
|
|
"iopub.status.busy": "2021-10-18T02:34:07.187761Z",
|
|
"iopub.status.idle": "2021-10-18T02:34:07.230533Z",
|
|
"shell.execute_reply": "2021-10-18T02:34:07.227725Z",
|
|
"shell.execute_reply.started": "2021-10-18T02:34:07.188577Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"from bson.objectid import ObjectId\n",
|
|
"from dateutil import parser\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"unit\"]\n",
|
|
"mycol1 = mydb[\"event\"]\n",
|
|
"dict1 = {}\n",
|
|
"\n",
|
|
"name = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
|
"myquery = { \"name\": name}\n",
|
|
"dict1['code'] = 120\n",
|
|
"dict1['unit'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
|
|
"dict1['address'] = '安徽安庆'\n",
|
|
"dict1['date_begin'] ='2021-09-08'\n",
|
|
"dict1['date_end'] = '2021-09-30'\n",
|
|
"if mycol.find_one(myquery) is None: \n",
|
|
" print('体测单位不存在!')\n",
|
|
"else:\n",
|
|
" myquery1 = { \"code\": dict1['code']}\n",
|
|
" if mycol1.find_one(myquery1) is None:\n",
|
|
" mycol1.insert_one(dict1)\n",
|
|
" print('ok!')\n",
|
|
" else:\n",
|
|
" print('该体测信息已经存在!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0c144068-4f2d-4901-bd28-725ecb260fd4",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出单位员工信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d80c482d-aee2-45cf-8ac8-c357171f17f7",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"from bson.objectid import ObjectId\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"person\"]\n",
|
|
"\n",
|
|
"wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"#sheets = wb.sheetnames\n",
|
|
"list1 = []\n",
|
|
"person = {}\n",
|
|
"new_code = []\n",
|
|
"for n in range(2,sheet.max_row+1):\n",
|
|
" code = sheet.cell(n,1).value\n",
|
|
" person.setdefault(code,{})\n",
|
|
" dict1 = {} \n",
|
|
" dict1['name'] = sheet.cell(n,2).value\n",
|
|
" dict1['sex'] = sheet.cell(n,3).value\n",
|
|
" dict1['unit'] = sheet.cell(n,5).value\n",
|
|
" if sheet.cell(n,4).value is None:\n",
|
|
" dict1['birth'] = sheet.cell(n,6).value\n",
|
|
" else:\n",
|
|
" dict1['id_num'] = sheet.cell(n,4).value\n",
|
|
" person[code] = dict1\n",
|
|
"filename = '安庆炼化人员名单.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(person, fl,ensure_ascii=False) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "54d4790d-973f-4ee6-abff-3d5ff962de23",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取测试人员名单导入数据库"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 79,
|
|
"id": "82e1b982-3c88-4f01-ad94-49177c4a46f6",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-18T02:36:32.491973Z",
|
|
"iopub.status.busy": "2021-10-18T02:36:32.491036Z",
|
|
"iopub.status.idle": "2021-10-18T02:36:34.395918Z",
|
|
"shell.execute_reply": "2021-10-18T02:36:34.393177Z",
|
|
"shell.execute_reply.started": "2021-10-18T02:36:32.491866Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<pymongo.results.InsertManyResult object at 0x7f6f28531ec0>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"from bson.objectid import ObjectId\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"person\"]\n",
|
|
"\n",
|
|
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"\n",
|
|
"place_id = 120\n",
|
|
"exam_person = []\n",
|
|
"sql = f'SELECT distinct a.avatar_id FROM places_result AS a WHERE a.place_id={place_id} and a.avatar_id < 4999 ORDER BY a.avatar_id '\n",
|
|
"cursor.execute(sql)\n",
|
|
"results = cursor.fetchall()\n",
|
|
"cursor.close\n",
|
|
"for result in results:\n",
|
|
" exam_person.append(str(result[0]).rjust(5,'0'))\n",
|
|
"\n",
|
|
"filename = '安庆炼化人员名单.json'\n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"list2 = []\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" all_person = json.load(fl)\n",
|
|
"with open('result.json','r') as fl1:\n",
|
|
" res = json.load(fl1)\n",
|
|
"for k,v in all_person.items():\n",
|
|
" if k in exam_person:\n",
|
|
" dict2 = {}\n",
|
|
" dict3 = {}\n",
|
|
" dict2['name'] = v['name']\n",
|
|
" if v['sex'] == '男':\n",
|
|
" dict2['sex'] = 'M'\n",
|
|
" else:\n",
|
|
" dict2['sex'] = 'F'\n",
|
|
" if 'birth' in v:\n",
|
|
" s = str(v['birth'])\n",
|
|
" dict2['birth'] = f'{s[:4]}-{s[4:6]}-{s[6:8]}'\n",
|
|
" if 'id_num' in v:\n",
|
|
" s = v['id_num']\n",
|
|
" dict2['id_num'] = s\n",
|
|
" dict2['birth'] = f'{s[6:10]}-{s[10:12]}-{s[12:14]}'\n",
|
|
" dict2.setdefault('exam',[])\n",
|
|
" dict3['code'] = 120\n",
|
|
" dict3['sn'] = k\n",
|
|
" dict3['result'] = res[k]\n",
|
|
" dict2['exam'].append(dict3)\n",
|
|
"\n",
|
|
" list1.append(dict2)\n",
|
|
"x = mycol.insert_many(list1)\n",
|
|
"mycol1 = mydb[\"event\"]\n",
|
|
"myquery = {'code':120}\n",
|
|
"mycol1.update_one(myquery,{'$push':{'persons':x.inserted_ids}})\n",
|
|
"print('ok!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "95ad1920-1393-4830-a48a-540070b51a09",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 测试项目添加测试人员名单"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "adf13de2-8205-4511-a655-75989440967e",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"from bson.objectid import ObjectId\n",
|
|
"import pymongo\n",
|
|
"import pymysql\n",
|
|
"\n",
|
|
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"sql = f'SELECT distinct a.avatar_id FROM places_result AS a WHERE a.place_id={place_id} and a.avatar_id < 4999 ORDER BY a.avatar_id '\n",
|
|
"cursor.execute(sql)\n",
|
|
"results = cursor.fetchall()\n",
|
|
"cursor.close\n",
|
|
"for result in results:\n",
|
|
" list1.append(str(result[0]).rjust(5,'0'))\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"tice\"]\n",
|
|
"mycol = mydb[\"event\"]\n",
|
|
"myquery = {'code':120}\n",
|
|
"mycol.update_one(myquery,{'$push':{'persons':list1}})\n",
|
|
" \n",
|
|
"print('ok')\n",
|
|
" \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "44149ba0-1730-43d4-b07f-82a53dca4ce4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2bb3cbdd-9fe1-4345-8c5a-53acb1a386de",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取人员测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 75,
|
|
"id": "910c3fcd-121a-42c0-9465-ad79a5829239",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-18T02:29:20.586805Z",
|
|
"iopub.status.busy": "2021-10-18T02:29:20.585860Z",
|
|
"iopub.status.idle": "2021-10-18T02:29:24.051120Z",
|
|
"shell.execute_reply": "2021-10-18T02:29:24.049117Z",
|
|
"shell.execute_reply.started": "2021-10-18T02:29:20.586699Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"运动项目信息:\n",
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"import json\n",
|
|
"import time\n",
|
|
"\n",
|
|
"filename = 'item.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" item[k] = v\n",
|
|
"user_id = 5\n",
|
|
"place_id =120\n",
|
|
"#user = '包永'\n",
|
|
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"\n",
|
|
"sql = f'SELECT a.item_id,a.performance,a.score,DATE_FORMAT(a.date,\"%Y-%m-%d\") as date1,a.avatar_id FROM places_result AS a WHERE a.place_id={place_id} AND a.avatar_id < 4999 ORDER BY a.avatar_id,date1'\n",
|
|
"cursor.execute(sql)\n",
|
|
"re_ta = {}\n",
|
|
"dict1 = {}\n",
|
|
"print(\"\\n运动项目信息:\")\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results: \n",
|
|
" user = str(result[4]).rjust(5,'0')\n",
|
|
" m_item = str(result[0])\n",
|
|
" \n",
|
|
" re_ta.setdefault(user,{})\n",
|
|
" re_ta[user]['date'] =result[3]\n",
|
|
" item_name = item[m_item]['name']\n",
|
|
" re_ta[user].setdefault(item_name,{})\n",
|
|
" \n",
|
|
" #dict1.setdefault(item[m_item]['name'],{})\n",
|
|
" score = result[1]/item[m_item]['divisor']\n",
|
|
" #dict1[item[m_item]['name']]['成绩'] =f'{score} {item[m_item][\"unit\"]}'\n",
|
|
" #dict1[item[m_item]['name']]['得分'] =result[2]\n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
" re_ta[user][item_name]['得分'] =result[2]\n",
|
|
" \n",
|
|
" #re_ta[user] = dict1\n",
|
|
" #print(re_ta)\n",
|
|
"filename = 'result.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(re_ta, fl,ensure_ascii=False) \n",
|
|
"print('ok')\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "43cc57b0-aebc-4315-b48f-9268e754bebb",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 读取体测报告信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5ac5e20c-c836-4ea4-a62c-acafbdb636e0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pdfplumber\n",
|
|
"\n",
|
|
"# 读取 PDF 文档\n",
|
|
"pdf = pdfplumber.open(\"5.pdf\")\n",
|
|
"\n",
|
|
"# 获取页数\n",
|
|
"print(\"总页数:\",len(pdf.pages))\n",
|
|
"print(\"-----------------------------------------\")\n",
|
|
"\n",
|
|
"# 读取第 4 页;索引从 1 开始\n",
|
|
"page = pdf.pages[1] \n",
|
|
"print(\"本页:\",page.page_number + 1)\n",
|
|
"print(\"-----------------------------------------\")\n",
|
|
"text = page.extract_text()\n",
|
|
"#for s in text:\n",
|
|
"# print(s)\n",
|
|
"print(text)\n",
|
|
"print(text.split('\\n'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "957b1771-7da1-4ecd-a2b8-889c288b2789",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pdfplumber\n",
|
|
"import pymysql\n",
|
|
"\"\"\"获取人员测试成绩\"\"\"\n",
|
|
"user_id = 5\n",
|
|
"place_id =120\n",
|
|
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = f'SELECT a.item_id,a.performance,a.score,a.date FROM places_result AS a WHERE a.place_id={place_id} AND a.avatar_id={user_id}'\n",
|
|
"cursor.execute(sql)\n",
|
|
"re_ta = {}\n",
|
|
"print(\"\\n运动项目信息:\")\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results:\n",
|
|
"# print (\"%d--%s\" %(result[0],result[1]))\n",
|
|
" re_ta[result[0]] = result[1]\n",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"\n",
|
|
"# 读取 PDF 文档\n",
|
|
"pdf = pdfplumber.open(\"5.pdf\")\n",
|
|
"\n",
|
|
"# 获取页数\n",
|
|
"num = len(pdf.pages)\n",
|
|
"page = pdf.pages[0] \n",
|
|
"text = page.extract_text()\n",
|
|
"dict1['name'] = text.split('\\n')[2]\n",
|
|
"dict1['sn'] = text.split('\\n')[4]\n",
|
|
"\n",
|
|
"\n",
|
|
"print(dict1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "81b0babc-5da8-43b2-b81a-61db0e7e301b",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-12T13:21:30.438009Z",
|
|
"iopub.status.busy": "2021-10-12T13:21:30.437074Z",
|
|
"iopub.status.idle": "2021-10-12T13:21:30.449886Z",
|
|
"shell.execute_reply": "2021-10-12T13:21:30.447584Z",
|
|
"shell.execute_reply.started": "2021-10-12T13:21:30.437900Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"## 体测项目信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6531259c-9727-44f7-9ec3-d6dbe9b76987",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"import json\n",
|
|
"\n",
|
|
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = \"SELECT a.id,a.name, b.name,b.divisor FROM items AS a,items_unit AS b WHERE a.unit_id = b.id\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"dict1 = {}\n",
|
|
"\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results:\n",
|
|
"# print (\"%d--%s\" %(result[0],result[1]))\n",
|
|
" item = {}\n",
|
|
" id = result[0]\n",
|
|
" dict1.setdefault(id,{})\n",
|
|
" item['name'] = result[1]\n",
|
|
" item['unit'] = result[2]\n",
|
|
" item['divisor'] = result[3]\n",
|
|
" dict1[id] = item\n",
|
|
"filename = 'item.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl,ensure_ascii=False) \n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" print(k,v)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9af74d66-b410-4fbf-afcd-9884174e6841",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"filename = 'item.json'\n",
|
|
"item = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" item[k] = v\n",
|
|
"print(item['1'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1ccab0f2-448b-4423-ae21-aa1c0f6470da",
|
|
"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"
|
|
},
|
|
"toc-showtags": false
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|