From 3a9cb48f1e1e17e05cad795fb5f89b0f768daae3 Mon Sep 17 00:00:00 2001 From: 512song Date: Tue, 24 Sep 2024 19:37:04 +0800 Subject: [PATCH] 20240924 --- 体测单位/体测数据管理.ipynb | 110 ++- 体测单位/体质检测数据处理.ipynb | 54 +- 体测单位/天宫院社区.ipynb | 239 ++--- 体测单位/镇海.ipynb | 1490 ++++++++++++++++++++++++++++++- 数据处理.ipynb | 33 + 5 files changed, 1697 insertions(+), 229 deletions(-) diff --git a/体测单位/体测数据管理.ipynb b/体测单位/体测数据管理.ipynb index 2f9a357..1396168 100644 --- a/体测单位/体测数据管理.ipynb +++ b/体测单位/体测数据管理.ipynb @@ -10,9 +10,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "360f0a97-d73d-43f3-9f7a-0f9582103c82", "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T09:50:41.703850Z", + "iopub.status.busy": "2024-09-24T09:50:41.703095Z", + "iopub.status.idle": "2024-09-24T09:50:41.720718Z", + "shell.execute_reply": "2024-09-24T09:50:41.719536Z", + "shell.execute_reply.started": "2024-09-24T09:50:41.703777Z" + }, "tags": [] }, "outputs": [], @@ -23,10 +30,10 @@ "mydb = myclient[\"baogao\"]\n", "mycol = mydb[\"place\"]\n", "\n", - "place_id = 727411\n", - "place_code = \"13\"\n", - "dw_name = \"北体体质康健班\"\n", - "dw_jc = \"北体体质康健班\"\n", + "place_id = 345321\n", + "place_code = \"14\"\n", + "dw_name = \"中国石化镇海炼化公司\"\n", + "dw_jc = \"中国石化镇海炼化公司\"\n", "myquery = { \"id\": place_id }\n", "num = mycol.count_documents(myquery)\n", "if num>0:\n", @@ -46,10 +53,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "6ce2cbc7-435a-461c-bdb8-abd9a6962fbc", - "metadata": {}, - "outputs": [], + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-23T09:16:02.614379Z", + "iopub.status.busy": "2024-09-23T09:16:02.613463Z", + "iopub.status.idle": "2024-09-23T09:16:02.633416Z", + "shell.execute_reply": "2024-09-23T09:16:02.632423Z", + "shell.execute_reply.started": "2024-09-23T09:16:02.614298Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], "source": [ "import openpyxl\n", "import os,sys,shutil\n", @@ -63,10 +86,10 @@ "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", "mydb = myclient[\"baogao\"]\n", "\n", - "place_id = 727411\n", - "place_code = \"13\"\n", - "dw_name = \"北体体质康健班\"\n", - "dw_jc = \"北体体质康健班\"\n", + "place_id = 496534\n", + "place_code = \"12\"\n", + "dw_name = \"天宫院社区\"\n", + "dw_jc = \"天宫院社区\"\n", "fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n", "fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n", "\n", @@ -97,7 +120,7 @@ " #fi_name =Path(fn).stem\n", " code = int(fi_name)\n", " dxm = list1[i]\n", - " dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name,'rq':'20240914'}\n", + " dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n", " list2.append(dict2)\n", " i +=1\n", "x = mycol.insert_many(list2)\n", @@ -114,12 +137,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "5f665c0f-8d30-4759-b7f8-fb7e13b98efa", "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T06:02:00.787106Z", + "iopub.status.busy": "2024-09-24T06:02:00.786300Z", + "iopub.status.idle": "2024-09-24T06:02:00.838883Z", + "shell.execute_reply": "2024-09-24T06:02:00.838280Z", + "shell.execute_reply.started": "2024-09-24T06:02:00.787028Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 13488820384 0014-舒浩轩.pdf\n", + "2 18612703139 0025-李嘉睿.pdf\n", + "3 13522895654 0003-杨宾.pdf\n", + "4 13718367043 0012-杨玉芬.pdf\n", + "5 15210713283 0005-王红柳.pdf\n", + "6 15101087817 0024-茅晴晴.pdf\n", + "7 18810111978 0008-段丽阳.pdf\n", + "8 15224991657 0026-郑慧敏.pdf\n", + "9 15210713283 0006-高天蕴.pdf\n", + "10 15010699019 0021-董润华.pdf\n", + "11 13671026339 0013-王柱明.pdf\n", + "12 15551006319 0029-林景平.pdf\n", + "13 13522895654 0004-武馨怡.pdf\n", + "14 18660799298 0023-程军妮.pdf\n", + "15 18233207289 0019-张傲楠.pdf\n", + "16 13910932179 0017-朱芷祁.pdf\n", + "17 18210661187 0011-张耀聪.pdf\n", + "18 18232370815 0020-尹晓晴.pdf\n", + "19 13426267482 0018-卢浥尘.pdf\n", + "20 13552494958 0031-魏丽.pdf\n", + "21 13681380585 0007-刘颖.pdf\n", + "22 13311183808 0016-张玉后.pdf\n", + "23 18210661187 0001-李雪莉.pdf\n", + "24 17665174761 0027-郑文结.pdf\n", + "25 15588818169 0022-刘小云.pdf\n", + "26 13011189787 0028-潘妍.pdf\n", + "27 13770726975 0030-宋元宵.pdf\n", + "28 18210661187 0002-张进刚.pdf\n", + "29 13671271202 0010-范文兰.pdf\n", + "30 18810111978 0009-段宇辰.pdf\n", + "31 13581907290 0015-罗靖卓.pdf\n" + ] + } + ], "source": [ "from tencentcloud.common import credential\n", "from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n", @@ -133,13 +201,13 @@ "mydb = myclient[\"baogao\"]\n", "mycol = mydb[\"pdf\"]\n", "\n", - "dw_jc = \"北体体质康健班\"\n", - "filename = 'data/北体体质康健.json'\n", + "dw_jc = \"天宫院社区\"\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "#place_id = 571315\n", - "myquery = { \"place_id\": place_id,\"rq\":'20240914' }\n", + "myquery = { \"place_id\": place_id}\n", "for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n", " code = int(x['fn'].split('-')[0])\n", " if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():\n", @@ -214,13 +282,13 @@ "mydb = myclient[\"baogao\"]\n", "mycol = mydb[\"pdf\"]\n", "\n", - "dw_jc = \"北体体质康健班测试者\"\n", - "filename = 'data/北体体质康健.json'\n", + "dw_jc = \"天宫院社区测试者\"\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "#place_id = 571315\n", - "myquery = { \"place_id\": place_id,\"rq\":'20240914' }\n", + "myquery = { \"place_id\": place_id }\n", "for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n", " code = int(x['fn'].split('-')[0])\n", " if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():\n", diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index c5f580d..c2c230d 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -431,15 +431,15 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 1, "id": "3e614f4a-a623-48e2-97f8-b31f62c9a983", "metadata": { "execution": { - "iopub.execute_input": "2024-07-11T02:15:15.011907Z", - "iopub.status.busy": "2024-07-11T02:15:15.011411Z", - "iopub.status.idle": "2024-07-11T02:15:15.033470Z", - "shell.execute_reply": "2024-07-11T02:15:15.032441Z", - "shell.execute_reply.started": "2024-07-11T02:15:15.011858Z" + "iopub.execute_input": "2024-09-23T09:01:55.163463Z", + "iopub.status.busy": "2024-09-23T09:01:55.162587Z", + "iopub.status.idle": "2024-09-23T09:01:55.182154Z", + "shell.execute_reply": "2024-09-23T09:01:55.181668Z", + "shell.execute_reply.started": "2024-09-23T09:01:55.163386Z" }, "tags": [] }, @@ -448,8 +448,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "47\n", - "47\n" + "31\n", + "31\n" ] } ], @@ -482,11 +482,11 @@ "re_ta = {}\n", "dict1 = {}\n", "list1 = []\n", - "filename = 'data/天宫院街道2024.json'\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", - "filename = 'data/places_result_20240710.csv'\n", + "filename = 'data/places_result_20240923.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -527,7 +527,7 @@ " score = int(result[4])/item[m_item]['divisor'] \n", " re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", "print(len(re_ta))\n", - "filename = 'data/result_天宫院社区2024.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", @@ -548,11 +548,11 @@ "id": "141b30dc-5975-4dcb-9bc3-9b20d26a0917", "metadata": { "execution": { - "iopub.execute_input": "2024-09-14T12:17:16.275045Z", - "iopub.status.busy": "2024-09-14T12:17:16.274382Z", - "iopub.status.idle": "2024-09-14T12:17:16.304051Z", - "shell.execute_reply": "2024-09-14T12:17:16.303490Z", - "shell.execute_reply.started": "2024-09-14T12:17:16.274984Z" + "iopub.execute_input": "2024-09-23T09:02:38.046594Z", + "iopub.status.busy": "2024-09-23T09:02:38.045904Z", + "iopub.status.idle": "2024-09-23T09:02:38.070709Z", + "shell.execute_reply": "2024-09-23T09:02:38.070026Z", + "shell.execute_reply.started": "2024-09-23T09:02:38.046526Z" }, "tags": [] }, @@ -662,7 +662,7 @@ "\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", - "filename = 'data/result_北体体质康健1.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", @@ -683,7 +683,7 @@ " dict2[k][item_en]['score'] = cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", - "filename = f'data/result_北体体质康健2.json'\n", + "filename = f'data/result_天宫院社区240922.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " @@ -846,15 +846,15 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 3, "id": "b123ee6b-85d2-4660-b226-321832a6b796", "metadata": { "execution": { - "iopub.execute_input": "2024-07-11T02:18:04.079962Z", - "iopub.status.busy": "2024-07-11T02:18:04.079156Z", - "iopub.status.idle": "2024-07-11T02:18:13.608066Z", - "shell.execute_reply": "2024-07-11T02:18:13.606969Z", - "shell.execute_reply.started": "2024-07-11T02:18:04.079886Z" + "iopub.execute_input": "2024-09-23T09:03:50.560872Z", + "iopub.status.busy": "2024-09-23T09:03:50.560147Z", + "iopub.status.idle": "2024-09-23T09:04:05.194187Z", + "shell.execute_reply": "2024-09-23T09:04:05.193055Z", + "shell.execute_reply.started": "2024-09-23T09:03:50.560801Z" }, "tags": [] }, @@ -863,7 +863,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "22\n" + "31\n" ] } ], @@ -876,11 +876,11 @@ "headers = {\n", " \"Content-Type\": \"application/json; charset=UTF-8\"\n", " }\n", - "filename = 'data/result_天宫院街道1.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", - "file_path ='./天宫院2024/'\n", + "file_path ='./天宫院240922/'\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", "i=0\n", "list2 = []\n", diff --git a/体测单位/天宫院社区.ipynb b/体测单位/天宫院社区.ipynb index a9efa54..6a171c3 100644 --- a/体测单位/天宫院社区.ipynb +++ b/体测单位/天宫院社区.ipynb @@ -10,18 +10,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "a03a5289-9766-4a60-9d38-245deb2ee4e6", "metadata": { + "execution": { + "iopub.execute_input": "2024-09-23T08:54:21.300838Z", + "iopub.status.busy": "2024-09-23T08:54:21.300070Z", + "iopub.status.idle": "2024-09-23T08:54:21.477586Z", + "shell.execute_reply": "2024-09-23T08:54:21.476575Z", + "shell.execute_reply.started": "2024-09-23T08:54:21.300765Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", - "wb = openpyxl.load_workbook('data/天宫院街道2024.xlsx')\n", + "wb = openpyxl.load_workbook('data/240922名单.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", @@ -36,14 +51,13 @@ " \n", " dict1['sex'] = sheet.cell(n,3).value\n", " birth = str(sheet.cell(n, 4).value).split()[0]\n", - " dict1['birth'] = birth.replace('/','-')\n", + " dict1['birth'] = birth.replace('/','-') \n", " \n", - " person[code] = dict1\n", " if sheet.cell(n,5).value is not None:\n", " dict1['phone'] = sheet.cell(n,5).value\n", "\n", " person[code] = dict1\n", - "filename = 'data/天宫院街道2024.json'\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" @@ -51,26 +65,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "b29a6f3c-035c-4c74-bbac-61e83be2b37c", - "metadata": { - "execution": { - "iopub.execute_input": "2024-07-11T08:18:28.633340Z", - "iopub.status.busy": "2024-07-11T08:18:28.632568Z", - "iopub.status.idle": "2024-07-11T08:18:28.654035Z", - "shell.execute_reply": "2024-07-11T08:18:28.653382Z", - "shell.execute_reply.started": "2024-07-11T08:18:28.633268Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import openpyxl\n", "import json\n", @@ -149,12 +147,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "db39190f-47d4-4a7c-b727-c79e2a64452f", "metadata": { + "execution": { + "iopub.execute_input": "2024-09-23T08:55:23.555758Z", + "iopub.status.busy": "2024-09-23T08:55:23.554865Z", + "iopub.status.idle": "2024-09-23T08:55:23.569912Z", + "shell.execute_reply": "2024-09-23T08:55:23.568888Z", + "shell.execute_reply.started": "2024-09-23T08:55:23.555680Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "31\n", + "31\n" + ] + } + ], "source": [ "import json\n", "import time\n", @@ -170,11 +184,11 @@ "re_ta = {}\n", "dict1 = {}\n", "list1 = []\n", - "filename = 'data/天宫院街道2024.json'\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", - "filename = 'data/places_result_20240710.csv'\n", + "filename = 'data/places_result_20240923.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -194,7 +208,7 @@ " score = int(result[4])/item[m_item]['divisor'] \n", " re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", "print(len(re_ta))\n", - "filename = 'data/result_天宫院街道2024.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", @@ -203,15 +217,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "id": "590775c3-16ef-43ad-99a2-85e847fe4079", "metadata": { "execution": { - "iopub.execute_input": "2024-07-11T08:19:29.653063Z", - "iopub.status.busy": "2024-07-11T08:19:29.652598Z", - "iopub.status.idle": "2024-07-11T08:19:29.662479Z", - "shell.execute_reply": "2024-07-11T08:19:29.661939Z", - "shell.execute_reply.started": "2024-07-11T08:19:29.653037Z" + "iopub.execute_input": "2024-09-23T08:57:30.916080Z", + "iopub.status.busy": "2024-09-23T08:57:30.915319Z", + "iopub.status.idle": "2024-09-23T08:57:30.930835Z", + "shell.execute_reply": "2024-09-23T08:57:30.929793Z", + "shell.execute_reply.started": "2024-09-23T08:57:30.916010Z" } }, "outputs": [ @@ -219,8 +233,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "61\n", - "61\n" + "31\n", + "31\n" ] } ], @@ -239,11 +253,11 @@ "re_ta = {}\n", "dict1 = {}\n", "list1 = []\n", - "filename = 'data/天宫院街道all.json'\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", - "filename = 'data/places_result_20240710.csv'\n", + "filename = 'data/places_result_20240923.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -262,7 +276,7 @@ " score = int(result[4])/item[m_item]['divisor'] \n", " re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", "print(len(re_ta))\n", - "filename = 'data/result_天宫院街道all.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", @@ -279,15 +293,15 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 4, "id": "c2ee2c71-7e28-4201-af85-ed7f001c6872", "metadata": { "execution": { - "iopub.execute_input": "2024-07-11T08:19:59.192307Z", - "iopub.status.busy": "2024-07-11T08:19:59.191555Z", - "iopub.status.idle": "2024-07-11T08:19:59.221577Z", - "shell.execute_reply": "2024-07-11T08:19:59.220830Z", - "shell.execute_reply.started": "2024-07-11T08:19:59.192234Z" + "iopub.execute_input": "2024-09-23T08:58:27.504156Z", + "iopub.status.busy": "2024-09-23T08:58:27.503390Z", + "iopub.status.idle": "2024-09-23T08:58:27.530165Z", + "shell.execute_reply": "2024-09-23T08:58:27.529383Z", + "shell.execute_reply.started": "2024-09-23T08:58:27.504064Z" }, "tags": [] }, @@ -296,18 +310,37 @@ "name": "stdout", "output_type": "stream", "text": [ - "101 李先生\n" - ] - }, - { - "ename": "KeyError", - "evalue": "'sex'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[10], line 20\u001b[0m\n\u001b[1;32m 18\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mstr\u001b[39m(k)\u001b[38;5;241m.\u001b[39mrjust(\u001b[38;5;241m3\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m 19\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(v[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]) \n\u001b[0;32m---> 20\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[43mdict2\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msex\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m)\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m items:\n\u001b[1;32m 24\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m v\u001b[38;5;241m.\u001b[39mkeys():\n", - "\u001b[0;31mKeyError\u001b[0m: 'sex'" + "31 魏丽\n", + "1 李雪莉\n", + "2 张进刚\n", + "3 杨宾\n", + "4 武馨怡\n", + "6 高天蕴\n", + "5 王红柳\n", + "7 刘颖\n", + "8 段丽阳\n", + "9 段宇辰\n", + "10 范文兰\n", + "11 张耀聪\n", + "12 杨玉芬\n", + "13 王柱明\n", + "14 舒浩轩\n", + "15 罗靖卓\n", + "16 张玉后\n", + "17 朱芷祁\n", + "18 卢浥尘\n", + "19 张傲楠\n", + "20 尹晓晴\n", + "21 董润华\n", + "22 刘小云\n", + "23 程军妮\n", + "24 茅晴晴\n", + "25 李嘉睿\n", + "26 郑慧敏\n", + "27 郑文结\n", + "28 潘妍\n", + "29 林景平\n", + "30 宋元宵\n" ] } ], @@ -317,11 +350,11 @@ "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "title = ['编号','姓名','性别','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", - "filename = 'data/result_天宫院街道.json'\n", + "filename = 'data/result_天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", - "filename = 'data/天宫院街道all.json'\n", + "filename = 'data/天宫院社区240922.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", " \n", @@ -342,7 +375,7 @@ " else:\n", " list2.append('') \n", " list1.append(list2)\n", - "filename = 'data/天宫院社区体测情况表_all.xlsx'\n", + "filename = 'data/天宫院社区体测情况表_240922.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", @@ -354,86 +387,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "ddba1233-6ab2-480d-8bde-ed8e1c34e48e", - "metadata": { - "execution": { - "iopub.execute_input": "2024-07-11T08:20:48.587834Z", - "iopub.status.busy": "2024-07-11T08:20:48.587065Z", - "iopub.status.idle": "2024-07-11T08:20:48.615936Z", - "shell.execute_reply": "2024-07-11T08:20:48.615410Z", - "shell.execute_reply.started": "2024-07-11T08:20:48.587764Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "101 李有才\n", - "44 星众豪\n", - "94 谢红印\n", - "14 孙一萂\n", - "132 梁正文\n", - "123 刘\n", - "93 李洪芝\n", - "71 李羽馨\n", - "91 孙婧祎\n", - "8 王红晶\n", - "126 马\n", - "125 陈\n", - "6 刘艳\n", - "96 薛颖\n", - "2 刘书本\n", - "40 杨春华\n", - "9 霍思诺\n", - "124 苗\n", - "128 张\n", - "78 朱蕊\n", - "10 李晨曦\n", - "5 李芳\n", - "100 聂彦芹\n", - "4 富红\n", - "68 冯瑞文\n", - "108 杨\n", - "130 徐\n", - "86 阎树芹\n", - "83 张万成\n", - "116 白景香\n", - "103 王梓涵\n", - "15 王慧兰\n", - "36 冯玉红\n", - "118 王玉芬\n", - "102 王岩东\n", - "19 张竹辰\n", - "38 路德慧\n", - "111 张\n", - "37 张影\n", - "25 孟现春\n", - "41 朱朝云\n", - "85 武宜国\n", - "107 刘连英\n", - "20 王韵琪\n", - "7 李雪\n", - "18 王真秀\n", - "98 张建霞\n", - "131 陈艳莉\n", - "106 沈建新\n", - "43 杨桂兰\n", - "127 张\n", - "39 韩润壮\n", - "129 薛\n", - "110 赵\n", - "79 郭忠臣\n", - "81 赵淑芬\n", - "115 朱\n", - "114 王淑云\n", - "62 赵秀香\n", - "31 张成林\n", - "99 张东喜\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import openpyxl\n", diff --git a/体测单位/镇海.ipynb b/体测单位/镇海.ipynb index 6a03301..82af8d3 100644 --- a/体测单位/镇海.ipynb +++ b/体测单位/镇海.ipynb @@ -1,5 +1,13 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "92891af2-e909-4b8e-a08a-b5b5e4a1c732", + "metadata": {}, + "source": [ + "# 体质测试" + ] + }, { "cell_type": "markdown", "id": "338fb8da-815a-4536-ae91-4f461ba9401f", @@ -10,15 +18,15 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 81, "id": "ba24132c-133f-4508-8fe7-e68d1908b6e9", "metadata": { "execution": { - "iopub.execute_input": "2024-09-20T08:47:18.577809Z", - "iopub.status.busy": "2024-09-20T08:47:18.577022Z", - "iopub.status.idle": "2024-09-20T08:47:18.914709Z", - "shell.execute_reply": "2024-09-20T08:47:18.914113Z", - "shell.execute_reply.started": "2024-09-20T08:47:18.577734Z" + "iopub.execute_input": "2024-09-23T08:05:35.010497Z", + "iopub.status.busy": "2024-09-23T08:05:35.009998Z", + "iopub.status.idle": "2024-09-23T08:05:35.403341Z", + "shell.execute_reply": "2024-09-23T08:05:35.402730Z", + "shell.execute_reply.started": "2024-09-23T08:05:35.010448Z" } }, "outputs": [ @@ -47,9 +55,11 @@ " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n, 3).value\n", " dict1['unit'] = sheet.cell(n, 7).value\n", - " dict1['gh'] = sheet.cell(n, 5).value\n", + " if sheet.cell(n, 5).value is not None:\n", + " dict1['gh'] = sheet.cell(n, 5).value\n", " dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0] \n", - " dict1['phone'] = str(sheet.cell(n,4).value)\n", + " if sheet.cell(n, 4).value is not None:\n", + " dict1['phone'] = str(sheet.cell(n,4).value)\n", " person[code] = dict1\n", "filename = 'data/镇海.json'\n", "with open(filename, 'w') as fl:\n", @@ -119,15 +129,15 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 58, "id": "5d864909-d10f-461d-8e6e-dc5c43613576", "metadata": { "execution": { - "iopub.execute_input": "2024-09-20T08:48:09.078723Z", - "iopub.status.busy": "2024-09-20T08:48:09.077996Z", - "iopub.status.idle": "2024-09-20T08:48:09.151435Z", - "shell.execute_reply": "2024-09-20T08:48:09.150864Z", - "shell.execute_reply.started": "2024-09-20T08:48:09.078657Z" + "iopub.execute_input": "2024-09-22T10:49:09.815998Z", + "iopub.status.busy": "2024-09-22T10:49:09.815209Z", + "iopub.status.idle": "2024-09-22T10:49:09.910712Z", + "shell.execute_reply": "2024-09-22T10:49:09.910125Z", + "shell.execute_reply.started": "2024-09-22T10:49:09.815926Z" } }, "outputs": [ @@ -135,8 +145,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "934\n", - "934\n" + "1365\n", + "1365\n" ] } ], @@ -159,7 +169,7 @@ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", - "filename = 'data/places_result_20240920.csv'\n", + "filename = 'data/places_result_20240922.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -198,15 +208,15 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 57, "id": "bc79f0d2-62a2-40c8-bd74-9c7ff17bec8e", "metadata": { "execution": { - "iopub.execute_input": "2024-09-20T08:48:32.839532Z", - "iopub.status.busy": "2024-09-20T08:48:32.838772Z", - "iopub.status.idle": "2024-09-20T08:48:33.052265Z", - "shell.execute_reply": "2024-09-20T08:48:33.051700Z", - "shell.execute_reply.started": "2024-09-20T08:48:32.839461Z" + "iopub.execute_input": "2024-09-22T10:44:33.765318Z", + "iopub.status.busy": "2024-09-22T10:44:33.764545Z", + "iopub.status.idle": "2024-09-22T10:44:33.796972Z", + "shell.execute_reply": "2024-09-22T10:44:33.796426Z", + "shell.execute_reply.started": "2024-09-22T10:44:33.765245Z" } }, "outputs": [], @@ -240,7 +250,7 @@ " else:\n", " list2.append('') \n", " list1.append(list2)\n", - "filename = 'data/镇海体测情况(截至20240920).xlsx'\n", + "filename = 'data/镇海体测情况(20240922手工).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", @@ -260,15 +270,15 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 41, "id": "cf22739a-5cf3-47fd-b87a-158a2e2d5a95", "metadata": { "execution": { - "iopub.execute_input": "2024-09-20T08:49:06.241970Z", - "iopub.status.busy": "2024-09-20T08:49:06.241223Z", - "iopub.status.idle": "2024-09-20T08:49:06.291731Z", - "shell.execute_reply": "2024-09-20T08:49:06.291195Z", - "shell.execute_reply.started": "2024-09-20T08:49:06.241901Z" + "iopub.execute_input": "2024-09-22T03:58:55.502517Z", + "iopub.status.busy": "2024-09-22T03:58:55.501726Z", + "iopub.status.idle": "2024-09-22T03:58:55.536562Z", + "shell.execute_reply": "2024-09-22T03:58:55.536063Z", + "shell.execute_reply.started": "2024-09-22T03:58:55.502442Z" } }, "outputs": [], @@ -293,7 +303,7 @@ " i+=1\n", " list1.append(list2)\n", "#print(list1)\n", - "filename = f'data/镇海未测试人员名单.xlsx'\n", + "filename = f'data/镇海未测试人员名单(截至20240922).xlsx'\n", "title = ['序号','员工编号','姓名','部门']\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", @@ -313,15 +323,15 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 39, "id": "f4dade65-f760-4220-8a65-39843688a60a", "metadata": { "execution": { - "iopub.execute_input": "2024-09-20T08:48:41.723955Z", - "iopub.status.busy": "2024-09-20T08:48:41.723229Z", - "iopub.status.idle": "2024-09-20T08:48:41.926161Z", - "shell.execute_reply": "2024-09-20T08:48:41.925529Z", - "shell.execute_reply.started": "2024-09-20T08:48:41.723892Z" + "iopub.execute_input": "2024-09-22T03:58:31.869404Z", + "iopub.status.busy": "2024-09-22T03:58:31.868639Z", + "iopub.status.idle": "2024-09-22T03:58:32.098484Z", + "shell.execute_reply": "2024-09-22T03:58:32.097950Z", + "shell.execute_reply.started": "2024-09-22T03:58:31.869332Z" } }, "outputs": [ @@ -329,8 +339,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "1354\n", - "1298\n" + "1462\n", + "1406\n" ] } ], @@ -363,10 +373,1410 @@ " json.dump(dict1, fl, ensure_ascii=False) \n" ] }, + { + "cell_type": "markdown", + "id": "e513b5bb-8a4e-412a-880b-1ae36e059bfd", + "metadata": {}, + "source": [ + "## 转换报告格式" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "7f038e8d-dd57-4880-8726-6dfa86fbc4a2", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T10:49:29.510032Z", + "iopub.status.busy": "2024-09-22T10:49:29.509298Z", + "iopub.status.idle": "2024-09-22T10:49:29.639707Z", + "shell.execute_reply": "2024-09-22T10:49:29.639166Z", + "shell.execute_reply.started": "2024-09-22T10:49:29.509965Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1365\n", + "1365\n" + ] + } + ], + "source": [ + "import json\n", + "import datetime\n", + "import csv\n", + "from datetime import date\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", + "item['1']['en'] = 'lung'\n", + "item['2']['en'] = 'grip'\n", + "item['3']['en'] = 'flexion'\n", + "item['4']['en'] = 'jump'\n", + "item['5']['en'] = 'pushup'\n", + "item['6']['en'] = 'balance'\n", + "item['7']['en'] = 'reaction'\n", + "item['8']['en'] = 'step'\n", + "item['9']['en'] = 'situp'\n", + "item['10']['en'] = 'height'\n", + "item['11']['en'] = 'weight'\n", + "\n", + "\n", + "re_ta = {}\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/镇海.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "filename = 'data/places_result_20240922.csv'\n", + "with open(filename,'r',newline='') as csv_file:\n", + " fl = csv.reader(csv_file,delimiter=',')\n", + " header = next(fl) \n", + " for line in fl:\n", + " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", + " list1.append(line)\n", + "#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n", + "#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n", + "for result in list1:\n", + " user = str(result[2])\n", + " rq = date.fromisoformat(result[6].replace('/','-'))\n", + " if user in dict1.keys():\n", + " l_xm = []\n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " re_ta[user]['name'] = dict1[user]['name']\n", + " re_ta[user]['sex'] = dict1[user]['sex']\n", + " if dict1[user]['sex'] == '男':\n", + " l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n", + " else:\n", + " l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n", + " re_ta[user]['unit'] = dict1[user]['unit']\n", + " #birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n", + " birth = date.fromisoformat(dict1[user]['birth'])\n", + " #nian = int(birth[0].strip())\n", + " #yue = int(birth[1].strip())\n", + " #ri = int(birth[2].strip())\n", + " #print(k,nian,yue,ri)\n", + " item_name = item[m_item]['en'] \n", + " if item_name in l_xm: \n", + " days = (rq-birth).days \n", + " re_ta[user]['age'] = int(days/365)\n", + " re_ta[user]['month'] = int(days/365*12)\n", + " re_ta[user]['rq'] = result[6]\n", + "\n", + "\n", + " re_ta[user].setdefault(item_name,{}) \n", + " score = int(result[4])/item[m_item]['divisor'] \n", + " re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", + "print(len(re_ta))\n", + "filename = 'data/result_镇海1.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(re_ta, fl, ensure_ascii=False) \n", + "print(len(re_ta))" + ] + }, + { + "cell_type": "markdown", + "id": "de2eec6d-a74e-47e1-ab7a-c7f6eda80a20", + "metadata": {}, + "source": [ + "## 生成完善得分" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "763aa68a-da54-4745-a759-4399aba10f7e", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T10:49:36.694100Z", + "iopub.status.busy": "2024-09-22T10:49:36.693314Z", + "iopub.status.idle": "2024-09-22T10:49:36.784607Z", + "shell.execute_reply": "2024-09-22T10:49:36.784166Z", + "shell.execute_reply.started": "2024-09-22T10:49:36.694030Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok!\n" + ] + } + ], + "source": [ + "import json\n", + "import time\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl) \n", + "for k,v in dict3.items():\n", + " item[k] = v\n", + "item['1']['en'] = 'lung'\n", + "item['2']['en'] = 'grip'\n", + "item['3']['en'] = 'flexion'\n", + "item['4']['en'] = 'jump'\n", + "item['5']['en'] = 'pushup'\n", + "item['6']['en'] = 'balance'\n", + "item['7']['en'] = 'reaction'\n", + "item['8']['en'] = 'step'\n", + "item['9']['en'] = 'situp'\n", + "item['10']['en'] = 'height'\n", + "item['11']['en'] = 'weight'\n", + "\n", + "filename = 'data/体质检测标准 (1).json' \n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "\n", + "\n", + "def cal_score(data1):\n", + " #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n", + " person = dict1['person']\n", + " criteria = dict1['criteria']\n", + " if data1['age'] >59:\n", + " data1['age'] = 59\n", + " if data1['age'] <20:\n", + " data1['age'] = 20\n", + " info = data1['sex']+str(data1['age'])\n", + " bz = person[info]\n", + " mx = criteria[bz][data1['item']]\n", + " result = data1['result'] \n", + " if data1['item'] == 'reaction':\n", + " for bz1 in mx:\n", + " if result > bz1:\n", + " #print(bz1)\n", + " score = mx.index(bz1,0)\n", + " break\n", + " else:\n", + " score = 5\n", + " else:\n", + " for bz1 in mx:\n", + " if result < bz1:\n", + " #print(bz1)\n", + " score = mx.index(bz1,0)\n", + " break\n", + " else:\n", + " score = 5\n", + " return(score)\n", + "filename = 'data/体质检测标准_BMI.json'\n", + "with open(filename,'r') as fl:\n", + " dict4 = json.load(fl) \n", + " \n", + "def cal_bmi(data1):\n", + " # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n", + " person = dict4['person']\n", + " criteria = dict4['criteria']\n", + " if data1['age'] > 59:\n", + " data1['age'] = 59\n", + " if data1['age'] <20:\n", + " data1['age'] = 20\n", + " info = data1['sex']+str(data1['age'])\n", + " bz = person[info]\n", + " #print(bz)\n", + " result = data1['result']\n", + " #print(data1['code'],result)\n", + " height = int(float(result.split(',')[0]))\n", + " weight = float(result.split(',')[1])\n", + " if str(height) not in criteria[bz]:\n", + " score = 1\n", + " else: \n", + " mx = criteria[bz][str(height)]\n", + " if weight < mx[0]:\n", + " score = 1\n", + " elif weight < mx[1]:\n", + " score = 3\n", + " elif weight < mx[2]:\n", + " score = 5 \n", + " elif weight <= mx[3]:\n", + " score = 3 \n", + " elif weight > mx[3]:\n", + " score = 1\n", + " return score\n", + " \n", + " \n", + "\n", + "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", + "filename = 'data/result_镇海1.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl) \n", + "for k, v in dict2.items():\n", + " #print(k)\n", + " if v['sex'] == '男':\n", + " sex = 'M'\n", + " else:\n", + " sex = 'F' \n", + " if 'height' in v.keys() and 'weight' in v.keys():\n", + " bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", + " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n", + " dict2[k]['bmi'] = {}\n", + " dict2[k]['bmi']['成绩'] = bmi_data\n", + " dict2[k]['bmi']['score'] = cal_bmi(data1)\n", + " for item_en in list_item:\n", + " if item_en in v.keys(): \n", + " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n", + " dict2[k][item_en]['score'] = cal_score(data1)\n", + " #print(k,v[item_en]['成绩'],cal_score(data1))\n", + "\n", + "filename = f'data/result_镇海2.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print('ok!') " + ] + }, + { + "cell_type": "markdown", + "id": "723ae3d7-ec16-4dc6-91e2-eeeea6ffe081", + "metadata": {}, + "source": [ + "## 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "90faac13-492d-4b3d-bb21-c228af6d9864", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T10:54:16.247571Z", + "iopub.status.busy": "2024-09-22T10:54:16.246795Z", + "iopub.status.idle": "2024-09-22T11:05:57.685110Z", + "shell.execute_reply": "2024-09-22T11:05:57.683956Z", + "shell.execute_reply.started": "2024-09-22T10:54:16.247498Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1365\n" + ] + } + ], + "source": [ + "import requests\n", + "import json\n", + "import openpyxl\n", + "\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "filename = 'data/result_镇海2.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "file_path ='./镇海石化/'\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", + "i=0\n", + "list2 = []\n", + "for k, v in dict1.items():\n", + " list1 = []\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(4,\"0\")\n", + " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '中国石化镇海炼化公司'\n", + " mydata['subtitle'] = v['unit']\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " mydata['gender'] = 'male'\n", + " else:\n", + " mydata['gender'] = 'female'\n", + " \n", + " mydata['month'] = v['month']\n", + " mydata['fits'] = {}\n", + " survey_list = ['tcm','psy','spine']\n", + " for item in survey_list:\n", + " if item in v.keys():\n", + " mydata.setdefault('surveys',{})\n", + " mydata['surveys'][item] = v[item]\n", + " \n", + " \n", + " #mydata['fits'] = {}\n", + " for item in list_item:\n", + " if item in v.keys():\n", + " mydata.setdefault('fits',{})\n", + " if item in ['lung','pushup','step','situp']:\n", + " mark = v[item]['成绩'].split()[0].split('.')[0]\n", + " else:\n", + " mark = v[item]['成绩'].split()[0]\n", + " mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n", + " #if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n", + " if len(mydata['fits']) >2 : \n", + " list1.append(mydata)\n", + " list2.append([k,v['name']])\n", + " i+=1\n", + " x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n", + " #print(id,v['name'],x.text)\n", + " #print(mydata)\n", + " #x.close()\n", + "print(i)" + ] + }, + { + "cell_type": "markdown", + "id": "82c1eaea-89ad-444a-8dad-07f438c739cc", + "metadata": {}, + "source": [ + "## 统计报告人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "61c731bc-6117-4a9f-8bfa-66f820e49fc4", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-23T08:21:40.030772Z", + "iopub.status.busy": "2024-09-23T08:21:40.030153Z", + "iopub.status.idle": "2024-09-23T08:21:40.215352Z", + "shell.execute_reply": "2024-09-23T08:21:40.214783Z", + "shell.execute_reply.started": "2024-09-23T08:21:40.030713Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1365\n" + ] + } + ], + "source": [ + "import json\n", + "import glob\n", + "from pathlib import Path\n", + "import openpyxl\n", + "\n", + "filename = 'data/镇海.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "fi_path = '/home/songyi/python/mycrm/flask/pdf/files/345321'\n", + "fls = glob.glob(f'{fi_path}/*.pdf')\n", + "dict2 = {}\n", + "for fn in fls:\n", + " \n", + " fi_name =Path(fn).stem.split('-')[0]\n", + " #fi_name =Path(fn).stem\n", + " code = int(fi_name)\n", + " dict2[str(code)] = dict1[str(code)]\n", + "filename = 'data/镇海体测人员.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print(len(dict2)) \n", + "list1 = []\n", + "for k, v in dict2.items(): \n", + " list2 = []\n", + " if 'gh' in v.keys():\n", + " gh = v['gh']\n", + " else:\n", + " gh = ''\n", + " if 'phone' in v.keys():\n", + " phone = v['phone']\n", + " else:\n", + " phone = ''\n", + " list2 = [k,v['name'],v['sex'],v['birth'],v['unit'],gh,phone]\n", + " list1.append(list2)\n", + "#print(list1)\n", + "filename = 'data/镇海参加测试人员名单.xlsx'\n", + "title = ['序号','员工编号','姓名','部门']\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "sheet.append(title)\n", + "for row in list1:\n", + " sheet.append(row) \n", + "wb.save(filename)" + ] + }, + { + "cell_type": "markdown", + "id": "385285b8-fdb3-421d-afbf-c13e4f55bb46", + "metadata": {}, + "source": [ + "## 核验报告人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "c6195bc3-64bc-4f52-8ebc-ba16fd222f85", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T09:46:54.184271Z", + "iopub.status.busy": "2024-09-24T09:46:54.183550Z", + "iopub.status.idle": "2024-09-24T09:46:54.365589Z", + "shell.execute_reply": "2024-09-24T09:46:54.364993Z", + "shell.execute_reply.started": "2024-09-24T09:46:54.184207Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "71 方法泉\n", + "125 徐荟杰\n", + "704 陈鼎\n", + "1365\n" + ] + } + ], + "source": [ + "import openpyxl\n", + "import json\n", + "from datetime import date\n", + "\n", + "wb = openpyxl.load_workbook('data/镇海炼化参加测试人员名单.xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "person = {}\n", + "\n", + "for n in range(2, sheet.max_row+1):\n", + " code = int(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, 6).value is not None:\n", + " dict1['gh'] = sheet.cell(n, 6).value\n", + " dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0] \n", + " if sheet.cell(n, 7).value is not None:\n", + " dict1['phone'] = str(sheet.cell(n,7).value)\n", + " if len(str(sheet.cell(n,7).value))<11:\n", + " print(code,sheet.cell(n, 2).value)\n", + " person[code] = dict1\n", + "filename = 'data/镇海炼化参加测试人员.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(person, fl, ensure_ascii=False)\n", + "print(len(person))" + ] + }, + { + "cell_type": "markdown", + "id": "7e551660-e85f-4da2-8224-042784033ed5", + "metadata": {}, + "source": [ + "## 生成查询信息" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "299c1d41-7634-4703-8411-08f175df4e16", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T09:56:29.452711Z", + "iopub.status.busy": "2024-09-24T09:56:29.451957Z", + "iopub.status.idle": "2024-09-24T09:56:29.517710Z", + "shell.execute_reply": "2024-09-24T09:56:29.517153Z", + "shell.execute_reply.started": "2024-09-24T09:56:29.452638Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "import openpyxl\n", + "import os,sys,shutil\n", + "import json\n", + "import math\n", + "import glob\n", + "import random\n", + "from pathlib import Path\n", + "import pymongo\n", + "\n", + "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", + "mydb = myclient[\"baogao\"]\n", + "mycol = mydb[\"pdf\"]\n", + "\n", + "place_id = 345321\n", + "\n", + "fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n", + "fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n", + "\n", + "filename = 'data/镇海炼化参加测试人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "for fn in fls:\n", + " dict2 = {}\n", + " fi_name =Path(fn).stem.split('-')[0]\n", + " #fi_name =Path(fn).stem\n", + " code = int(fi_name)\n", + " dxm = dict1[str(code)]['gh']\n", + " dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n", + " list2.append(dict2)\n", + " i +=1\n", + "x = mycol.insert_many(list2)\n", + "print('ok') " + ] + }, + { + "cell_type": "markdown", + "id": "e923022e-aef7-4c8e-84f9-b853e53ff820", + "metadata": {}, + "source": [ + "## 根据工号生成查询信息" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "f709fd4a-d0b0-44a9-a782-0c1ffd43f6b8", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T09:47:36.612690Z", + "iopub.status.busy": "2024-09-24T09:47:36.611927Z", + "iopub.status.idle": "2024-09-24T09:47:36.637765Z", + "shell.execute_reply": "2024-09-24T09:47:36.637249Z", + "shell.execute_reply.started": "2024-09-24T09:47:36.612619Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], + "source": [ + "import json\n", + "filename = 'data/镇海炼化参加测试人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "list2 = []\n", + "set1 = set()\n", + "for k, v in dict1.items():\n", + " if 'gh' in v.keys():\n", + " gh = v['gh']\n", + " if gh not in list1:\n", + " list1.append(v['gh'])\n", + " else:\n", + " list2.append(gh)\n", + "print(list2)" + ] + }, + { + "cell_type": "markdown", + "id": "d9464f81-9228-403a-9d78-090fb4ce0faa", + "metadata": {}, + "source": [ + "## 体测报告按部门分类" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "7eac364f-0fde-4853-9d2b-8c4c0c59a341", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T10:28:39.624502Z", + "iopub.status.busy": "2024-09-24T10:28:39.623736Z", + "iopub.status.idle": "2024-09-24T10:28:39.991374Z", + "shell.execute_reply": "2024-09-24T10:28:39.990804Z", + "shell.execute_reply.started": "2024-09-24T10:28:39.624428Z" + } + }, + "outputs": [], + "source": [ + "import os,sys,shutil\n", + "import json\n", + "import glob\n", + "from pathlib import Path\n", + "\n", + "fi_path = '/home/songyi/pdf-typescript/镇海石化'\n", + "new_path = 'file/镇海石化'\n", + "old = []\n", + "dict2 = {}\n", + "\n", + "filename = 'data/镇海炼化参加测试人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "fls = glob.glob(f'{fi_path}/*.pdf')\n", + "for fn in fls:\n", + " fi_name =Path(fn).stem.split('-')[0]\n", + " code = int(fi_name)\n", + " unit_path = Path(new_path,dict1[str(code)]['unit'])\n", + " unit_path.mkdir(parents = True, exist_ok = True)\n", + " n_name = Path(unit_path,Path(fn).stem+'.pdf')\n", + " if not os.path.exists(n_name):\n", + " shutil.copyfile(fn,n_name)" + ] + }, + { + "cell_type": "markdown", + "id": "d7bb270c-cc9e-413b-af36-17c33692e289", + "metadata": {}, + "source": [ + "## 生成体测报告打印明细表" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "d88bd5c4-1df3-457b-b65d-61692c45e7bd", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-24T10:30:51.115176Z", + "iopub.status.busy": "2024-09-24T10:30:51.114431Z", + "iopub.status.idle": "2024-09-24T10:30:51.335424Z", + "shell.execute_reply": "2024-09-24T10:30:51.334870Z", + "shell.execute_reply.started": "2024-09-24T10:30:51.115089Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "import os,sys,shutil\n", + "import json\n", + "import glob\n", + "from pathlib import Path\n", + "import openpyxl\n", + "\n", + "fi_path = '/home/songyi/pdf-typescript/镇海石化'\n", + "\n", + "filename = 'data/镇海炼化参加测试人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "fls = glob.glob(f'{fi_path}/*.pdf')\n", + "list1 = []\n", + "title = ['测试编号','姓名','性别','部门']\n", + "for fn in fls:\n", + " list2 = []\n", + " fi_name =Path(fn).stem.split('-')[0] \n", + " code = int(fi_name)\n", + " sex = dict1[str(code)]['sex']\n", + " unit = dict1[str(code)]['unit']\n", + " list2 = [fi_name,Path(fn).stem.split('-')[1],sex,unit]\n", + " \n", + " list1.append(list2)\n", + "\n", + "filename = 'data/镇海石化体测报告明细表.xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "sheet.append(title)\n", + "for row in list1:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename) \n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "6b521daf-f9dc-4579-9400-d8ab857bb166", + "metadata": {}, + "source": [ + "# 体质测试综合报告数据分析" + ] + }, + { + "cell_type": "markdown", + "id": "83203d08-46ca-45f6-8204-0c8e35f754b6", + "metadata": {}, + "source": [ + "## 清理报告数据" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "cccc2e43-7a73-48ec-8540-06b4d59f8ceb", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:06:13.897106Z", + "iopub.status.busy": "2024-09-22T11:06:13.896366Z", + "iopub.status.idle": "2024-09-22T11:06:13.985127Z", + "shell.execute_reply": "2024-09-22T11:06:13.984566Z", + "shell.execute_reply.started": "2024-09-22T11:06:13.897035Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok!\n" + ] + } + ], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "\n", + "filename = 'data/result_镇海2.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + " \n", + "#items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "items = {}\n", + "items['lung'] = '肺活量'\n", + "items['grip'] ='握力'\n", + "items['flexion'] ='坐位体前屈'\n", + "items['jump'] ='纵跳'\n", + "items['pushup'] ='俯卧撑'\n", + "items['balance'] ='单脚站立'\n", + "items['reaction'] ='选择反应时'\n", + "items['step'] ='台阶指数'\n", + "items['situp'] ='一分钟仰卧起坐'\n", + "items['bmi'] ='BMI'\n", + "\n", + "\n", + "list1 = []\n", + "#fiie_path ='./138/'\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", + "i=1\n", + "list2 = []\n", + "dict2 = {}\n", + "for k, v in dict1.items():\n", + " list1 = []\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(8,\"0\")\n", + " mydata['unit'] = v['unit']\n", + " mydata['name'] = v['name']\n", + " mydata['sex'] = v['sex']\n", + " mydata['month'] = v['month']\n", + " age = int(v['month']/12)\n", + " if age <20:\n", + " mydata['age'] = 20\n", + " else:\n", + " mydata['age'] = int(v['month']/12)\n", + " \n", + " mydata['fits'] = {}\n", + " score = 0\n", + " for item in list_item:\n", + " if item in v.keys():\n", + " if item in ['lung','pushup','step','situp']:\n", + " mark = v[item]['成绩'].split()[0].split('.')[0]\n", + " else:\n", + " mark = v[item]['成绩'].split()[0]\n", + " mydata['fits'][items[item]] = {'mark':mark,'score':v[item]['score']}\n", + " score = score + v[item]['score']\n", + " mydata['score'] = round(score/len(mydata['fits']),2)\n", + " if len(mydata['fits']) >2:\n", + " dict2[str(k)] = mydata\n", + "filename = f'data/data_镇海.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print('ok!') " + ] + }, + { + "cell_type": "markdown", + "id": "c3bcd7ec-1d66-40c6-a27d-1c73e6eef695", + "metadata": {}, + "source": [ + "## 计算平均成绩" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "d5721244-b5f5-4577-bae8-2e6c5bd8e4da", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:07:17.674314Z", + "iopub.status.busy": "2024-09-22T11:07:17.673571Z", + "iopub.status.idle": "2024-09-22T11:07:17.699078Z", + "shell.execute_reply": "2024-09-22T11:07:17.698099Z", + "shell.execute_reply.started": "2024-09-22T11:07:17.674240Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "平均成绩:3.1739分,男性:1074人\n", + "平均成绩:3.3303分,女性:291人\n", + "平均成绩:3.2072分,总体:1365人\n" + ] + } + ], + "source": [ + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "filename = 'data/data_镇海.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "i = 1\n", + "m = 0\n", + "f = 0\n", + "score = 0\n", + "t_score = 0\n", + "for k,v in dict1.items():\n", + " if v['sex'] == '男':\n", + " m = m +1\n", + " score = score+v['score']\n", + "print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')\n", + "t_score = t_score + score\n", + "score = 0\n", + "for k,v in dict1.items():\n", + " if v['sex'] == '女':\n", + " f = f +1\n", + " score = score+v['score']\n", + "print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n", + "t_score = t_score + score\n", + "print(f'平均成绩:{round(t_score/(f+m),4)}分,总体:{(f+m)}人')" + ] + }, + { + "cell_type": "markdown", + "id": "a7ba7d25-b7a0-4641-a218-b4569d31acb1", + "metadata": {}, + "source": [ + "## 计算测试等级" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "cff50f06-3221-4340-950f-3a24073b8565", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:09:10.042162Z", + "iopub.status.busy": "2024-09-22T11:09:10.041458Z", + "iopub.status.idle": "2024-09-22T11:09:10.113085Z", + "shell.execute_reply": "2024-09-22T11:09:10.112552Z", + "shell.execute_reply.started": "2024-09-22T11:09:10.042084Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0~255分人数:134人,男性:118人,女性:16人\n", + "256~332分人数:585人,男性:472人,女性:113人\n", + "333~367分人数:431人,男性:333人,女性:98人\n", + "368~500分人数:215人,男性:151人,女性:64人\n", + "1365\n", + "ok\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "\n", + "#filename = 'data/data_长炼医院.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "dict2 = {}\n", + "dict2['不合格'] = [0,255]\n", + "dict2['合格'] = [256,332]\n", + "dict2['良好'] = [333,367]\n", + "dict2['优秀'] = [368,500]\n", + "\n", + "for k1, v1 in dict2.items():\n", + " di = v1[0]\n", + " gao = v1[1]\n", + " i = 0 \n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if int(v['score']*100) in range(di,gao+1):\n", + " dict1[k]['level'] = k1\n", + " i+=1\n", + " if v['sex'] == '男':\n", + " m = m +1\n", + " else:\n", + " f = f+1\n", + " print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n", + "print(len(dict1))\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl) \n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "16a0d09b-2128-4df4-9745-954f48384244", + "metadata": {}, + "source": [ + "### 计算各年龄段测试等级(女)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "6baf0ff2-cdfa-4396-bcf8-3e23a18670dc", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:11:36.729958Z", + "iopub.status.busy": "2024-09-22T11:11:36.729223Z", + "iopub.status.idle": "2024-09-22T11:11:36.759840Z", + "shell.execute_reply": "2024-09-22T11:11:36.759298Z", + "shell.execute_reply.started": "2024-09-22T11:11:36.729889Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20-24 {'良好': 29, '合格': 60, '优秀': 22, '不合格': 8}\n", + "25-29 {'良好': 24, '合格': 32, '不合格': 3, '优秀': 14}\n", + "30-34 {'不合格': 3, '优秀': 6, '合格': 11, '良好': 15}\n", + "35-39 {'合格': 5, '不合格': 2, '良好': 13, '优秀': 6}\n", + "40-44 {'良好': 6, '合格': 1, '优秀': 1, '不合格': 0}\n", + "45-49 {'良好': 8, '合格': 4, '优秀': 12, '不合格': 0}\n", + "50-54 {'良好': 3, '不合格': 0, '合格': 0, '优秀': 2}\n", + "55-80 {'优秀': 1, '合格': 0, '良好': 0, '不合格': 0}\n" + ] + } + ], + "source": [ + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "dict2 = {}\n", + "dict2['不合格'] = [0,255]\n", + "dict2['合格'] = [256,332]\n", + "dict2['良好'] = [333,367]\n", + "dict2['优秀'] = [368,500]\n", + "dict3 = {}\n", + "for item in nld:\n", + " di = item[0]\n", + " gao = item[1]\n", + " age = f'{di}-{gao}'\n", + " dict3.setdefault(age,{})\n", + " i = 0 \n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if v['age'] in range(di,gao+1): \n", + " dict3[age].setdefault(v['level'],0)\n", + " if v['sex'] == '女':\n", + " dict3[age][v['level']] = dict3[age][v['level']]+1\n", + " \n", + "for k, v in dict3.items():\n", + " print(k,v)" + ] + }, + { + "cell_type": "markdown", + "id": "79fb3eab-e8d4-42bb-9ba4-8402f3b82b54", + "metadata": {}, + "source": [ + "### 计算各年龄段测试等级(男)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "2979cf80-5268-4754-ab8a-11a539315e92", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:14:29.282315Z", + "iopub.status.busy": "2024-09-22T11:14:29.281554Z", + "iopub.status.idle": "2024-09-22T11:14:29.310507Z", + "shell.execute_reply": "2024-09-22T11:14:29.309894Z", + "shell.execute_reply.started": "2024-09-22T11:14:29.282244Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20-24 {'良好': 97, '合格': 177, '优秀': 38, '不合格': 53}\n", + "25-29 {'良好': 57, '合格': 97, '不合格': 21, '优秀': 21}\n", + "30-34 {'不合格': 15, '优秀': 13, '合格': 43, '良好': 29}\n", + "35-39 {'合格': 57, '不合格': 11, '良好': 45, '优秀': 22}\n", + "40-44 {'良好': 27, '合格': 18, '优秀': 12, '不合格': 2}\n", + "45-49 {'良好': 26, '合格': 28, '优秀': 17, '不合格': 1}\n", + "50-54 {'良好': 33, '不合格': 10, '合格': 29, '优秀': 16}\n", + "55-80 {'优秀': 12, '合格': 23, '良好': 19, '不合格': 5}\n" + ] + } + ], + "source": [ + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "dict2 = {}\n", + "dict2['不合格'] = [0,255]\n", + "dict2['合格'] = [256,332]\n", + "dict2['良好'] = [333,367]\n", + "dict2['优秀'] = [368,500]\n", + "dict3 = {}\n", + "for item in nld:\n", + " di = item[0]\n", + " gao = item[1]\n", + " age = f'{di}-{gao}'\n", + " dict3.setdefault(age,{})\n", + " i = 0 \n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if v['age'] in range(di,gao+1): \n", + " dict3[age].setdefault(v['level'],0)\n", + " if v['sex'] == '男':\n", + " dict3[age][v['level']] = dict3[age][v['level']]+1\n", + " \n", + "for k, v in dict3.items():\n", + " print(k,v)" + ] + }, + { + "cell_type": "markdown", + "id": "9a38fc15-579c-42e9-a23c-1050a96e0cf8", + "metadata": {}, + "source": [ + "## 根据年龄汇总人员信息及成绩" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "8a7cb3b0-d7be-44ac-a1ec-40bdcf29e83b", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:16:13.093509Z", + "iopub.status.busy": "2024-09-22T11:16:13.092890Z", + "iopub.status.idle": "2024-09-22T11:16:13.121521Z", + "shell.execute_reply": "2024-09-22T11:16:13.120918Z", + "shell.execute_reply.started": "2024-09-22T11:16:13.093450Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "16~24岁平均成绩:3.11分,人数:484人,男性:365人\n", + "25~29岁平均成绩:3.16分,人数:269人,男性:196人\n", + "30~34岁平均成绩:3.15分,人数:135人,男性:100人\n", + "35~39岁平均成绩:3.3分,人数:161人,男性:135人\n", + "40~44岁平均成绩:3.39分,人数:67人,男性:59人\n", + "45~49岁平均成绩:3.48分,人数:96人,男性:72人\n", + "50~54岁平均成绩:3.29分,人数:93人,男性:88人\n", + "55~69岁平均成绩:3.27分,人数:60人,男性:59人\n" + ] + } + ], + "source": [ + "nld = [[16,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for item in nld:\n", + " di = item[0]\n", + " gao = item[1]\n", + " i = 0\n", + " score = 0\n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if v['age'] in range(di,gao+1):\n", + " score = score+v['score']\n", + " i+=1\n", + " if v['sex'] == '男':\n", + " m = m +1\n", + " if i ==0:\n", + " print(f'{di}~{gao}岁平均成绩:0分,人数:0人,男性:{m}人')\n", + " else:\n", + " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人,男性:{m}人')" + ] + }, + { + "cell_type": "markdown", + "id": "48debe3b-d0ec-41e8-93ef-921b8e013aa7", + "metadata": {}, + "source": [ + "### 根据年龄汇总人员信息及成绩(男)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "c5bb03ca-b7ee-4564-b425-8513e1bff081", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:18:31.953834Z", + "iopub.status.busy": "2024-09-22T11:18:31.953204Z", + "iopub.status.idle": "2024-09-22T11:18:31.982787Z", + "shell.execute_reply": "2024-09-22T11:18:31.982216Z", + "shell.execute_reply.started": "2024-09-22T11:18:31.953775Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20~24岁平均成绩:3.08分,人数:365人\n", + "25~29岁平均成绩:3.1分,人数:196人\n", + "30~34岁平均成绩:3.1分,人数:100人\n", + "35~39岁平均成绩:3.27分,人数:135人\n", + "40~44岁平均成绩:3.39分,人数:59人\n", + "45~49岁平均成绩:3.4分,人数:72人\n", + "50~54岁平均成绩:3.27分,人数:88人\n", + "55~80岁平均成绩:3.25分,人数:59人\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for item in nld:\n", + " di = item[0]\n", + " gao = item[1]\n", + " i = 0\n", + " score = 0\n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if v['age'] in range(di,gao+1) and v['sex'] == '男':\n", + " score = score+v['score']\n", + " i+=1\n", + " if i ==0:\n", + " print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人') \n", + " else:\n", + " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')" + ] + }, + { + "cell_type": "markdown", + "id": "92bb0683-81ea-4b90-8b74-4a2f43b4835c", + "metadata": {}, + "source": [ + "### 根据年龄汇总人员信息及成绩(女)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "bf333998-230c-4365-aadc-b0d1be073b39", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:20:46.582055Z", + "iopub.status.busy": "2024-09-22T11:20:46.581306Z", + "iopub.status.idle": "2024-09-22T11:20:46.606923Z", + "shell.execute_reply": "2024-09-22T11:20:46.606298Z", + "shell.execute_reply.started": "2024-09-22T11:20:46.581983Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20~24岁平均成绩:3.21分,人数:119人\n", + "25~29岁平均成绩:3.32分,人数:73人\n", + "30~34岁平均成绩:3.32分,人数:35人\n", + "35~39岁平均成绩:3.44分,人数:26人\n", + "40~44岁平均成绩:3.4分,人数:8人\n", + "45~49岁平均成绩:3.73分,人数:24人\n", + "50~54岁平均成绩:3.71分,人数:5人\n", + "55~80岁平均成绩:4.0分,人数:1人\n" + ] + } + ], + "source": [ + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for item in nld:\n", + " di = item[0]\n", + " gao = item[1]\n", + " i = 0\n", + " score = 0\n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if v['age'] in range(di,gao+1) and v['sex'] == '女':\n", + " score = score+v['score']\n", + " i+=1\n", + " if i ==0:\n", + " print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人') \n", + " else:\n", + " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')" + ] + }, + { + "cell_type": "markdown", + "id": "026d11e4-7f3d-4be5-9fa0-fa3699969c6b", + "metadata": {}, + "source": [ + "## 计算各项目成绩" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "352c6c29-8929-4210-84c5-8dbc3d5ffeee", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:21:51.501623Z", + "iopub.status.busy": "2024-09-22T11:21:51.500851Z", + "iopub.status.idle": "2024-09-22T11:21:51.526895Z", + "shell.execute_reply": "2024-09-22T11:21:51.526331Z", + "shell.execute_reply.started": "2024-09-22T11:21:51.501553Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "BMI 4.0 1364\n", + "肺活量 3.52 1364\n", + "握力 3.25 1361\n", + "坐位体前屈 2.93 1346\n", + "纵跳 3.4 1316\n", + "俯卧撑 3.65 1047\n", + "一分钟仰卧起坐 4.27 240\n", + "单脚站立 2.6 1356\n", + "选择反应时 2.88 1317\n", + "台阶指数 2.5 1286\n" + ] + } + ], + "source": [ + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "for item in items:\n", + " score = 0\n", + " n = 0\n", + " for k, v in dict1.items(): \n", + " if item in v['fits'].keys():\n", + " n = n + 1\n", + " score =score + int(v['fits'][item]['score'])\n", + " print(item,round(score/n,2),n)" + ] + }, + { + "cell_type": "markdown", + "id": "a13d5644-7cd1-4943-bce9-c6863f75b986", + "metadata": {}, + "source": [ + "## 按照部门计算平均成绩" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "97f5a1cf-341e-4b99-9549-b6a3fb165849", + "metadata": { + "execution": { + "iopub.execute_input": "2024-09-22T11:23:46.840351Z", + "iopub.status.busy": "2024-09-22T11:23:46.839524Z", + "iopub.status.idle": "2024-09-22T11:23:46.865572Z", + "shell.execute_reply": "2024-09-22T11:23:46.865072Z", + "shell.execute_reply.started": "2024-09-22T11:23:46.840276Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "采购中心 3.39 20\n", + "炼油三部 3.2 30\n", + "烯烃一部 3.21 156\n", + "炼油五部 3.26 72\n", + "公用工程二部 3.26 72\n", + "合成材料部 3.12 55\n", + "质管中心 3.24 56\n", + "储运一部 3.1 82\n", + "氢能制造部 3.18 59\n", + "电气中心 3.14 45\n", + "公用工程一部 3.12 81\n", + "仪表和计量中心 3.29 81\n", + "港储部 3.13 36\n", + "炼油二部 3.28 60\n", + "消防支队 3.35 25\n", + "烯烃二部 3.03 42\n", + "炼油一部 3.29 42\n", + "事务中心 3.17 35\n", + "公司机关 3.3 102\n", + "化学制品部 3.31 43\n", + "项目管理部 3.38 19\n", + "新材料研究院 3.31 15\n", + "炼油四部 3.08 27\n", + "油库中心 3.22 25\n", + "炼油六部 3.08 34\n", + "储运二部 3.12 13\n", + "宣传部 3.11 1\n", + "财务部 3.0 1\n", + "生产部 3.04 3\n", + "发展部 2.78 4\n", + "项目部 2.7 2\n", + "炼油七部 3.25 26\n", + "公用工程五部 2.8 1\n" + ] + } + ], + "source": [ + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "depart = []\n", + "for k, v in dict1.items():\n", + " if v['unit'] not in depart:\n", + " depart.append(v['unit'])\n", + "\n", + "for item in depart:\n", + " score = 0\n", + " n = 0\n", + " for k, v in dict1.items():\n", + " if item == v['unit']:\n", + " score = score + v['score']\n", + " n = n +1 \n", + " print(item,round(score/n,2),n)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "ef930e32-9413-4fb0-b9e4-ba548d89ec60", + "id": "0d043ccc-a241-4b72-912f-7609d3f794a7", "metadata": {}, "outputs": [], "source": [] diff --git a/数据处理.ipynb b/数据处理.ipynb index 54400f2..1c6ebb5 100644 --- a/数据处理.ipynb +++ b/数据处理.ipynb @@ -557,6 +557,39 @@ "print(dict1)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 生成导入数据库语句" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "from datetime import date\n", + "\n", + "wb = openpyxl.load_workbook('data/镇海体测手工数据.xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "dict1 = {}\n", + "list1 = []\n", + "for n in range(1, sheet.max_row+1):\n", + " id = int(sheet.cell(n, 1).value)\n", + " item = int(sheet.cell(n, 2).value)\n", + " perf = int(sheet.cell(n, 3).value)\n", + " s = f'(345321,{id},{item},{perf},\"2024-09-22\",\"2024-09-22 18:00:00\")'\n", + " list1.append(s)\n", + "ss = ','.join(list1)\n", + "print(ss)\n", + " " + ] + }, { "cell_type": "markdown", "metadata": {