From 6803e6fff6ba2f5ad777e3fe34eb4e4a82e7f59d Mon Sep 17 00:00:00 2001 From: 512song Date: Mon, 15 Dec 2025 08:11:54 +0800 Subject: [PATCH] 250251215 --- 体测单位/东营老年大学.ipynb | 315 +++++++++- 体测单位/体质检测数据处理.ipynb | 42 +- 体测单位/天津石化.ipynb | 844 +++++++++++++++----------- 体测单位/宁夏能化.ipynb | 359 +++++++++-- 体测单位/新疆油田采油工艺研究院.ipynb | 482 +++++++++------ 文件管理.ipynb | 42 +- 6 files changed, 1464 insertions(+), 620 deletions(-) diff --git a/体测单位/东营老年大学.ipynb b/体测单位/东营老年大学.ipynb index 22d879f..62c7c21 100644 --- a/体测单位/东营老年大学.ipynb +++ b/体测单位/东营老年大学.ipynb @@ -63,6 +63,59 @@ "print('ok')" ] }, + { + "cell_type": "code", + "execution_count": 24, + "id": "27a49c91-b122-47cf-806a-6b252787b2db", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-12T13:13:24.043753Z", + "iopub.status.busy": "2025-12-12T13:13:24.042051Z", + "iopub.status.idle": "2025-12-12T13:13:24.065063Z", + "shell.execute_reply": "2025-12-12T13:13:24.064583Z", + "shell.execute_reply.started": "2025-12-12T13:13:24.043682Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n", + "ok\n" + ] + } + ], + "source": [ + "import openpyxl\n", + "import json\n", + "from datetime import date\n", + "\n", + "wb = openpyxl.load_workbook('data/东营油田老年大学体质检测名单(2512).xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "person = {}\n", + "\n", + "for n in range(2, sheet.max_row+1):\n", + " if sheet.cell(n,1).value is not None:\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'] = ''\n", + " dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]\n", + " #dict1['age'] = sheet.cell(n, 6).value\n", + " if sheet.cell(n,5).value is not None:\n", + " dict1['phone'] = str(sheet.cell(n,5).value) \n", + " person[code] = dict1\n", + "filename = 'data/油田老年大学2025年度体质复测.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(person, fl, ensure_ascii=False)\n", + "print(len(person))\n", + "print('ok')" + ] + }, { "cell_type": "code", "execution_count": 88, @@ -341,6 +394,85 @@ "print(len(re_ta))" ] }, + { + "cell_type": "code", + "execution_count": 25, + "id": "dcc5a261-35ef-48c2-b4dd-618f417e45dc", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-12T13:13:33.184367Z", + "iopub.status.busy": "2025-12-12T13:13:33.183622Z", + "iopub.status.idle": "2025-12-12T13:13:33.204374Z", + "shell.execute_reply": "2025-12-12T13:13:33.203788Z", + "shell.execute_reply.started": "2025-12-12T13:13:33.184296Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n" + ] + } + ], + "source": [ + "import json\n", + "import datetime\n", + "import csv\n", + "from datetime import date\n", + "\n", + "\n", + "re_ta = {}\n", + "list1 = []\n", + "filename = 'data/油田老年大学2025年度体质复测.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "filename = 'data/marks_20251212.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", + "\n", + "for result in list1:\n", + " user = str(result[2])\n", + " rq = date.fromisoformat(result[5].replace('/','-'))\n", + " if user in dict1.keys():\n", + " #print(user)\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", + " re_ta[user]['birth'] = dict1[user]['birth']\n", + " re_ta[user]['unit'] = dict1[user]['unit']\n", + " if 'phone' in dict1[user].keys():\n", + " re_ta[user]['phone'] = dict1[user]['phone']\n", + " if dict1[user]['sex'] == '男':\n", + " l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step']\n", + " else:\n", + " l_xm = ['bmi','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", + " item_name = result[3] \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[5]\n", + " re_ta[user].setdefault(item_name,{}) \n", + " score = result[4] \n", + " re_ta[user][item_name]['成绩'] = score\n", + "\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\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": "74ec60b7-b1d9-488d-95fa-4ddd020c2a4c", @@ -351,15 +483,15 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 26, "id": "c3b99428-00d5-45ea-9803-261194525fa4", "metadata": { "execution": { - "iopub.execute_input": "2025-04-07T12:39:35.778154Z", - "iopub.status.busy": "2025-04-07T12:39:35.777362Z", - "iopub.status.idle": "2025-04-07T12:39:35.793555Z", - "shell.execute_reply": "2025-04-07T12:39:35.792548Z", - "shell.execute_reply.started": "2025-04-07T12:39:35.778096Z" + "iopub.execute_input": "2025-12-12T13:13:35.809342Z", + "iopub.status.busy": "2025-12-12T13:13:35.808036Z", + "iopub.status.idle": "2025-12-12T13:13:35.820106Z", + "shell.execute_reply": "2025-12-12T13:13:35.818957Z", + "shell.execute_reply.started": "2025-12-12T13:13:35.809273Z" } }, "outputs": [ @@ -378,7 +510,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_陈庄检测人员-2.json'\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", @@ -401,7 +533,7 @@ " dict2[k][item_en]['score'] = My.cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", - "filename = f'data/result_陈庄检测人员-2.json'\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " @@ -874,6 +1006,142 @@ " json.dump(dict1, fl, ensure_ascii=False) " ] }, + { + "cell_type": "code", + "execution_count": 35, + "id": "0ba2e1a3-78c8-44d9-ab7d-b17b52b0a99f", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-12T13:38:13.857680Z", + "iopub.status.busy": "2025-12-12T13:38:13.856977Z", + "iopub.status.idle": "2025-12-12T13:38:13.880423Z", + "shell.execute_reply": "2025-12-12T13:38:13.879532Z", + "shell.execute_reply.started": "2025-12-12T13:38:13.857614Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15684378667\n", + "15684378667\n", + "13699180673\n", + "15105461296\n", + "13012909096\n", + "13954605763\n", + "13287350839\n", + "13561090015\n", + "13287336162\n", + "13963396946\n", + "15105461298\n", + "13864739068\n", + "13013569039\n", + "13864757610\n", + "15725185717\n" + ] + } + ], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "dict1 = {}\n", + "\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl)\n", + "\n", + "\n", + "list1 = []\n", + "filename = 'data/sql_20251212.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", + " list1.append(line)\n", + "#print(list1)\n", + "dict2 = {}\n", + "\n", + "for item in list1:\n", + " psy = []\n", + " tcm = []\n", + " spine = []\n", + " for i in range(0,30):\n", + " psy.append(0)\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for i in range(0,26):\n", + " spine.append(0)\n", + " phone = item[0][2:]\n", + " print(phone)\n", + " for k1, v1 in dict3.items():\n", + " if 'phone' in v1.keys() and phone ==v1['phone']: \n", + " dict1[k1] = dict3[k1]\n", + " #dict1[k1]['month'] = dict1[k1]['age'] *12\n", + "for item in list1:\n", + " #print(item)\n", + " psy = []\n", + " tcm = []\n", + " spine = []\n", + " for i in range(0,30):\n", + " psy.append(0)\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for i in range(0,26):\n", + " spine.append(0)\n", + " phone = item[0][2:]\n", + " for k1, v1 in dict1.items():\n", + " #print((k1,v1))\n", + " if 'phone' in v1.keys() and phone ==v1['phone']: \n", + " content = json.loads(item[1])\n", + " #print(content)\n", + " \n", + " rq = date.fromisoformat(item[2].replace('/','-').split(' ')[0])\n", + " #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", + " for k, v in json.loads(content).items():\n", + " #print('k:',k,'v:',v)\n", + " if 'psyOld' in k: \n", + " i = int(k[6:])\n", + " psy[i-1] = int(v)\n", + " if 'tcm' in k: \n", + " i = int(k[3:])\n", + " tcm[i-1] = int(v)\n", + " if 'spine' in k:\n", + " i = int(k[5:])\n", + " spine[i-1] = int(v)\n", + " if 'psyOld' in item[1]:\n", + " \n", + " dict1[k1]['psy_yangmiao_old'] = psy\n", + " if 'tcm' in item[1]:\n", + " \n", + " dict1[k1]['tcm'] = tcm\n", + " if 'spine' in item[1]:\n", + " for ii in range(25,23,-1):\n", + " \n", + " spine[ii] = spine[ii-1]\n", + " \n", + " spine[22] = 0\n", + " \n", + " \n", + " \n", + " dict1[k1]['spine'] = spine\n", + " #birth = date.fromisoformat(dict3[k1]['birth'].replace('/','-'))\n", + "\n", + " #days = (rq-birth).days \n", + " #dict1[k1]['age'] = int(days/365)\n", + " \n", + " dict1[k1]['rq'] = item[2].replace('/','-').split(' ')[0]\n", + "#print(dict1)\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False) " + ] + }, { "cell_type": "markdown", "id": "85d087e3-c469-409e-893b-a22789d73613", @@ -1037,15 +1305,15 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 36, "id": "7ee80847-2bc0-4cbe-9534-c5dcf97c2833", "metadata": { "execution": { - "iopub.execute_input": "2025-04-07T12:40:25.086716Z", - "iopub.status.busy": "2025-04-07T12:40:25.086178Z", - "iopub.status.idle": "2025-04-07T12:40:51.228212Z", - "shell.execute_reply": "2025-04-07T12:40:51.227012Z", - "shell.execute_reply.started": "2025-04-07T12:40:25.086666Z" + "iopub.execute_input": "2025-12-12T13:38:35.200844Z", + "iopub.status.busy": "2025-12-12T13:38:35.200220Z", + "iopub.status.idle": "2025-12-12T13:38:42.941941Z", + "shell.execute_reply": "2025-12-12T13:38:42.941270Z", + "shell.execute_reply.started": "2025-12-12T13:38:35.200787Z" } }, "outputs": [ @@ -1053,7 +1321,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "56\n" + "12\n" ] } ], @@ -1066,11 +1334,11 @@ "headers = {\n", " \"Content-Type\": \"application/json; charset=UTF-8\"\n", " }\n", - "filename = 'data/result_陈庄检测人员-2.json'\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", - "file_path ='./东营陈庄2/'\n", + "file_path ='./油田老年大学年度体质复测/'\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", "i=0\n", "list2 = []\n", @@ -1080,7 +1348,7 @@ " \n", " id = str(k).rjust(4,\"0\")\n", " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", - " mydata['title'] = '山东东营陈庄镇'\n", + " mydata['title'] = '油田老年大学年度体质复测'\n", " mydata['subtitle'] = v['unit']\n", " mydata['id'] = id\n", " mydata['name'] = v['name']\n", @@ -1090,7 +1358,15 @@ " mydata['gender'] = 'female'\n", " \n", " mydata['month'] = v['month']\n", + " mydata['fits'] = {}\n", + " survey_list = ['tcm','psy_yangmiao_old','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", @@ -1100,7 +1376,8 @@ " 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", + " #if len(mydata['fits']) >2 : \n", + " if len(mydata['fits']) >2 or 'surveys' in mydata.keys():\n", " list1.append(mydata)\n", " list2.append([k,v['name']])\n", " i+=1\n", diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index d339e23..367f796 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -2310,15 +2310,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "6f9768ce-2ef5-4253-9fc6-49dbdcf00a19", "metadata": { "execution": { - "iopub.execute_input": "2025-12-04T01:12:54.320249Z", - "iopub.status.busy": "2025-12-04T01:12:54.319633Z", - "iopub.status.idle": "2025-12-04T01:12:54.339019Z", - "shell.execute_reply": "2025-12-04T01:12:54.337721Z", - "shell.execute_reply.started": "2025-12-04T01:12:54.320195Z" + "iopub.execute_input": "2025-12-12T13:17:17.795264Z", + "iopub.status.busy": "2025-12-12T13:17:17.794719Z", + "iopub.status.idle": "2025-12-12T13:17:17.805357Z", + "shell.execute_reply": "2025-12-12T13:17:17.804292Z", + "shell.execute_reply.started": "2025-12-12T13:17:17.795214Z" } }, "outputs": [], @@ -2672,23 +2672,35 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "id": "9ecd3ad8-c8af-4f3e-90e5-1618fea905a4", "metadata": { "execution": { - "iopub.execute_input": "2025-12-04T01:13:55.931481Z", - "iopub.status.busy": "2025-12-04T01:13:55.930100Z", - "iopub.status.idle": "2025-12-04T01:13:55.996588Z", - "shell.execute_reply": "2025-12-04T01:13:55.996041Z", - "shell.execute_reply.started": "2025-12-04T01:13:55.931411Z" + "iopub.execute_input": "2025-12-12T13:46:10.803542Z", + "iopub.status.busy": "2025-12-12T13:46:10.802812Z", + "iopub.status.idle": "2025-12-12T13:46:10.973193Z", + "shell.execute_reply": "2025-12-12T13:46:10.972533Z", + "shell.execute_reply.started": "2025-12-12T13:46:10.803460Z" } }, - "outputs": [], + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[9], line 57\u001b[0m\n\u001b[1;32m 55\u001b[0m psy\u001b[38;5;241m=\u001b[39mv[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpsy_yangmiao_old\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 56\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m26\u001b[39m,\u001b[38;5;241m40\u001b[39m):\n\u001b[0;32m---> 57\u001b[0m new_valve \u001b[38;5;241m=\u001b[39m \u001b[43mpsy\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 58\u001b[0m psy[i] \u001b[38;5;241m=\u001b[39m new_valve\n\u001b[1;32m 59\u001b[0m dict3 \u001b[38;5;241m=\u001b[39m {}\n", + "\u001b[0;31mIndexError\u001b[0m: list index out of range" + ] + } + ], "source": [ "import openpyxl\n", "\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", - "filename = 'data/result_新疆油田采油工艺研究院2511.json'\n", + "filename = 'data/result_油田老年大学年度体质复测.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "data_list = []\n", @@ -2770,7 +2782,7 @@ " list6.append('')\n", " i+=1\n", " data_list.append(list6)\n", - "filename = 'data/新疆油田采油工艺研究院体质检测明细表(2025年11月).xlsx'\n", + "filename = 'data/油田老年大学年度体质复测体质检测明细表(2025年11月).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "title = ['编号', '姓名', '性别', '单位/部门', '年龄', '身高', '体重', 'bmi', '肺活量', '得分', '握力', '得分', '坐位体前屈', '得分', '纵跳', '得分', '俯卧撑', '得分', '单脚站立', '得分', '选择反应时', '得分', '台阶指数', '得分', '一分钟仰卧起坐', '得分', '中医体质', '是否倾向', '平和', '气虚', '阳虚', '阴虚', '痰湿', '湿热', '血瘀', '气郁', '特禀', '成就感', '愉快心理', '放松程度', '压力应对', '体力充沛', '情感充沛度', '颈椎', '胸椎', '腰椎', '骶尾椎']\n", diff --git a/体测单位/天津石化.ipynb b/体测单位/天津石化.ipynb index 0abc31c..72308cf 100644 --- a/体测单位/天津石化.ipynb +++ b/体测单位/天津石化.ipynb @@ -2793,9 +2793,7 @@ { "cell_type": "markdown", "id": "08bcbf58-4356-4f30-850f-0d0ff0e2528b", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ "# 第三次体测(2024年10月)" ] @@ -3941,26 +3939,10 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": null, "id": "d0368e0f-270b-47fd-aec0-cae3cadd68b2", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-04T12:11:07.227210Z", - "iopub.status.busy": "2025-12-04T12:11:07.226601Z", - "iopub.status.idle": "2025-12-04T12:11:08.296200Z", - "shell.execute_reply": "2025-12-04T12:11:08.295131Z", - "shell.execute_reply.started": "2025-12-04T12:11:07.227149Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import requests\n", "import json\n", @@ -4076,9 +4058,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 129, "id": "b9f88d36-e72a-4f26-8357-62c7b0e2128d", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-12T08:29:57.850673Z", + "iopub.status.busy": "2025-12-12T08:29:57.850426Z", + "iopub.status.idle": "2025-12-12T08:30:01.391878Z", + "shell.execute_reply": "2025-12-12T08:30:01.391315Z", + "shell.execute_reply.started": "2025-12-12T08:29:57.850650Z" + } + }, "outputs": [], "source": [ "import os,sys,shutil\n", @@ -4097,7 +4087,7 @@ "fls = glob.glob(f'{fi_path}/*.pdf')\n", "for fn in fls:\n", " fi_name =Path(fn).stem.split('-')[0]\n", - " code = fi_name\n", + " code = int(fi_name)\n", " unit_path = Path(new_path,dict1[str(code)]['unit'],dict1[str(code)]['sub_unit'])\n", " unit_path.mkdir(parents = True, exist_ok = True)\n", " n_name = Path(unit_path,Path(fn).stem+'.pdf')\n", @@ -4105,6 +4095,52 @@ " shutil.copyfile(fn,n_name)" ] }, + { + "cell_type": "markdown", + "id": "efb959c7-8c1f-44d5-b0c0-cf9b4773fb6d", + "metadata": {}, + "source": [ + "## 体测报告按日期_编号分类" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "71a8a3fe-4668-4f2c-98d2-e3b432f1882c", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-12T08:32:03.116678Z", + "iopub.status.busy": "2025-12-12T08:32:03.115718Z", + "iopub.status.idle": "2025-12-12T08:32:04.143449Z", + "shell.execute_reply": "2025-12-12T08:32:04.142955Z", + "shell.execute_reply.started": "2025-12-12T08:32:03.116623Z" + } + }, + "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-fit2023/天津石化2025'\n", + "new_path = 'file/天津石化2025'\n", + "old = []\n", + "dict2 = {}\n", + "\n", + "filename = 'data/result_天津石化2025-2.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 = fi_name\n", + " rq = dict1[code]['rq'].replace('-','')\n", + " n_name = Path(new_path,code+'_'+rq+'.pdf')\n", + " if not os.path.exists(n_name):\n", + " shutil.copyfile(fn,n_name)" + ] + }, { "cell_type": "markdown", "id": "d4950051-c196-461a-a862-758ad014923d", @@ -4115,26 +4151,10 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "id": "d5ec9835-0f8d-4755-8fa1-b0a1f7f35bfc", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-04T01:42:19.668220Z", - "iopub.status.busy": "2025-12-04T01:42:19.667596Z", - "iopub.status.idle": "2025-12-04T01:46:02.421978Z", - "shell.execute_reply": "2025-12-04T01:46:02.421489Z", - "shell.execute_reply.started": "2025-12-04T01:42:19.668162Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import pdfplumber\n", "import os,sys,shutil\n", @@ -4180,26 +4200,10 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": null, "id": "e48afdab-13f5-492a-9c14-72e00a883cdd", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-05T04:28:27.297909Z", - "iopub.status.busy": "2025-12-05T04:28:27.297070Z", - "iopub.status.idle": "2025-12-05T04:32:11.169088Z", - "shell.execute_reply": "2025-12-05T04:32:11.168527Z", - "shell.execute_reply.started": "2025-12-05T04:28:27.297834Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3740\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import pdfplumber\n", "import os,sys,shutil\n", @@ -4221,16 +4225,16 @@ " list1 = text.split('\\n')\n", " for item in list1:\n", " if '感谢您完成测试' in item:\n", + " i = list1.index(item)\n", + " ss = ''.join(list1[i:])\n", " score_pattern = r\"分为(\\d+)\"\n", - " score_match = re.search(score_pattern, text)\n", + " score_match = re.search(score_pattern, ss)\n", " if score_match:\n", " average_score = score_match.group(1)\n", " else:\n", " average_score = ''\n", - "\n", - "# 提取等级信息(包括括号内的内容)\n", " grade_pattern = r\"等级为([^,]+)\"\n", - " grade_match = re.search(grade_pattern, text)\n", + " grade_match = re.search(grade_pattern, ss)\n", " if grade_match:\n", " grade = grade_match.group(1) \n", " else:\n", @@ -4239,7 +4243,7 @@ " dict1[code]['等级'] = grade.split('(')[0] \n", " \n", " \n", - "filename = 'data/天津石化体测报告提取数据(得分及等级).json'\n", + "filename = 'data/天津石化体测报告提取数据(得分及等级)-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False) \n", "print(len(dict1)) " @@ -4247,17 +4251,9 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": null, "id": "c624a091-4851-4f3a-83c9-83520b20603b", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-05T06:39:21.668327Z", - "iopub.status.busy": "2025-12-05T06:39:21.667654Z", - "iopub.status.idle": "2025-12-05T06:39:21.677684Z", - "shell.execute_reply": "2025-12-05T06:39:21.676710Z", - "shell.execute_reply.started": "2025-12-05T06:39:21.668269Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import json\n", @@ -4273,26 +4269,10 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "id": "e40caa62-9f50-4480-964e-177e88549425", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-04T01:50:28.395443Z", - "iopub.status.busy": "2025-12-04T01:50:28.394915Z", - "iopub.status.idle": "2025-12-04T01:50:28.426527Z", - "shell.execute_reply": "2025-12-04T01:50:28.425998Z", - "shell.execute_reply.started": "2025-12-04T01:50:28.395395Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'纵跳', '请注意:以上测试项目及格线为60分。列表中红色项目需重点关注,建议在专家指导下进行科学锻炼,', '选择反应时', '肺活量', '俯卧撑', '闭眼单脚站立', '坐位体前屈', '1分钟仰卧起坐', '腰臀比', '减少潜在的运动风险。', '握力', '身高体重指数', '台阶指数'}\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "filename = 'data/天津石化体测报告提取数据.json'\n", "with open(filename,'r') as fl:\n", @@ -4306,26 +4286,10 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": null, "id": "1edd3188-e28f-459c-a7f3-369393e43b47", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-04T12:18:14.866809Z", - "iopub.status.busy": "2025-12-04T12:18:14.866039Z", - "iopub.status.idle": "2025-12-04T12:18:15.086401Z", - "shell.execute_reply": "2025-12-04T12:18:15.085861Z", - "shell.execute_reply.started": "2025-12-04T12:18:14.866737Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3740\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "\n", @@ -4378,15 +4342,15 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 127, "id": "ed42e2f1-c024-4d29-86c3-b47edb97724f", "metadata": { "execution": { - "iopub.execute_input": "2025-12-05T06:51:04.517628Z", - "iopub.status.busy": "2025-12-05T06:51:04.516907Z", - "iopub.status.idle": "2025-12-05T06:51:04.714115Z", - "shell.execute_reply": "2025-12-05T06:51:04.713629Z", - "shell.execute_reply.started": "2025-12-05T06:51:04.517561Z" + "iopub.execute_input": "2025-12-08T06:18:06.610510Z", + "iopub.status.busy": "2025-12-08T06:18:06.609836Z", + "iopub.status.idle": "2025-12-08T06:18:06.795571Z", + "shell.execute_reply": "2025-12-08T06:18:06.795011Z", + "shell.execute_reply.started": "2025-12-08T06:18:06.610481Z" } }, "outputs": [ @@ -4402,7 +4366,7 @@ "filename = 'data/data_天津石化2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", - "filename = 'data/天津石化体测报告提取数据(得分及等级).json'\n", + "filename = 'data/天津石化体测报告提取数据(得分及等级)-1.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "items = ['纵跳','选择反应时','肺活量','俯卧撑','闭眼单脚站立','坐位体前屈','1分钟仰卧起坐','握力','台阶指数','身高体重指数']\n", @@ -4430,15 +4394,15 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 128, "id": "5f7cbf7c-ad59-4c84-8592-34ae71c10e26", "metadata": { "execution": { - "iopub.execute_input": "2025-12-05T07:11:47.233380Z", - "iopub.status.busy": "2025-12-05T07:11:47.232806Z", - "iopub.status.idle": "2025-12-05T07:11:48.772073Z", - "shell.execute_reply": "2025-12-05T07:11:48.771510Z", - "shell.execute_reply.started": "2025-12-05T07:11:47.233324Z" + "iopub.execute_input": "2025-12-10T10:21:04.978876Z", + "iopub.status.busy": "2025-12-10T10:21:04.978184Z", + "iopub.status.idle": "2025-12-10T10:21:06.635144Z", + "shell.execute_reply": "2025-12-10T10:21:06.634552Z", + "shell.execute_reply.started": "2025-12-10T10:21:04.978818Z" } }, "outputs": [], @@ -4446,13 +4410,16 @@ "import json\n", "import openpyxl\n", "\n", - "title = ['编号', '姓名', '性别', '部门', '车间','年龄', '身高体重指数', '肺活量', '得分', '握力', '得分', '坐位体前屈', '得分', '纵跳', '得分', '俯卧撑', '得分', '单脚站立', '得分', '选择反应时', '得分', '一分钟仰卧起坐', '得分','台阶指数', '得分','腰臀比','状态','平均分','等级']\n", + "title = ['编号', '姓名', '性别', '部门', '车间','年龄', '身高体重指数', '得分','肺活量', '得分', '握力', '得分', '坐位体前屈', '得分', '纵跳', '得分', '俯卧撑', '得分', '单脚站立', '得分', '选择反应时', '得分', '一分钟仰卧起坐', '得分','台阶指数', '得分','腰臀比','状态','平均分','等级']\n", "items = ['身高体重指数','肺活量','握力','坐位体前屈','纵跳','俯卧撑','闭眼单脚站立','选择反应时','1分钟仰卧起坐','台阶指数','腰臀比']\n", "\n", "list1 = []\n", "filename = 'data/data_天津石化2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", + "filename = 'data/result_天津石化2025-2.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", "\n", "for k, v in dict1.items():\n", " list2 = []\n", @@ -4461,6 +4428,14 @@ " list2.append(v['sex'])\n", " list2.append(v['unit'])\n", " list2.append(v['sub_unit'])\n", + " list2.append(v['age'])\n", + " list2.append(dict2[k]['rq'])\n", + " if 'bmi' in dict2[k].keys():\n", + " list2.append( dict2[k]['bmi']['成绩'].split(',')[0])\n", + " list2.append( dict2[k]['bmi']['成绩'].split(',')[1])\n", + " else:\n", + " list2.append('')\n", + " list2.append('') \n", " for item in items:\n", " if item in v.keys():\n", " list2.append(v[item]['mark'])\n", @@ -4470,17 +4445,14 @@ " list2.append('') \n", " list2.append(v['平均分'])\n", " list2.append(v['等级'])\n", - " list1.append(list2)\n", - " \n", - "\n", + " list1.append(list2) \n", "\n", "filename = 'data/天津石化体测报告数据(2025年).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list1:\n", - " sheet.append(row)\n", - " \n", + " sheet.append(row) \n", "wb.save(filename) \n" ] }, @@ -4495,93 +4467,12 @@ "shell.execute_reply": "2023-10-25T02:50:57.004773Z", "shell.execute_reply.started": "2023-10-25T02:50:56.997463Z" }, - "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "# 体测数据分析" ] }, - { - "cell_type": "markdown", - "id": "dca06570-73e6-4f60-8cf9-b3f9da64f1c4", - "metadata": {}, - "source": [ - "## 清理报告数据" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f9fee64f-41ff-4453-8a32-a33df086022e", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import json\n", - "import openpyxl\n", - "\n", - "\n", - "filename = 'data/result_天津231017.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 ='./134/'\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_天津231017.json'\n", - "with open(filename,'w') as fl:\n", - " json.dump(dict2,fl , ensure_ascii=False) \n", - "print('ok!') " - ] - }, { "cell_type": "markdown", "id": "bd1f8f42-c14a-4bb7-8656-14a0f7968cfc", @@ -4603,31 +4494,25 @@ "\n", "items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", - "filename = 'data/data_天津231017_非倒班.json'\n", + "filename = 'data/data_天津石化2025.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", + "level = ['一级','二级','三级','四级']\n", "\n", - "for k1, v1 in dict2.items():\n", - " di = v1[0]\n", - " gao = v1[1]\n", + "for item in level:\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", + " if v['等级'] == item:\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))" + " print(f'{item}人数:{i}人,男性:{m}人,女性:{f}人')\n", + "#print(len(dict1))" ] }, { @@ -4660,9 +4545,9 @@ " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1):\n", - " score = score+v['score']\n", + " score = score + int(v['平均分'])\n", " i+=1\n", - " if v['sex'] == '男':\n", + " if v['sex'] == '女':\n", " m = m +1\n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人,男性:{m}人')" @@ -4700,7 +4585,7 @@ " 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", + " score = score+int(v['平均分'])\n", " i+=1\n", " \n", " \n", @@ -4739,7 +4624,7 @@ " 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", + " score = score+int(v['平均分'])\n", " i+=1\n", " \n", " \n", @@ -4777,14 +4662,14 @@ "for k,v in dict1.items():\n", " if v['sex'] == '男':\n", " m = m +1\n", - " score = score+v['score']\n", + " score = score+int(v['平均分'])\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", + " score = score+int(v['平均分'])\n", "print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n", "t_score = t_score + score\n", "print(f'平均成绩:{round(t_score/3657,4)}分,总体:3657人')" @@ -4812,31 +4697,20 @@ "\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", + "level = ['一级','二级','三级','四级']\n", "\n", - "for k1, v1 in dict2.items():\n", - " di = v1[0]\n", - " gao = v1[1]\n", + "for item in level:\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", + " if v['等级'] == item:\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", - "#filename = 'data/result_石家庄.json'\n", - "with open(filename,'w') as fl:\n", - " json.dump(dict1, fl) \n", - "print('ok')" + " print(f'{item}人数:{i}人,男性:{m}人,女性:{f}人')" ] }, { @@ -4854,36 +4728,27 @@ "metadata": {}, "outputs": [], "source": [ - "import json\n", - "\n", - "\n", + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "level = ['一级','二级','三级','四级']\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", + "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 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", - "#filename = 'data/result_石家庄.json'\n", - "with open(filename,'w') as fl:\n", - " json.dump(dict1, fl) \n", - "print('ok')" + " if v['age'] in range(di,gao+1): \n", + " dict3[age].setdefault(v['等级'],0)\n", + " if v['sex'] == '男':\n", + " dict3[age][v['等级']] = dict3[age][v['等级']]+1\n", + " \n", + "for k, v in dict3.items():\n", + " print(k,v)" ] }, { @@ -4891,7 +4756,7 @@ "id": "194217e0-f1cf-4945-ad5a-52304ed2f943", "metadata": {}, "source": [ - "## 计算各项目成绩" + "## 计算无年龄限制项目成绩" ] }, { @@ -4905,15 +4770,214 @@ "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", - "items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "items = ['纵跳','选择反应时','肺活量','俯卧撑','闭眼单脚站立','坐位体前屈','1分钟仰卧起坐','握力','台阶指数','身高体重指数']\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", + " if item in v.keys():\n", " n = n + 1\n", - " score =score + int(v['fits'][item]['score'])\n", - " print(item,round(score/n,2),n)" + " score =score + int(v[item]['score'])\n", + " if n>0:\n", + " print(item,round(score/n,2),n)\n", + " else:\n", + " print(item,0)" + ] + }, + { + "cell_type": "markdown", + "id": "69323553-a963-4bb7-a1d0-ec450035bffb", + "metadata": {}, + "source": [ + "## 计算有年龄限制项目成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d2cfb07b-648c-426b-824e-83a512849a3c", + "metadata": {}, + "outputs": [], + "source": [ + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "items = ['纵跳','选择反应时','肺活量','俯卧撑','闭眼单脚站立','坐位体前屈','1分钟仰卧起坐','握力','台阶指数','身高体重指数']\n", + "\n", + "score = 0\n", + "n = 0\n", + "for k, v in dict1.items(): \n", + " if '纵跳' in v.keys() and v['age']<50:\n", + " n = n + 1\n", + " score =score + int(v['纵跳']['score'])\n", + "if n>0:\n", + " print('纵跳',round(score/n,2),n)\n", + "else:\n", + " print('纵跳',0)" + ] + }, + { + "cell_type": "markdown", + "id": "31506d33-4d41-4221-bc7f-feadd1475733", + "metadata": {}, + "source": [ + "## 分析腰臀比情况" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "df8b3211-a8fb-4687-ae81-a9fb12f46e3c", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-08T03:17:15.473341Z", + "iopub.status.busy": "2025-12-08T03:17:15.472735Z", + "iopub.status.idle": "2025-12-08T03:17:15.525161Z", + "shell.execute_reply": "2025-12-08T03:17:15.524615Z", + "shell.execute_reply.started": "2025-12-08T03:17:15.473283Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "正常人数:2856人,男性:1980人,女性:876人\n", + "较高人数:572人,男性:410人,女性:162人\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "level = ['正常', '较高']\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "for item in level:\n", + " i = 0 \n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items():\n", + " if '腰臀比' in v.keys() and v['腰臀比']['score'] == item:\n", + " i+=1\n", + " if v['sex'] == '男':\n", + " m = m +1\n", + " else:\n", + " f = f+1\n", + " print(f'{item}人数:{i}人,男性:{m}人,女性:{f}人')" + ] + }, + { + "cell_type": "markdown", + "id": "594fee88-208e-4429-9453-879e1903b72b", + "metadata": {}, + "source": [ + "## 分析腰臀比年龄段情况" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "935f9e99-ab72-48db-9415-c1df9d971dbf", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-08T03:25:45.388610Z", + "iopub.status.busy": "2025-12-08T03:25:45.387820Z", + "iopub.status.idle": "2025-12-08T03:25:45.453284Z", + "shell.execute_reply": "2025-12-08T03:25:45.452775Z", + "shell.execute_reply.started": "2025-12-08T03:25:45.388537Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20-24 {'正常': 120, '较高': 15}\n", + "25-29 {'正常': 161, '较高': 23}\n", + "30-34 {'正常': 46, '较高': 4}\n", + "35-39 {'正常': 86, '较高': 18}\n", + "40-44 {'正常': 81, '较高': 9}\n", + "45-49 {'正常': 219, '较高': 39}\n", + "50-54 {'正常': 158, '较高': 54}\n", + "55-80 {'正常': 5, '较高': 0}\n" + ] + } + ], + "source": [ + "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", + "level = ['正常', '较高']\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \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) and '腰臀比' in v.keys(): \n", + " dict3[age].setdefault(v['腰臀比']['score'],0)\n", + " if v['sex'] == '女':\n", + " dict3[age][v['腰臀比']['score']] = dict3[age][v['腰臀比']['score']]+1\n", + " \n", + "for k, v in dict3.items():\n", + " print(k,v)" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "d3f6ebf0-ad27-43ee-971c-28b88398b72a", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-08T03:30:44.333330Z", + "iopub.status.busy": "2025-12-08T03:30:44.332781Z", + "iopub.status.idle": "2025-12-08T03:30:44.406674Z", + "shell.execute_reply": "2025-12-08T03:30:44.406032Z", + "shell.execute_reply.started": "2025-12-08T03:30:44.333270Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20~24岁平均成绩:63.57分,人数:134人\n", + "25~29岁平均成绩:63.2分,人数:186人\n", + "30~34岁平均成绩:66.65分,人数:50人\n", + "35~39岁平均成绩:68.39分,人数:109人\n", + "40~44岁平均成绩:68.71分,人数:94人\n", + "45~49岁平均成绩:67.98分,人数:261人\n", + "50~54岁平均成绩:72.13分,人数:217人\n", + "55~80岁平均成绩:62.71分,人数:6人\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 = 1\n", + " score = 0\n", + " m = 0\n", + " f = 0\n", + " for k,v in dict1.items(): \n", + " if '身高体重指数' in v.keys() and v['age'] in range(di,gao+1) and v['sex'] == '女':\n", + " score = score+int(v['平均分'])\n", + " i+=1\n", + " \n", + " \n", + " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')" ] }, { @@ -4924,52 +4988,6 @@ "## 按部门统计" ] }, - { - "cell_type": "markdown", - "id": "cb1e13ae-3eba-4f6e-b70a-2bf87168ef1a", - "metadata": {}, - "source": [ - "### 计算部门完成情况" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5e7c1c49-75bf-4238-9bd7-b8511687f639", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import json\n", - "\n", - "\n", - "filename = 'data/data_天津231017.json'\n", - "with open(filename,'r') as fl:\n", - " dict1 = json.load(fl)\n", - "\n", - "filename = 'data/天津石化人员名单2023.json'\n", - "with open(filename,'r') as fl:\n", - " dict2 = json.load(fl)\n", - "dict3 = {}\n", - "\n", - "for k, v in dict2.items():\n", - " unit = v['unit']\n", - " dict3.setdefault(unit,{})\n", - " dict3[unit].setdefault('应测',0)\n", - " dict3[unit].setdefault('已测',0)\n", - " dict3[unit]['应测']+=1\n", - "for k, v in dict1.items():\n", - " unit = v['unit']\n", - " \n", - " dict3[unit]['已测']+=1\n", - " \n", - "print(dict3)\n", - "for k ,v in dict3.items():\n", - " print(k,v['应测'],v['已测'])\n", - " " - ] - }, { "cell_type": "markdown", "id": "e83941b9-b2b5-41db-b08a-a619f07c2487", @@ -4987,32 +5005,6 @@ "### 计算部门合格率" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "d023724c-46b7-4b4e-bbcc-8b4f171590c5", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "for k, v in dict1.items():\n", - " unit = v['unit']\n", - " dict3[unit].setdefault(v['level'],0)\n", - " dict3[unit][v['level']]+=1\n", - "print(dict3)\n", - "for k ,v in dict3.items():\n", - " print(k,v['已测'],v['不合格'])" - ] - }, - { - "cell_type": "markdown", - "id": "4b996a8a-70e7-4c95-8b14-0f8fa89df7a4", - "metadata": {}, - "source": [ - "### 计算部门成绩" - ] - }, { "cell_type": "code", "execution_count": null, @@ -5065,15 +5057,155 @@ }, "outputs": [], "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 k ,v in dict3.items():\n", - " print(k)\n", - " for k1,v1 in v.items():\n", - " if v1['count']>0:\n", - " print(k1,round(v1['score']/v1['count'],4))\n", - " print()" + "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 + int(v['平均分'])\n", + " n = n +1 \n", + " print(item,round(score/n,2),n)" ] }, + { + "cell_type": "markdown", + "id": "6a2e2477-1707-4001-a5ca-81290f6d4538", + "metadata": {}, + "source": [ + "### 按照部门计算平均成绩(女性)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c904fa39-4352-496f-8e5d-b22c47902905", + "metadata": {}, + "outputs": [], + "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'] and v['sex'] == '男':\n", + " score = score + int(v['平均分'])\n", + " n = n +1 \n", + " if n>0:\n", + " print(item,round(score/n,2),n)\n", + " else:\n", + " print(item,0,n)" + ] + }, + { + "cell_type": "markdown", + "id": "008f6e47-86bc-40d9-b445-054cc4c8e84e", + "metadata": {}, + "source": [ + "### 计算部门等级" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00178ceb-67d3-45da-ba0d-7f04da6825b6", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "level = ['一级','二级','三级','四级']\n", + "\n", + "\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "\n", + "dict3 = {}\n", + "for k, v in dict1.items():\n", + " unit = v['unit']\n", + " dict3.setdefault(unit,{})\n", + " for item in level:\n", + " dict3[unit].setdefault(item,0)\n", + "\n", + "for k, v in dict1.items():\n", + " unit = v['unit']\n", + " #dict3.setdefault(unit,{})\n", + " #for item in items:\n", + " #dict3[unit].setdefault(v['level'],0)\n", + " dict3[unit][v['等级']] +=1\n", + "for k, v in dict3.items():\n", + " print(k,v['一级'],v['二级'],v['三级'],v['四级'])" + ] + }, + { + "cell_type": "markdown", + "id": "69a3b24d-abd6-4d1a-9d54-0e66c6483aff", + "metadata": {}, + "source": [ + "### 计算部门成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc877211-7b65-420e-ab99-392b0b906d05", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "items = ['纵跳','选择反应时','肺活量','俯卧撑','闭眼单脚站立','坐位体前屈','1分钟仰卧起坐','握力','台阶指数','身高体重指数']\n", + "item1s = ['选择反应时','肺活量','俯卧撑','闭眼单脚站立','坐位体前屈','1分钟仰卧起坐','握力','台阶指数','身高体重指数']\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "\n", + "dict3 = {}\n", + "\n", + "for k, v in dict1.items():\n", + " unit = v['unit']\n", + " dict3.setdefault(unit,{})\n", + " for item in items:\n", + " dict3[unit].setdefault(item,{})\n", + " dict3[unit][item].setdefault('score',0)\n", + " dict3[unit][item].setdefault('count',0)\n", + " for k1,v1 in v.items():\n", + " if k1 in item1s:\n", + " dict3[unit][k1]['score']+=v1['score']\n", + " dict3[unit][k1]['count']+=1\n", + " if k1 =='纵跳' and v['age'] < 50:\n", + " dict3[unit][k1]['score']+=v1['score']\n", + " dict3[unit][k1]['count']+=1\n", + " \n", + " \n", + "\n", + "for k, v in dict3.items():\n", + " print(k)\n", + " for k1, v1 in v.items():\n", + " print(k1,v1['score'],v1['count'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2676033f-4b5e-473e-a3ee-8dd8d18033f5", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "id": "d3d9d517-61e5-4c4c-bddb-1f386a518d99", diff --git a/体测单位/宁夏能化.ipynb b/体测单位/宁夏能化.ipynb index 4dec9ac..fc47022 100644 --- a/体测单位/宁夏能化.ipynb +++ b/体测单位/宁夏能化.ipynb @@ -991,17 +991,16 @@ "# sheets = wb.sheetnames\n", "person = {}\n", "for n in range(2, sheet.max_row+1):\n", - " code = int(sheet.cell(n, 2).value)\n", + " code = str(int(sheet.cell(n, 2).value))\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 3).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", - " dict1['unit'] = sheet.cell(n, 6).value\n", - " \n", - " \n", + " dict1['unit'] = sheet.cell(n, 6).value \n", " dict1['age'] = int(sheet.cell(n, 5).value)\n", + " dict1['symptoms'] = sheet.cell(n, 8).value\n", " person[code] = dict1\n", - "filename = 'data/宁夏能化干预人员.json'\n", + "filename = 'data/宁夏能化高危风险干预人员.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print(len(person),'ok')" @@ -1017,21 +1016,40 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "f60e8194-7ef6-49d8-8538-9b79f35bb64d", - "metadata": {}, - "outputs": [], + "execution_count": 28, + "id": "7261e146-03f5-4943-8a3a-479d0e4a025d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-09T09:50:57.787016Z", + "iopub.status.busy": "2025-12-09T09:50:57.786321Z", + "iopub.status.idle": "2025-12-09T09:50:57.827675Z", + "shell.execute_reply": "2025-12-09T09:50:57.827125Z", + "shell.execute_reply.started": "2025-12-09T09:50:57.786958Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "204 ok\n" + ] + } + ], "source": [ - "import json\n", + "##### import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", - "\n", + "filename = 'data/宁夏能化高危风险干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl)\n", + " \n", "dict1 = {}\n", "list1 = []\n", - "filename = 'data/sql_20251009.csv'\n", + "filename = 'data/sql_20251209.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -1041,10 +1059,10 @@ "nn = 0\n", "for item in list1:\n", " dict2 = {}\n", - " name = item[1]\n", - " phone = str(item[2])[2:]\n", - " birth = str(item[4])\n", - " content = json.loads(item[0])\n", + " name = item[2]\n", + " phone = str(item[3])[2:]\n", + " birth = str(item[5])\n", + " content = json.loads(item[1])\n", " tcm = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", @@ -1055,26 +1073,177 @@ " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " \n", - " code = int(dict2['code'])\n", - " dict1.setdefault(code,{})\n", - " dict1[code]['name'] = dict2['name']\n", - " if dict2['gender'] == 'm':\n", - " dict1[code]['sex'] = '男'\n", - " else:\n", - " dict1[code]['sex'] = '女'\n", - " dict1[code]['birth'] = str(item[4])\n", - " dict1[code]['unit'] = dict2['unit']\n", - " dict1[code]['phone'] = phone\n", - " dict1[code]['waist'] = dict2['waist']\n", - " dict1[code]['hip'] = dict2['hip']\n", - " dict1[code]['tcm'] = tcm\n", - "filename = 'data/survey_宁夏能化干预人员.json'\n", + " code = str(int(dict2['code']))\n", + " if code in dict3.keys():\n", + " dict1.setdefault(code,{})\n", + " dict1[code]['name'] = dict2['name']\n", + " if dict2['gender'] == 'm':\n", + " dict1[code]['sex'] = '男'\n", + " else:\n", + " dict1[code]['sex'] = '女'\n", + " dict1[code]['birth'] = str(item[4])\n", + " dict1[code]['unit'] = dict2['unit']\n", + " dict1[code]['age'] = dict3[code]['age']\n", + " dict1[code]['phone'] = phone\n", + " dict1[code]['waist'] = dict2['waist']\n", + " dict1[code]['hip'] = dict2['hip']\n", + " dict1[code]['tcm'] = tcm\n", + "filename = 'data/survey_宁夏能化高危风险干预人员.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(len(dict1),'ok')" ] }, + { + "cell_type": "markdown", + "id": "c4486c37-d1a4-460f-9997-6405c51b805c", + "metadata": {}, + "source": [ + "## 常用参数及自定义函数" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "34cb26d7-cd7b-4ad5-bb7b-71cfcce16c24", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-09T09:51:13.116856Z", + "iopub.status.busy": "2025-12-09T09:51:13.116051Z", + "iopub.status.idle": "2025-12-09T09:51:13.133080Z", + "shell.execute_reply": "2025-12-09T09:51:13.132231Z", + "shell.execute_reply.started": "2025-12-09T09:51:13.116787Z" + } + }, + "outputs": [], + "source": [ + "import json\n", + "\n", + "questions = [[1],[-1, 2],[-1, 2],[-1, 8],[-1, 3],[1],[-1],[-1, 7],[2],[2],[2],[2, 3],[2],[2],[3],[3],[3],[3],[3],[4],[4],[4],[4],[4],[4],[4],[4],[5], [5],[5],[5],[5],[5],[5],[5],[6],[6],[6],[6],[6],[6],[7],[7],[7],[7],[7],[7],[8],[8],[8],[8],[8],[8],[9],[9],[9],[9],[9],[9],[9]]\n", + "\n", + "kinds = ['平和','气虚','阳虚','阴虚','痰湿','湿热','血瘀','气郁','特禀']\n", + "\n", + "def tcm_calc(arr):\n", + " qa = [8, 8, 7, 8, 8, 6, 7, 7, 7]\n", + " s = [0] * 9\n", + " for i in range(len(questions)):\n", + " m = arr[i] - 1\n", + " for v in questions[i]:\n", + " if v < 0:\n", + " s[-v - 1] += 4 - m\n", + " else:\n", + " s[v - 1] += m\n", + " return [int((v / qa[i]) * 25) for i, v in enumerate(s)]\n", + "\n", + "def tcm_kind(score):\n", + " kind = 0\n", + " near = False\n", + " max_kind = 0\n", + " max_score = 0\n", + " for i in range(1, 9):\n", + " if score[i] > max_score:\n", + " max_kind = i\n", + " max_score = score[i]\n", + " if score[0] >= 60 and max_score < 40:\n", + " if max_score >= 30:\n", + " near = True\n", + " kind = max_kind\n", + " else:\n", + " kind = max_kind\n", + " return {\n", + " \"kind\": kind,\n", + " \"near\": near\n", + " }\n", + "list2 = ['成就感','愉快心境','放松程度','压力应对','体力充沛','情感充沛度']\n", + "list3 = [[5,7],[7,4],[7,4],[7,4],[8,1],[6,1]] \n", + "list4 = ['颈椎','胸椎','腰椎','骶尾椎']\n", + "list5 = [[0,10,10],[10,17,7],[17,24,6],[24,26,2]]\n", + "qb = [\n", + " 1, 1, 1, 1, 1,\n", + " 4, 3, 2, 3, 2, 4, 3,\n", + " 4, 3, 2, 4, 4, 2, 4,\n", + " 3, 2, 2, 4, 3, 3, 2,\n", + " 5, 5, 5, 5, 5, 5, 5, 5,\n", + " 6, 6, 6, 6, 6, 6\n", + " ]" + ] + }, + { + "cell_type": "markdown", + "id": "f0bae0b0-2edb-4d3e-a2ae-154d23fea48b", + "metadata": {}, + "source": [ + "## 导出问卷监测情况表" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "d78c0f3f-cd1a-4c6c-9f5b-b1b874a95fe3", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-09T09:52:01.947920Z", + "iopub.status.busy": "2025-12-09T09:52:01.947633Z", + "iopub.status.idle": "2025-12-09T09:52:01.999096Z", + "shell.execute_reply": "2025-12-09T09:52:01.998620Z", + "shell.execute_reply.started": "2025-12-09T09:52:01.947897Z" + } + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "\n", + "\n", + "filename = 'data/survey_宁夏能化高危风险干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "data_list = []\n", + "for k, v in dict1.items():\n", + " list6 = []\n", + " list6.append(str(k).rjust(4,'0'))\n", + " list6.append(v['name'])\n", + " list6.append(v['sex'])\n", + " list6.append(v['unit'])\n", + " list6.append(v['age'])\n", + " list6.append(v['waist'])\n", + " list6.append(v['hip'])\n", + " \n", + " if 'tcm' in v.keys():\n", + " list1 = []\n", + " tcm =v['tcm']\n", + " for item in tcm:\n", + " list1.append(item)\n", + " score = tcm_calc(list1)\n", + "\n", + " result = tcm_kind(score)\n", + " kind = result['kind']\n", + " near = result['near']\n", + " #print(k,kinds[kind], near, score)\n", + " list6.append(kinds[kind])\n", + " if near:\n", + " list6.append('是')\n", + " else:\n", + " list6.append('')\n", + " for item in score:\n", + " list6.append(item)\n", + " else:\n", + " for i in range(0,11):\n", + " list6.append('')\n", + " i+=1\n", + " \n", + " data_list.append(list6)\n", + "filename = 'data/宁夏能化高危风险干预人员体质问卷明细表(20251209).xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "title = ['编号', '姓名', '性别', '单位/部门', '年龄', '腰围', '臀围', '中医体质', '是否倾向', '平和', '气虚', '阳虚', '阴虚', '痰湿', '湿热', '血瘀', '气郁', '特禀']\n", + "sheet.append(title)\n", + "for row in data_list:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename) " + ] + }, { "cell_type": "markdown", "id": "93a9b31e-49ea-45cd-bb0b-5c3db19bbb54", @@ -1121,6 +1290,14 @@ "wb.save(filename)" ] }, + { + "cell_type": "markdown", + "id": "4b0cd38c-d14c-48e7-83cb-8afc7665b060", + "metadata": {}, + "source": [ + "# 体重管理系统" + ] + }, { "cell_type": "markdown", "id": "98de56de-95fe-4f21-be25-896fb1bda175", @@ -1131,9 +1308,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "22be8f39-afbb-448a-8ae6-c825c7d38757", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-14T23:43:21.978932Z", + "iopub.status.busy": "2025-12-14T23:43:21.978409Z", + "iopub.status.idle": "2025-12-14T23:43:22.273147Z", + "shell.execute_reply": "2025-12-14T23:43:22.272647Z", + "shell.execute_reply.started": "2025-12-14T23:43:21.978883Z" + } + }, "outputs": [], "source": [ "import json\n", @@ -1142,7 +1327,7 @@ "\n", "title = []\n", "\n", - "filename = 'data/surveys_records_2025-12-07.json'\n", + "filename = 'data/surveys_records_2025-12-15.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", @@ -1167,7 +1352,7 @@ " \n", " list1.append(list2)\n", "all_title = ['id', 'date_created','name', 'gender', 'birth', 'code', 'unit', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n", - "filename = 'data/宁夏能化干预人员问卷(20251207).xlsx'\n", + "filename = 'data/宁夏能化干预人员问卷(20251215).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(all_title)\n", @@ -1203,10 +1388,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "91c53866-3725-4ceb-b0eb-23fb14e20561", - "metadata": {}, - "outputs": [], + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-14T23:43:35.251673Z", + "iopub.status.busy": "2025-12-14T23:43:35.251057Z", + "iopub.status.idle": "2025-12-14T23:43:35.339896Z", + "shell.execute_reply": "2025-12-14T23:43:35.339186Z", + "shell.execute_reply.started": "2025-12-14T23:43:35.251623Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('梁正武', '男', '电气仪表中心', '1984-05-01', '02018801', 1)\n", + "('张艳萍', '女', '公用工程运行部', '1978-09-01', '02020548', 1)\n", + "('叶云飞', '男', '公用工程运行部', '1985-11-01', '02019460', 1)\n", + "('李效龙', '男', 'BDO运行部', '1987-09-01', '0201968', 1)\n", + "('何富来', '男', '宁夏能化', '1983-03-01', '02019507', 1)\n", + "('马荣', '女', '公用工程运行部', '1984-03-01', '02020205', 1)\n", + "('刘永清', '男', '热电运行部', '1968-10-01', '02019958', 1)\n", + "('马学锋', '男', '热电运行部', '1974-12-01', '02020025', 1)\n", + "('段庆霖', '男', '热电运行部', '1990-02-01', '02020062', 1)\n", + "('周卫星', '男', '热电运行部', '1970-05-01', '02019986', 1)\n", + "('姚户昌', '男', '热电运行部', '1970-12-01', '02019968', 1)\n", + "('姜德溪', '男', '热电运行部', '1970-01-01', '2019970', 1)\n", + "('陈海宝', '男', '乙炔运行部', '1990-07-01', '02019346', 1)\n", + "('丁红忠', '男', '热电运行部', '1990-09-01', '02020160', 1)\n", + "('孙柏', '男', '环保建材运行部', '1982-03-01', '02020446', 1)\n", + "('黄博', '男', '物资采购中心', '1995-12-01', '03391681', 1)\n", + "('王正东', '男', '热电运行部', '1990-01-01', '03428864', 1)\n", + "17\n" + ] + } + ], "source": [ "import json\n", "import openpyxl\n", @@ -1219,7 +1437,7 @@ " password=\"songyi\"\n", ")\n", "cur = conn.cursor()\n", - "wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251207).xlsx',data_only=True)\n", + "wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251215).xlsx',data_only=True)\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "org_id = 1\n", @@ -1245,8 +1463,15 @@ " else:\n", " dict1['sex'] = '女'\n", " birth = str(sheet.cell(n, 5).value).split()[0]\n", - " if len(birth)==7:\n", - " dict1['birth'] = birth+'-01'\n", + " \n", + " if len(birth)<10:\n", + " nian = birth.split('-')[0]\n", + " yue = birth.split('-')[1].rjust(2,'0')\n", + " if len(birth.split('-')[0]) ==3:\n", + " ri = birth.split('-')[2].rjust(2,'0')\n", + " else:\n", + " ri = '01' \n", + " dict1['birth'] = nian+'-'+ yue + '-'+ ri\n", " else:\n", " dict1['birth'] = birth\n", " dict1['unit'] = sheet.cell(n, 7).value\n", @@ -1346,15 +1571,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "b7133988-213c-4b52-8d6b-17b56b8ea310", - "metadata": {}, - "outputs": [], + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-14T23:43:56.303850Z", + "iopub.status.busy": "2025-12-14T23:43:56.303555Z", + "iopub.status.idle": "2025-12-14T23:43:56.413335Z", + "shell.execute_reply": "2025-12-14T23:43:56.412897Z", + "shell.execute_reply.started": "2025-12-14T23:43:56.303825Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "108 ok\n" + ] + } + ], "source": [ "import json\n", "import openpyxl\n", "\n", - "wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251207).xlsx',data_only=True)\n", + "wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251215).xlsx',data_only=True)\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", @@ -1365,15 +1606,19 @@ " dict1['name'] = sheet.cell(n, 3).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", " birth = str(sheet.cell(n, 5).value).split()[0]\n", - " if len(birth)==7:\n", - " dict1['birth'] = birth+'-01'\n", - " else:\n", - " dict1['birth'] = birth\n", + " if len(birth)<10:\n", + " nian = birth.split('-')[0]\n", + " yue = birth.split('-')[1].rjust(2,'0')\n", + " if len(birth.split('-')[0]) ==3:\n", + " ri = birth.split('-')[2].rjust(2,'0')\n", + " else:\n", + " ri = '01' \n", + " dict1['birth'] = nian+'-'+ yue + '-'+ ri\n", " dict1['unit'] = sheet.cell(n, 7).value\n", " person[code] = dict1\n", "#print(person)\n", "\n", - "filename = 'data/surveys_records_2025-12-07.json'\n", + "filename = 'data/surveys_records_2025-12-10.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", @@ -1431,7 +1676,7 @@ " dict2['last_lose-Comment'] = data['last_lose-Comment']\n", " if code in person.keys():\n", " person[code][rq] = dict2\n", - "filename = 'data/宁夏能化干预人员问卷情况(20251207).json'\n", + "filename = 'data/宁夏能化干预人员问卷情况(20251215).json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", @@ -1449,9 +1694,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "55b20059-ae36-493e-b0c5-c7e35473efc7", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-14T23:44:12.601625Z", + "iopub.status.busy": "2025-12-14T23:44:12.600884Z", + "iopub.status.idle": "2025-12-14T23:44:12.741676Z", + "shell.execute_reply": "2025-12-14T23:44:12.741060Z", + "shell.execute_reply.started": "2025-12-14T23:44:12.601562Z" + } + }, "outputs": [], "source": [ "import json\n", @@ -1468,7 +1721,7 @@ "cur = conn.cursor()\n", "event_id = 1\n", "org_id = 1\n", - "filename = 'data/宁夏能化干预人员问卷情况(20251207).json'\n", + "filename = 'data/宁夏能化干预人员问卷情况(20251215).json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = ['name','sex','birth','unit']\n", diff --git a/体测单位/新疆油田采油工艺研究院.ipynb b/体测单位/新疆油田采油工艺研究院.ipynb index 67543d8..043fa99 100644 --- a/体测单位/新疆油田采油工艺研究院.ipynb +++ b/体测单位/新疆油田采油工艺研究院.ipynb @@ -90,26 +90,10 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "cac3736a-56da-403b-9e62-5caaf989a6d4", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T13:46:10.295376Z", - "iopub.status.busy": "2025-12-03T13:46:10.294744Z", - "iopub.status.idle": "2025-12-03T13:46:13.043043Z", - "shell.execute_reply": "2025-12-03T13:46:13.042530Z", - "shell.execute_reply.started": "2025-12-03T13:46:10.295324Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "190 ok\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import openpyxl\n", "import json\n", @@ -211,26 +195,10 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "925f7152-b365-4df8-8d98-73569aef68f8", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T14:07:05.330354Z", - "iopub.status.busy": "2025-12-03T14:07:05.329571Z", - "iopub.status.idle": "2025-12-03T14:07:05.346870Z", - "shell.execute_reply": "2025-12-03T14:07:05.345950Z", - "shell.execute_reply.started": "2025-12-03T14:07:05.330293Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "95\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import datetime\n", @@ -261,26 +229,10 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "0905ad6a-f7e4-43ed-ae29-c4850deb946b", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T13:55:35.038083Z", - "iopub.status.busy": "2025-12-03T13:55:35.036944Z", - "iopub.status.idle": "2025-12-03T13:55:35.052613Z", - "shell.execute_reply": "2025-12-03T13:55:35.051549Z", - "shell.execute_reply.started": "2025-12-03T13:55:35.038026Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok!\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import time\n", @@ -319,26 +271,10 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "id": "0e71f6b8-e17e-49f8-a577-7a2eb6f5e994", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T14:07:15.401160Z", - "iopub.status.busy": "2025-12-03T14:07:15.400541Z", - "iopub.status.idle": "2025-12-03T14:07:15.419441Z", - "shell.execute_reply": "2025-12-03T14:07:15.418453Z", - "shell.execute_reply.started": "2025-12-03T14:07:15.401101Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok!\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import time\n", @@ -492,6 +428,49 @@ "wb.save(filename)" ] }, + { + "cell_type": "markdown", + "id": "44d5a1bf-b208-4a50-bea3-1019e737b7ab", + "metadata": {}, + "source": [ + "## 统计体测日期" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "f4fc0e48-5c8a-4ad9-817e-dd8dd1bf7b55", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-15T00:10:27.023346Z", + "iopub.status.busy": "2025-12-15T00:10:27.023028Z", + "iopub.status.idle": "2025-12-15T00:10:27.028151Z", + "shell.execute_reply": "2025-12-15T00:10:27.027670Z", + "shell.execute_reply.started": "2025-12-15T00:10:27.023320Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2025-07-03 2025-08-18\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "filename = 'data/result_新疆油田采油工艺研究院1-1.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "for k,v in dict1.items():\n", + " if 'rq' in v.keys():\n", + " list1.append(v['rq'])\n", + "print(min(list1),max(list1))" + ] + }, { "cell_type": "markdown", "id": "699c6a40-a6ae-4300-9646-708cb85aa5e8", @@ -629,7 +608,7 @@ " phone[v['phone']] = k\n", "\n", "list1 = []\n", - "filename = 'data/survey_records_20250813.csv'\n", + "filename = 'data/survey_records_20251214.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -639,8 +618,7 @@ "\n", "\n", "nn = 0\n", - "for item in list1:\n", - " \n", + "for item in list1: \n", " if int(item[3]) in phone.keys():\n", " code = phone[int(item[3])]\n", " tcm = []\n", @@ -686,6 +664,93 @@ "print(nn)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9a92b29-7112-459b-8c5a-4edd7e72457d", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "dict1 = {}\n", + "\n", + "filename = 'data/result_新疆油田采油工艺研究院1.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "filename = 'data/新疆油田采油工艺研究院-1.json'\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl)\n", + "\n", + "phone = {}\n", + "for k,v in dict3.items():\n", + " if 'phone' in v.keys():\n", + " phone[v['phone']] = k\n", + "print(phone)\n", + "list1 = []\n", + "filename = 'data/survey_records_20250813.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", + " list1.append(line)\n", + "\n", + "\n", + "\n", + "nn = 0\n", + "for item in list1:\n", + " content = json.loads(item[4])\n", + " print(content)\n", + " if 'phone' in content.keys() and int(content['phone']) in phone.keys():\n", + " code = phone[int(content['phone'])] \n", + " print(code)\n", + " tcm = []\n", + " spine = []\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for i in range(0,26):\n", + " spine.append(0)\n", + " \n", + " \n", + " if code not in dict1.keys():\n", + " dict1[code] = dict3[code]\n", + " rq = date.fromisoformat(item[5].replace('/','-').split(' ')[0])\n", + " dict1[code]['rq'] = item[5].replace('/','-').split(' ')[0]\n", + " for k, v in content.items():\n", + " \n", + " if 'tcm' in k:\n", + " i = int(k[3:])\n", + " tcm[i-1] = int(v)\n", + " if 'spine' in k:\n", + " i = int(k[5:])\n", + " spine[i-1] = int(v)\n", + " \n", + " if 'tcm' in item[4]:\n", + " \n", + " dict1[code]['tcm'] = tcm\n", + " if 'spine' in item[4]:\n", + " for ii in range(25,23,-1):\n", + " spine[ii] = spine[ii-1]\n", + " spine[22] = 0 \n", + " dict1[code]['spine'] = spine\n", + " birth = date.fromisoformat(dict3[code]['birth'].replace('/','-'))\n", + " rq = date.fromisoformat(item[5].replace('/','-').split(' ')[0])\n", + " days = (rq-birth).days \n", + " dict1[code]['age'] = int(days/365)\n", + " dict1[code]['month'] = int(days/365*12)\n", + " #print(phone[item[2]])\n", + " nn+=1\n", + "filename = 'data/result_新疆油田采油工艺研究院1-1.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n", + "print(nn)" + ] + }, { "cell_type": "markdown", "id": "6eea20f8-b457-455e-8409-5c8cdaa1efb6", @@ -696,26 +761,10 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "id": "83872322-129c-410d-a9a3-ef6f4fe8dcde", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T14:07:28.969613Z", - "iopub.status.busy": "2025-12-03T14:07:28.969043Z", - "iopub.status.idle": "2025-12-03T14:07:28.992695Z", - "shell.execute_reply": "2025-12-03T14:07:28.991843Z", - "shell.execute_reply.started": "2025-12-03T14:07:28.969559Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "95\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import csv\n", @@ -855,26 +904,10 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "694ad38e-755e-4885-94a9-c157ddc96564", - "metadata": { - "execution": { - "iopub.execute_input": "2025-11-24T11:08:24.326077Z", - "iopub.status.busy": "2025-11-24T11:08:24.325551Z", - "iopub.status.idle": "2025-11-24T11:08:55.094267Z", - "shell.execute_reply": "2025-11-24T11:08:55.093154Z", - "shell.execute_reply.started": "2025-11-24T11:08:24.326028Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "53\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import requests\n", "import json\n", @@ -939,26 +972,10 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "id": "28790176-7666-4b2d-83a5-9207cb8ad757", - "metadata": { - "execution": { - "iopub.execute_input": "2025-12-03T14:08:59.269168Z", - "iopub.status.busy": "2025-12-03T14:08:59.268598Z", - "iopub.status.idle": "2025-12-03T14:09:06.148725Z", - "shell.execute_reply": "2025-12-03T14:09:06.148173Z", - "shell.execute_reply.started": "2025-12-03T14:08:59.269114Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "14\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import requests\n", "import json\n", @@ -1098,26 +1115,10 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "73d28b6a-91be-47bb-bf76-1b8c26faafb5", - "metadata": { - "execution": { - "iopub.execute_input": "2025-11-11T04:31:28.041103Z", - "iopub.status.busy": "2025-11-11T04:31:28.040413Z", - "iopub.status.idle": "2025-11-11T04:31:28.055394Z", - "shell.execute_reply": "2025-11-11T04:31:28.054740Z", - "shell.execute_reply.started": "2025-11-11T04:31:28.041040Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "27\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import csv\n", @@ -1186,26 +1187,10 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "id": "cdbeb2f8-2784-4688-806a-6506799941cb", - "metadata": { - "execution": { - "iopub.execute_input": "2025-11-11T04:31:58.919201Z", - "iopub.status.busy": "2025-11-11T04:31:58.918605Z", - "iopub.status.idle": "2025-11-11T04:32:06.150780Z", - "shell.execute_reply": "2025-11-11T04:32:06.149803Z", - "shell.execute_reply.started": "2025-11-11T04:31:58.919144Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "27\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import requests\n", "import json\n", @@ -1268,10 +1253,157 @@ "print(i)" ] }, + { + "cell_type": "markdown", + "id": "03a98563-9dc9-4faf-97c0-d504f00f2dc3", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-14T08:18:47.657261Z", + "iopub.status.busy": "2025-12-14T08:18:47.656588Z", + "iopub.status.idle": "2025-12-14T08:18:47.662530Z", + "shell.execute_reply": "2025-12-14T08:18:47.661420Z", + "shell.execute_reply.started": "2025-12-14T08:18:47.657196Z" + } + }, + "source": [ + "## 生成体质检测报告" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "8564de3a-1511-4a79-9ec3-32aea03595c7", + "id": "7791e71a-6eb0-4943-9aa4-9a2a0ebe6c43", + "metadata": {}, + "outputs": [], + "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_新疆油田采油工艺研究院-1.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'] = 60\n", + " mydata['fits'] = {}\n", + " #survey_list = ['tcm','psy57','spine']\n", + " survey_list = ['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", + " \n", + " if 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": "code", + "execution_count": null, + "id": "a24a10c2-bc1c-4675-b49d-b6e208190c61", + "metadata": {}, + "outputs": [], + "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_新疆油田采油工艺研究院-1.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(8,\"0\")\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": "code", + "execution_count": null, + "id": "e50769a2-cf7b-4019-a5b9-f9d83e0bc374", "metadata": {}, "outputs": [], "source": [] diff --git a/文件管理.ipynb b/文件管理.ipynb index d28f5d6..ae0f141 100644 --- a/文件管理.ipynb +++ b/文件管理.ipynb @@ -1456,7 +1456,7 @@ ], "source": [ "import pdfplumber\n", - "name = 'file/01730823-邵希强.pdf'\n", + "name = 'file/03499391-宋文路.pdf'\n", "pdf = pdfplumber.open(name)\n", "text = pdf.pages[1].extract_text()#######页码从0开始计数\n", "#print(text)\n", @@ -1474,8 +1474,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "ac034bf9-cba9-4a72-87ba-d77721cc7097", + "metadata": { + "execution": { + "iopub.execute_input": "2025-12-08T01:54:24.900658Z", + "iopub.status.busy": "2025-12-08T01:54:24.900121Z", + "iopub.status.idle": "2025-12-08T01:54:24.960757Z", + "shell.execute_reply": "2025-12-08T01:54:24.960174Z", + "shell.execute_reply.started": "2025-12-08T01:54:24.900608Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['北体乾元健康管理中心', '姓名 宋文路', '中石化(天津)石油化工 编号 03499391', '有限公司 性别 男', '年龄 26', '国民体质检测结果与健康处方', '握力', '纵跳 身高体重指数', '选择反应时', '测试标准 国民体质测定标准', '身高体重指数 33.68 20分', '握力 38.6 千克 55分', '纵跳 22.8 厘米 30分', '选择反应时 0.466 秒 90分', '腰臀比 0.95 正常', '请注意:以上测试项目及格线为60分。列表中红色项目需重点关注,建议在专家指导下进行科学锻炼,', '减少潜在的运动风险。', '感谢您完成测试,因为您未完成肺活量、台阶指数、俯卧撑、1分钟仰卧起坐、坐位体前屈、闭眼单脚', '站立,无法以《国民体质测定标准》综合评级,改为以平均分作为综合评级参考。您的平均得分为53,等级', '为四级(不合格),仅供参考。', '北体乾元体质监测报告']\n", + "感谢您完成测试,因为您未完成肺活量、台阶指数、俯卧撑、1分钟仰卧起坐、坐位体前屈、闭眼单脚站立,无法以《国民体质测定标准》综合评级,改为以平均分作为综合评级参考。您的平均得分为53,等级为四级(不合格),仅供参考。北体乾元体质监测报告\n" + ] + } + ], + "source": [ + "import pdfplumber\n", + "name = 'file/03499391-宋文路.pdf'\n", + "pdf = pdfplumber.open(name)\n", + "text = pdf.pages[1].extract_text()#######页码从0开始计数\n", + "#print(text)\n", + "list1 = text.split('\\n')\n", + "print(list1)\n", + "for item in list1:\n", + " if '感谢您完成测试' in item:\n", + " i = list1.index(item)\n", + " ss = ''.join(list1[i:])\n", + " print(ss)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41177ae9-d7ae-45c2-90b5-94578699215e", "metadata": {}, "outputs": [], "source": []