452 lines
15 KiB
Plaintext
452 lines
15 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": null,
|
|
"id": "91a8f4f4-c417-4db7-94ba-2d3404e5c2c9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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[\"unit\"]\n",
|
|
"\n",
|
|
"myquery = { \"_id\": ObjectId(\"6164fc343d39c8cdd2d97179\")}\n",
|
|
" \n",
|
|
"mydoc = mycol.find(myquery)\n",
|
|
" \n",
|
|
"for x in mydoc:\n",
|
|
" print(x)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2bb3cbdd-9fe1-4345-8c5a-53acb1a386de",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取人员测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 95,
|
|
"id": "910c3fcd-121a-42c0-9465-ad79a5829239",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-12T14:56:11.707898Z",
|
|
"iopub.status.busy": "2021-10-12T14:56:11.706965Z",
|
|
"iopub.status.idle": "2021-10-12T14:56:11.819192Z",
|
|
"shell.execute_reply": "2021-10-12T14:56:11.816891Z",
|
|
"shell.execute_reply.started": "2021-10-12T14:56:11.707790Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"运动项目信息:\n",
|
|
"{'包永': {'台阶指数': {'成绩': '65.0 分', '得分': 4, 'date': datetime.date(2021, 9, 15)}, '身高': {'成绩': '174.7 厘米', '得分': None, 'date': datetime.date(2021, 9, 15)}, '体重': {'成绩': '73.6 千克', '得分': 5, 'date': datetime.date(2021, 9, 15)}, '肺活量': {'成绩': '3812.0 毫升', '得分': 4, 'date': datetime.date(2021, 9, 15)}, '握力': {'成绩': '51.0 千克', '得分': 4, 'date': datetime.date(2021, 9, 15)}, '单脚站立': {'成绩': '13.2 秒', '得分': 3, 'date': datetime.date(2021, 9, 15)}, '坐位体前屈': {'成绩': '20.0 厘米', '得分': 5, 'date': datetime.date(2021, 9, 15)}, '选择反应时': {'成绩': '0.554 秒', '得分': 3, 'date': datetime.date(2021, 9, 15)}, '俯卧撑': {'成绩': '39.0 次', '得分': 5, 'date': datetime.date(2021, 9, 15)}, '纵跳': {'成绩': '38.4 厘米', '得分': 4, 'date': datetime.date(2021, 9, 15)}}}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"import json\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",
|
|
"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",
|
|
"dict1 = {}\n",
|
|
"print(\"\\n运动项目信息:\")\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results:\n",
|
|
" re_ta.setdefault(user,{})\n",
|
|
" m_item = str(result[0])\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",
|
|
" dict1[item[m_item]['name']]['date'] =result[3]\n",
|
|
" re_ta[user] = dict1\n",
|
|
"\n",
|
|
"print(re_ta)\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": 91,
|
|
"id": "6531259c-9727-44f7-9ec3-d6dbe9b76987",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-12T14:49:29.798699Z",
|
|
"iopub.status.busy": "2021-10-12T14:49:29.797765Z",
|
|
"iopub.status.idle": "2021-10-12T14:49:29.861989Z",
|
|
"shell.execute_reply": "2021-10-12T14:49:29.859902Z",
|
|
"shell.execute_reply.started": "2021-10-12T14:49:29.798590Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1 {'name': '肺活量', 'unit': '毫升', 'divisor': 1}\n",
|
|
"2 {'name': '握力', 'unit': '千克', 'divisor': 1000}\n",
|
|
"3 {'name': '坐位体前屈', 'unit': '厘米', 'divisor': 10}\n",
|
|
"4 {'name': '纵跳', 'unit': '厘米', 'divisor': 10}\n",
|
|
"5 {'name': '俯卧撑', 'unit': '次', 'divisor': 1}\n",
|
|
"6 {'name': '单脚站立', 'unit': '秒', 'divisor': 1000}\n",
|
|
"7 {'name': '选择反应时', 'unit': '秒', 'divisor': 1000}\n",
|
|
"8 {'name': '台阶指数', 'unit': '分', 'divisor': 10}\n",
|
|
"9 {'name': '一分钟仰卧起坐', 'unit': '次', 'divisor': 1}\n",
|
|
"10 {'name': '身高', 'unit': '厘米', 'divisor': 10}\n",
|
|
"11 {'name': '体重', 'unit': '千克', 'divisor': 1000}\n",
|
|
"12 {'name': '立定跳远', 'unit': '厘米', 'divisor': 10}\n",
|
|
"13 {'name': '网球掷远', 'unit': '米', 'divisor': 1000}\n",
|
|
"14 {'name': '双脚连续跳', 'unit': '秒', 'divisor': 1000}\n",
|
|
"15 {'name': '10米折返跑', 'unit': '秒', 'divisor': 1000}\n",
|
|
"16 {'name': '走平衡木', 'unit': '秒', 'divisor': 1000}\n",
|
|
"17 {'name': '50米跑', 'unit': '秒', 'divisor': 1000}\n",
|
|
"18 {'name': '一分钟跳绳', 'unit': '次', 'divisor': 1}\n",
|
|
"19 {'name': '50米*8往返跑', 'unit': '秒', 'divisor': 1000}\n",
|
|
"20 {'name': '高压', 'unit': 'mmHg', 'divisor': 1}\n",
|
|
"21 {'name': '低压', 'unit': 'mmHg', 'divisor': 1}\n",
|
|
"22 {'name': '心率', 'unit': '次', 'divisor': 1}\n",
|
|
"23 {'name': '长跑', 'unit': '秒', 'divisor': 1000}\n",
|
|
"24 {'name': '引体向上', 'unit': '次', 'divisor': 1}\n",
|
|
"27 {'name': '实心球', 'unit': '米', 'divisor': 1000}\n",
|
|
"28 {'name': '篮球运球', 'unit': '秒', 'divisor': 1000}\n",
|
|
"29 {'name': '足球运球', 'unit': '秒', 'divisor': 1000}\n",
|
|
"30 {'name': '足球垫球', 'unit': '次', 'divisor': 1}\n",
|
|
"31 {'name': '排球垫球', 'unit': '次', 'divisor': 1}\n",
|
|
"32 {'name': '25米×2往返跑', 'unit': '秒', 'divisor': 1000}\n",
|
|
"33 {'name': '左右眼视力', 'unit': '分', 'divisor': 10}\n",
|
|
"34 {'name': '测试', 'unit': '毫升', 'divisor': 1}\n",
|
|
"37 {'name': '跪卧撑', 'unit': '次', 'divisor': 1}\n",
|
|
"38 {'name': '功率车', 'unit': '毫升/千克/分钟', 'divisor': 10}\n"
|
|
]
|
|
}
|
|
],
|
|
"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": 80,
|
|
"id": "9af74d66-b410-4fbf-afcd-9884174e6841",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-10-12T14:35:04.928544Z",
|
|
"iopub.status.busy": "2021-10-12T14:35:04.927553Z",
|
|
"iopub.status.idle": "2021-10-12T14:35:04.945489Z",
|
|
"shell.execute_reply": "2021-10-12T14:35:04.943664Z",
|
|
"shell.execute_reply.started": "2021-10-12T14:35:04.928432Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{'name': '肺活量', 'unit': '毫升', 'divisor': 1, 'info': '肺活量(vital capacity)是指在最大吸气后尽力呼气的气量。包括潮气量、补吸气量和补呼气量三部分。潮气量是指一次呼吸周期中肺吸量或呼出的气量,在潮气量之外再吸入的最大气量为补吸气量,在潮气量之外再呼出的最最大量为补呼气量,最大呼气后残留在肺内的气量为余气量。\\r\\n肺活量与人的呼吸密切相关。生理学研究表明:人体的各器官、系统、组织、细胞每时每刻都在消耗氧,机体只有在氧供应充足的情况下才能正常工作。人体内部的氧供给全部靠肺的呼吸来获得,在呼吸过程中,肺不仅要摄入氧气,还要将体内代谢出的二氧化碳排出。\\r\\n可以这样认为:肺是机体气体交换的中转站,这个中转站的容积大小直接决定着每次呼吸气体交换的量,这是检测肺功能的最直观、也是最客观的指标。'}\n"
|
|
]
|
|
}
|
|
],
|
|
"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"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|