diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index 31f4472..79afeb0 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -2376,15 +2376,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "6f9768ce-2ef5-4253-9fc6-49dbdcf00a19", "metadata": { "execution": { - "iopub.execute_input": "2025-09-16T02:05:51.668240Z", - "iopub.status.busy": "2025-09-16T02:05:51.667590Z", - "iopub.status.idle": "2025-09-16T02:05:51.678339Z", - "shell.execute_reply": "2025-09-16T02:05:51.677348Z", - "shell.execute_reply.started": "2025-09-16T02:05:51.668169Z" + "iopub.execute_input": "2025-09-22T12:52:59.350814Z", + "iopub.status.busy": "2025-09-22T12:52:59.350137Z", + "iopub.status.idle": "2025-09-22T12:52:59.367870Z", + "shell.execute_reply": "2025-09-22T12:52:59.366720Z", + "shell.execute_reply.started": "2025-09-22T12:52:59.350750Z" } }, "outputs": [], @@ -2752,15 +2752,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "id": "9ecd3ad8-c8af-4f3e-90e5-1618fea905a4", "metadata": { "execution": { - "iopub.execute_input": "2025-09-16T02:06:01.244917Z", - "iopub.status.busy": "2025-09-16T02:06:01.244267Z", - "iopub.status.idle": "2025-09-16T02:06:01.629798Z", - "shell.execute_reply": "2025-09-16T02:06:01.629334Z", - "shell.execute_reply.started": "2025-09-16T02:06:01.244858Z" + "iopub.execute_input": "2025-09-22T12:54:30.458387Z", + "iopub.status.busy": "2025-09-22T12:54:30.457853Z", + "iopub.status.idle": "2025-09-22T12:54:30.653511Z", + "shell.execute_reply": "2025-09-22T12:54:30.653048Z", + "shell.execute_reply.started": "2025-09-22T12:54:30.458336Z" } }, "outputs": [], @@ -2768,7 +2768,7 @@ "import openpyxl\n", "\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", - "filename = 'data/result_北海炼化2023.json'\n", + "filename = 'data/result_通用技术中国医药-1.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "data_list = []\n", @@ -2850,7 +2850,7 @@ " list6.append('')\n", " i+=1\n", " data_list.append(list6)\n", - "filename = 'data/北海炼化测试情况表2023.xlsx'\n", + "filename = 'data/通用技术中国医药.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "#sheet.append(title)\n", diff --git a/体测单位/南京化工.ipynb b/体测单位/南京化工.ipynb index 3874abd..693e1ec 100644 --- a/体测单位/南京化工.ipynb +++ b/体测单位/南京化工.ipynb @@ -10,33 +10,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "bbba6efc-73cd-4db6-bae7-014724fee731", "metadata": { + "execution": { + "iopub.execute_input": "2025-10-21T02:05:09.966940Z", + "iopub.status.busy": "2025-10-21T02:05:09.966195Z", + "iopub.status.idle": "2025-10-21T02:05:10.249499Z", + "shell.execute_reply": "2025-10-21T02:05:10.248277Z", + "shell.execute_reply.started": "2025-10-21T02:05:09.966870Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "270 ok\n" + ] + } + ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", - "wb = openpyxl.load_workbook('data/南化人员信息表.xlsx',data_only=True)\n", + "wb = openpyxl.load_workbook('data/胜利采油厂人员名单.xlsx',data_only=True)\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, 4).value)\n", + " code = int(sheet.cell(n, 2).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", - " dict1['name'] = sheet.cell(n, 3).value\n", + " dict1['name'] = sheet.cell(n, 4).value\n", " dict1['sex'] = sheet.cell(n, 5).value\n", - " dict1['unit'] = sheet.cell(n, 2).value \n", + " dict1['unit'] = sheet.cell(n, 3).value \n", " dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0]\n", - " dict1['phone'] = sheet.cell(n, 12).value \n", + " #dict1['phone'] = sheet.cell(n, 12).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')" @@ -52,16 +67,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f", "metadata": { + "execution": { + "iopub.execute_input": "2025-10-21T02:05:49.362922Z", + "iopub.status.busy": "2025-10-21T02:05:49.362143Z", + "iopub.status.idle": "2025-10-21T02:05:49.376741Z", + "shell.execute_reply": "2025-10-21T02:05:49.375761Z", + "shell.execute_reply.started": "2025-10-21T02:05:49.362862Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], "source": [ "import json\n", "\n", - "filename = 'data/南京化工人员.json'\n", + "filename = 'data/胜利采油厂人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", @@ -75,7 +105,7 @@ "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", "\n", "# 将 json 数据写入文件\n", - "with open(\"data/data_南京化工人员.json\", \"w\",encoding = 'utf-8') as file:\n", + "with open(\"data/data_胜利采油厂人员.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] diff --git a/体测单位/宁夏能化.ipynb b/体测单位/宁夏能化.ipynb index 2351867..b7f007d 100644 --- a/体测单位/宁夏能化.ipynb +++ b/体测单位/宁夏能化.ipynb @@ -1,5 +1,13 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "a3a2e21f-e62e-465b-818d-8acea289434f", + "metadata": {}, + "source": [ + "# 体质检测" + ] + }, { "cell_type": "markdown", "id": "04524c85-988e-4dbf-86eb-939a9db7aa28", @@ -10,27 +18,12 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "bbba6efc-73cd-4db6-bae7-014724fee731", "metadata": { - "execution": { - "iopub.execute_input": "2025-08-14T12:48:54.906761Z", - "iopub.status.busy": "2025-08-14T12:48:54.906261Z", - "iopub.status.idle": "2025-08-14T12:48:55.181497Z", - "shell.execute_reply": "2025-08-14T12:48:55.180926Z", - "shell.execute_reply.started": "2025-08-14T12:48:54.906723Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1698 ok\n" - ] - } - ], + "outputs": [], "source": [ "import openpyxl\n", "import json\n", @@ -342,17 +335,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "75b98b19-ab32-414a-b3f2-6efd58e1f9a9", - "metadata": { - "execution": { - "iopub.execute_input": "2025-08-28T09:16:02.802494Z", - "iopub.status.busy": "2025-08-28T09:16:02.801898Z", - "iopub.status.idle": "2025-08-28T09:16:02.994884Z", - "shell.execute_reply": "2025-08-28T09:16:02.994340Z", - "shell.execute_reply.started": "2025-08-28T09:16:02.802438Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import json\n", @@ -557,26 +542,10 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "d31020be-c9c0-404f-8e0b-f8f507385f48", - "metadata": { - "execution": { - "iopub.execute_input": "2025-08-14T12:28:32.225197Z", - "iopub.status.busy": "2025-08-14T12:28:32.224475Z", - "iopub.status.idle": "2025-08-14T12:28:32.933373Z", - "shell.execute_reply": "2025-08-14T12:28:32.932821Z", - "shell.execute_reply.started": "2025-08-14T12:28:32.225127Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "import json\n", "import openpyxl\n", @@ -877,17 +846,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "360831b7-e204-4801-9f72-879e338ed962", - "metadata": { - "execution": { - "iopub.execute_input": "2025-08-13T11:53:04.589116Z", - "iopub.status.busy": "2025-08-13T11:53:04.588495Z", - "iopub.status.idle": "2025-08-13T11:53:04.762457Z", - "shell.execute_reply": "2025-08-13T11:53:04.761877Z", - "shell.execute_reply.started": "2025-08-13T11:53:04.589057Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import json\n", @@ -963,17 +924,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "e3117237-b921-41fe-9b65-4918c5b2a165", - "metadata": { - "execution": { - "iopub.execute_input": "2025-08-13T08:52:05.672800Z", - "iopub.status.busy": "2025-08-13T08:52:05.672283Z", - "iopub.status.idle": "2025-08-13T08:52:05.820901Z", - "shell.execute_reply": "2025-08-13T08:52:05.820357Z", - "shell.execute_reply.started": "2025-08-13T08:52:05.672751Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import json\n", @@ -1004,10 +957,260 @@ " " ] }, + { + "cell_type": "markdown", + "id": "fabb8138-ad15-43a0-abf5-c5ff73318333", + "metadata": {}, + "source": [ + "# 高危风险干预" + ] + }, + { + "cell_type": "markdown", + "id": "5b5fcb90-e60e-4edd-929a-702fe93bd0e7", + "metadata": {}, + "source": [ + "## 导入干预人员名单" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "396e64b8-c306-4613-9848-f0f183052b78", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-10T02:18:51.157197Z", + "iopub.status.busy": "2025-10-10T02:18:51.156880Z", + "iopub.status.idle": "2025-10-10T02:18:51.211412Z", + "shell.execute_reply": "2025-10-10T02:18:51.210755Z", + "shell.execute_reply.started": "2025-10-10T02:18:51.157161Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "210 ok\n" + ] + } + ], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "wb = openpyxl.load_workbook('data/宁夏能化高危风险人群最终干预人员名单.xlsx',data_only=True)\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "person = {}\n", + "for n in range(2, sheet.max_row+1):\n", + " code = 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['age'] = int(sheet.cell(n, 5).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),'ok')" + ] + }, + { + "cell_type": "markdown", + "id": "952544fd-0fc6-4365-a43b-a12cab537bb2", + "metadata": {}, + "source": [ + "## 获取问卷人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "f60e8194-7ef6-49d8-8538-9b79f35bb64d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-10T02:09:50.365387Z", + "iopub.status.busy": "2025-10-10T02:09:50.364816Z", + "iopub.status.idle": "2025-10-10T02:09:50.391653Z", + "shell.execute_reply": "2025-10-10T02:09:50.391205Z", + "shell.execute_reply.started": "2025-10-10T02:09:50.365335Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "145 ok\n" + ] + } + ], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/sql_20251009.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", + "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", + " tcm = []\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for k, v in content.items(): \n", + " if 'tcm' not in k:\n", + " dict2[k] = v\n", + " else:\n", + " 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", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n", + "print(len(dict1),'ok')" + ] + }, + { + "cell_type": "markdown", + "id": "93a9b31e-49ea-45cd-bb0b-5c3db19bbb54", + "metadata": {}, + "source": [ + "## 导出问卷人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "f0853629-e971-492b-88c8-4e9521b4b017", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-10T02:16:14.316496Z", + "iopub.status.busy": "2025-10-10T02:16:14.315869Z", + "iopub.status.idle": "2025-10-10T02:16:14.344471Z", + "shell.execute_reply": "2025-10-10T02:16:14.343924Z", + "shell.execute_reply.started": "2025-10-10T02:16:14.316435Z" + } + }, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "\n", + "title = ['员工编号','姓名','性别','部门']\n", + "\n", + "filename = 'data/survey_宁夏能化干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "filename = 'data/宁夏能化干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + " \n", + "list1 = []\n", + "for k, v in dict2.items():\n", + " \n", + " if str(k) not in dict1.keys():\n", + " list2 = []\n", + " list2 = [k,v['name'],v['sex'],v['unit']] \n", + " list1.append(list2)\n", + "filename = 'data/宁夏能化干预人员未参加问卷人员(20251010).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)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "22be8f39-afbb-448a-8ae6-c825c7d38757", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-10T02:18:10.620552Z", + "iopub.status.busy": "2025-10-10T02:18:10.619865Z", + "iopub.status.idle": "2025-10-10T02:18:10.652211Z", + "shell.execute_reply": "2025-10-10T02:18:10.651710Z", + "shell.execute_reply.started": "2025-10-10T02:18:10.620490Z" + } + }, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "\n", + "title = ['员工编号','姓名','性别','部门','手机号码']\n", + "\n", + "filename = 'data/survey_宁夏能化干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "filename = 'data/宁夏能化干预人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + " \n", + "list1 = []\n", + "for k, v in dict2.items():\n", + " \n", + " if str(k) in dict1.keys():\n", + " list2 = []\n", + " list2 = [k,v['name'],v['sex'],v['unit'],dict1[k]['phone']] \n", + " list1.append(list2)\n", + "filename = 'data/宁夏能化干预人员参加问卷人员(20251010).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)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "6133f0d5-75aa-41c0-a624-b354d89b5ba3", + "id": "f32288ee-167c-4e2a-9679-5d927db34950", "metadata": {}, "outputs": [], "source": [] diff --git a/体测单位/胜利采油厂.ipynb b/体测单位/胜利采油厂.ipynb new file mode 100644 index 0000000..3874abd --- /dev/null +++ b/体测单位/胜利采油厂.ipynb @@ -0,0 +1,1202 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "04524c85-988e-4dbf-86eb-939a9db7aa28", + "metadata": {}, + "source": [ + "## 体测人员导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbba6efc-73cd-4db6-bae7-014724fee731", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "\n", + "wb = openpyxl.load_workbook('data/南化人员信息表.xlsx',data_only=True)\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, 4).value)\n", + " person.setdefault(code, {})\n", + " dict1 = {}\n", + " dict1['name'] = sheet.cell(n, 3).value\n", + " dict1['sex'] = sheet.cell(n, 5).value\n", + " dict1['unit'] = sheet.cell(n, 2).value \n", + " dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0]\n", + " dict1['phone'] = sheet.cell(n, 12).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),'ok')" + ] + }, + { + "cell_type": "markdown", + "id": "048a95aa-1691-45f6-b933-6eaf95ae1d30", + "metadata": {}, + "source": [ + "## 生成读卡系统文件" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import json\n", + "\n", + "filename = 'data/南京化工人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " dict2 = {}\n", + " #if dict1['sex'] =='男':\n", + " # sex = 1\n", + " \n", + " dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}\n", + " list1.append(dict2)\n", + "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", + "\n", + "# 将 json 数据写入文件\n", + "with open(\"data/data_南京化工人员.json\", \"w\",encoding = 'utf-8') as file:\n", + " file.write(json_data) \n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f", + "metadata": {}, + "source": [ + "## 获取人员测试成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "970e171e-1360-448f-a28c-520ccb8f314a", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import json\n", + "import datetime\n", + "import csv\n", + "from datetime import date\n", + "import my_module as My\n", + "\n", + "filename = 'data/南京化工人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "filename = 'data/marks_20250703.csv'\n", + "re_ta = My.get_result(filename,dict1)\n", + "\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": "6d381859-6d21-45d2-8313-55ebbabf8bd4", + "metadata": {}, + "source": [ + "## 生成测试得分" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0905ad6a-f7e4-43ed-ae29-c4850deb946b", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import time\n", + "import my_module as My\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_南京化工.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 'bmi' in v.keys():\n", + " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", + " bmi_data = v['bmi']['成绩']\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'] = My.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", + " #print(k,v['name'])\n", + " dict2[k][item_en]['score'] = My.cal_score(data1)\n", + " #print(k,v[item_en]['成绩'],cal_score(data1))\n", + "\n", + "filename = f'data/result_南京化工.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print('ok!') " + ] + }, + { + "cell_type": "markdown", + "id": "d034a61d-1fbd-417b-99bd-277e43ebb678", + "metadata": {}, + "source": [ + "## 导出测试人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", + "title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "\n", + "filename = 'data/result_南京化工.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "filename = 'data/南京化工人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + " \n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " list2 = []\n", + " list2.append(str(k).rjust(5,'0'))\n", + " list2.append(v['name']) \n", + " list2.append(dict2[k]['sex'])\n", + " list2.append(dict2[k]['unit'])\n", + " if 'bmi' in v.keys():\n", + " height = v['bmi']['成绩'].split(',')[0]\n", + " weight = v['bmi']['成绩'].split(',')[1]\n", + " list2.append(height)\n", + " list2.append(weight)\n", + " else:\n", + " list2.append('')\n", + " list2.append('')\n", + " for item in items:\n", + " if item in v.keys():\n", + " list2.append(v[item]['成绩']) \n", + " elif item =='name':\n", + " list2.append(v[item])\n", + " else:\n", + " list2.append('')\n", + " \n", + " list1.append(list2)\n", + "filename = 'data/南京化工测试情况明细表(截至20250630).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)" + ] + }, + { + "cell_type": "markdown", + "id": "699c6a40-a6ae-4300-9646-708cb85aa5e8", + "metadata": {}, + "source": [ + "## 统计问卷人员情况" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "def3f47a-24ef-4815-b63b-2a16b79b4c15", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "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", + " dict1 = json.load(fl)\n", + "\n", + "phone1 = set()\n", + "phone2 = set()\n", + "for k,v in dict1.items():\n", + " phone1.add(v['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", + "i =1\n", + "list2 = []\n", + "for item in list1:\n", + " content = json.loads(item[4])\n", + " code = int(content['phone'])\n", + " for k, v in dict1.items():\n", + " list3 = []\n", + " if v['phone'] == code: \n", + " list3.append(k)\n", + " list3.append(v['name'])\n", + " list3.append(v['sex'])\n", + " list3.append(v['unit'])\n", + " list3.append(code)\n", + " list2.append(list3)\n", + "filename = 'data/南化问卷情况表(第二批).xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "#sheet.append(title)\n", + "for row in list2:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b7c0528-17b6-4469-b15f-3c4b794e286e", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "\n", + "\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", + "i =1\n", + "list2 = []\n", + "for item in list1:\n", + " list3 = []\n", + " content = json.loads(item[4])\n", + " phone = int(content['phone'])\n", + " name = content['name']\n", + " sex = content['gender']\n", + " list3.append(name)\n", + " list3.append(sex)\n", + " list3.append(phone)\n", + " list2.append(list3)\n", + "filename = 'data/南化问卷情况表(第二批).xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "#sheet.append(title)\n", + "for row in list2:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename) " + ] + }, + { + "cell_type": "markdown", + "id": "797717d5-47b9-4d47-be6c-8d54bede67d4", + "metadata": {}, + "source": [ + "## 导入问卷信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d9dd574-9fbf-4d0a-96fd-9b55d98021d2", + "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_南京化工.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "filename = 'data/南京化工人员.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", + "\n", + "list1 = []\n", + "filename = 'data/survey_records_20250812.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", + " if int(item[3]) in phone.keys(): \n", + " tcm = []\n", + " code = phone[int(item[3])]\n", + " \n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " \n", + " \n", + " content = json.loads(item[4])\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'] = str(date.fromisoformat(item[5].replace('/','-').split(' ')[0]))\n", + " #dict1[code]['rq'] = item[5].replace('/','-').split(' ')[0]\n", + " else:\n", + " rq=date.fromisoformat('2025-07-01')\n", + " dict1[code]['rq'] = '2025-07-01'\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", + " \n", + " if 'tcm' in item[4]: \n", + " dict1[code]['tcm'] = tcm\n", + " \n", + " birth = date.fromisoformat(dict3[code]['birth'].replace('/','-'))\n", + " \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_南京化工-2.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n" + ] + }, + { + "cell_type": "markdown", + "id": "4930b4cb-2114-4432-a8ae-e6d2cde69b5c", + "metadata": {}, + "source": [ + "## 导入问卷信息(新)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "9b801085-ca98-4958-8dcc-bcd9985fcd4b", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-01T07:20:37.177771Z", + "iopub.status.busy": "2025-09-01T07:20:37.177055Z", + "iopub.status.idle": "2025-09-01T07:20:37.198841Z", + "shell.execute_reply": "2025-09-01T07:20:37.198253Z", + "shell.execute_reply.started": "2025-09-01T07:20:37.177707Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "83\n" + ] + } + ], + "source": [ + "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", + "\n", + "list1 = []\n", + "filename = 'data/survey_records_20250901.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", + "dict1 = {}\n", + "nn = 0\n", + "for item in list1: \n", + " tcm = [] \n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " \n", + " content = json.loads(item[4]) \n", + " phone = content['phone']\n", + " name = content['name']\n", + " for k,v in dict3.items():\n", + " if name == v['name']:\n", + " code = k\n", + " unit = v['unit']\n", + " sex = v['sex']\n", + " dict1.setdefault(code,{})\n", + " \n", + " #rq = date.fromisoformat(item[5].replace('/','-').split(' ')[0])\n", + " #dict1[phone]['rq'] = str(date.fromisoformat(item[5].replace('/','-').split(' ')[0]))\n", + " \n", + " for k, v in content.items(): \n", + " if 'tcm' in k:\n", + " i = int(k[3:])\n", + " tcm[i-1] = int(v) \n", + " \n", + " if 'tcm' in item[4]: \n", + " dict1[code]['tcm'] = tcm\n", + " \n", + " dict1[code]['name'] = content['name']\n", + " dict1[code]['unit'] = unit\n", + " dict1[code]['sex'] = sex\n", + " dict1[code]['weight'] = content['weight']\n", + " dict1[code]['tun'] = content['hip']\n", + " dict1[code]['yao'] = content['waist']\n", + " #print(phone[item[2]])\n", + " nn+=1\n", + "filename = 'data/result_南京化工-2.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n", + "print(len(dict1))" + ] + }, + { + "cell_type": "markdown", + "id": "89689b86-3fae-402e-a456-a646f0c7201f", + "metadata": {}, + "source": [ + "## 导入腰臀数据" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a0678c6-0c64-4314-bb03-24b10a3d695a", + "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", + "wb = openpyxl.load_workbook('data/南化腰臀数据.xlsx',data_only=True)\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "person = {}\n", + "\n", + "for n in range(2, sheet.max_row+1):\n", + " code = str(sheet.cell(n, 1).value)\n", + " if code in dict1.keys():\n", + " yao = str(sheet.cell(n, 2).value)\n", + " tun = str(sheet.cell(n, 3).value)\n", + " dict1[code]['腰臀比'] = yao+','+tun\n", + "filename = 'data/result_南京化工-1.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n" + ] + }, + { + "cell_type": "markdown", + "id": "19c6e8b6-2663-447d-884b-a22af3944c71", + "metadata": {}, + "source": [ + "## 计算中医体质并导出" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e233e6c3-9c3f-42c7-8057-012bbcfe8b26", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "questions = [\n", + " [1],\n", + " [-1, 2],\n", + " [-1, 2],\n", + " [-1, 8],\n", + " [-1, 3],\n", + " [1],\n", + " [-1],\n", + " [-1, 7],\n", + " [2],\n", + " [2],\n", + " [2],\n", + " [2, 3],\n", + " [2],\n", + " [2],\n", + " [3],\n", + " [3],\n", + " [3],\n", + " [3],\n", + " [3],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [4],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [5],\n", + " [6],\n", + " [6],\n", + " [6],\n", + " [6],\n", + " [6],\n", + " [6],\n", + " [7],\n", + " [7],\n", + " [7],\n", + " [7],\n", + " [7],\n", + " [7],\n", + " [8],\n", + " [8],\n", + " [8],\n", + " [8],\n", + " [8],\n", + " [8],\n", + " [9],\n", + " [9],\n", + " [9],\n", + " [9],\n", + " [9],\n", + " [9],\n", + " [9]\n", + "]\n", + "\n", + "kinds = [\n", + " '平和',\n", + " '气虚',\n", + " '阳虚',\n", + " '阴虚',\n", + " '痰湿',\n", + " '湿热',\n", + " '血瘀',\n", + " '气郁',\n", + " '特禀'\n", + "]\n", + "\n", + "def tcm_calc(arr):\n", + " qa = [8, 8, 7, 8, 8, 6, 7, 7, 7]\n", + " # 成绩数组\n", + " s = [0] * 9\n", + " # 遍历五进制\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", + "\n", + "\n", + "filename = 'data/result_南京化工-2.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "i = 1\n", + "list2 = []\n", + "for k, v in dict1.items():\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(i,k,kinds[kind], near, score)\n", + " #i+=1\n", + " list3 = []\n", + " list3.append(k)\n", + " list3.append(v['name'])\n", + " list3.append(v['sex'])\n", + " list3.append(v['weight'])\n", + " list3.append(v['yao'])\n", + " list3.append(v['tun'])\n", + " list3.append(kinds[kind])\n", + " list3.append(near)\n", + " for item in score:\n", + " list3.append(item)\n", + " list2.append(list3)\n", + "\n", + "filename = 'data/南化第二次问卷明细表(截至20250831).xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "\n", + "for row in list2:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename)\n", + "print('ok') " + ] + }, + { + "cell_type": "markdown", + "id": "caf77c95-3090-4fa1-bcec-c9e8a38d4ca9", + "metadata": {}, + "source": [ + "## 体检报告汇总" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b815a478-d178-4b87-9080-a779d397d945", + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "import json\n", + "import shutil\n", + "\n", + "\n", + "target_directory = Path('./file/南化体重')\n", + "new_path = './file/南化体重/new'\n", + "filename = 'data/南京化工人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "# 遍历目标目录及其子目录获取所有文件\n", + "\n", + "for fl in target_directory.rglob('*.pdf'):\n", + " if fl.is_file():\n", + " fl_name = fl.stem\n", + " name = fl_name[12:] \n", + " for k, v in dict1.items(): \n", + " if name == v['name']:\n", + " n_name = Path(new_path,str(k)+'-'+name+'.pdf')\n", + " shutil.copyfile(fl,n_name)\n", + " print(n_name)\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4f192b79-5dc7-4517-b7f3-409e30d60dad", + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "import json\n", + "import shutil\n", + "import pymupdf4llm\n", + "#md_text = pymupdf4llm.to_markdown(\"data/1782596-唐荣.pdf\")\n", + "llama_reader = pymupdf4llm.LlamaMarkdownReader()\n", + "#llama_docs = llama_reader.load_data(\"data/1782596-唐荣.pdf\")\n", + "\n", + "\n", + "target_directory = Path('./file/北海体检报告')\n", + "new_path = './file/北海体检报告/md'\n", + "\n", + "\n", + "for fl in target_directory.rglob('*.pdf'):\n", + " if fl.is_file():\n", + " fl_name = fl.stem\n", + " llama_lists = pymupdf4llm.to_markdown(fl,page_chunks=True)\n", + " list1 = []\n", + " for item in llama_lists:\n", + " list1.append(item['text'])\n", + " llama_docs = '\\n'.join(list1)\n", + " Path(new_path,fl_name+'.md').write_bytes(llama_docs.encode())\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5863760-0d11-45b0-acb3-1a38c78d4fc7", + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "import json\n", + "import shutil\n", + "import pymupdf4llm\n", + "#md_text = pymupdf4llm.to_markdown(\"data/1782596-唐荣.pdf\")\n", + "llama_reader = pymupdf4llm.LlamaMarkdownReader()\n", + "llama_docs = llama_reader.load_data(\"data/1782596-唐荣.pdf\",page_chunks=True)\n", + "print(llama_docs)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "8d5f4103-0d1e-4711-b324-ece360f8dcd3", + "metadata": {}, + "source": [ + "## 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23ffd115-72a3-4f90-9e64-ffa6420df8a4", + "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_南京化工-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','psy57','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": "007a67c3-3590-47d9-a6d3-9080574a7940", + "metadata": {}, + "source": [ + "### 生成报告(单问卷)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "fc2bfab2-7f56-4abf-b2c4-0fb49a0da563", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-01T07:20:49.606201Z", + "iopub.status.busy": "2025-09-01T07:20:49.605939Z", + "iopub.status.idle": "2025-09-01T07:21:08.746449Z", + "shell.execute_reply": "2025-09-01T07:21:08.745281Z", + "shell.execute_reply.started": "2025-09-01T07:20:49.606179Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "83\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)\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'] == 'm':\n", + " mydata['gender'] = 'male'\n", + " else:\n", + " mydata['gender'] = 'female'\n", + " \n", + " #mydata['month'] = v['month']\n", + " #mydata['fits'] = {}\n", + " survey_list = ['tcm','psy57','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": "markdown", + "id": "42f1a67c-756a-4cf0-bd53-d71fb9c95aa6", + "metadata": {}, + "source": [ + "## 导入体检报告数据" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c2fb2c7c-6541-4c41-ba38-0e1fee29aa97", + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "import json\n", + "import shutil\n", + "\n", + "\n", + "target_directory = Path('./data/json')\n", + "filename = 'data/南京化工人员.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "# 遍历目标目录及其子目录获取所有文件\n", + "dict2 = {}\n", + "list2 = ['总胆固醇','甘油三酯','尿微量白蛋白']\n", + "for fl in target_directory.glob('*.json'):\n", + " if fl.is_file():\n", + " code = fl.stem\n", + " dict2.setdefault(code,{})\n", + " dict2[code] = dict1[code]\n", + " with open(fl,'r') as fl1:\n", + " dict3 = json.load(fl1)\n", + " for k, v in dict3.items():\n", + " if k =='血压情况' and len(v)>0:\n", + " dict2[code].setdefault('血压',{})\n", + " list1 = [] \n", + " for item in v:\n", + " \n", + " dict2[code]['血压'][item['项目']] = item['结果']\n", + " if '状态' in item.keys():\n", + " list1.append(item['项目']+item['状态'])\n", + " if len(list1)>0:\n", + " dict2[code]['血压']['状态'] = ','.join(list1)\n", + " \n", + " if k in list2:\n", + " dict2[code].setdefault(k,{})\n", + " dict2[code][k]['结果'] = v['结果']\n", + " dict2[code][k]['参考值'] = v['参考值']\n", + " if '状态' in v.keys():\n", + " dict2[code][k]['状态'] = v['状态']\n", + " if k in ['空腹血糖','糖化血红蛋白']:\n", + " dict2[code].setdefault(k,{})\n", + " if '结果' in v.keys():\n", + " dict2[code][k]['结果'] = v['结果']\n", + " dict2[code][k]['参考值'] = v['参考值']\n", + " if '状态' in v.keys():\n", + " dict2[code][k]['状态'] = v['状态']\n", + " if k in ['ALT、AST、GGT','TSH、FT3、FT4']:\n", + " for item in v:\n", + " xm = item['项目']\n", + " dict2[code].setdefault(xm,{})\n", + " if '结果' in item.keys():\n", + " dict2[code][xm]['结果'] = item['结果']\n", + " if '参考值' in item.keys():\n", + " dict2[code][xm]['参考值'] = item['参考值']\n", + " if '状态' in item.keys():\n", + " dict2[code][xm]['状态'] = item['状态']\n", + " if k =='肾功能与尿微量白蛋白':\n", + " for item in v['肾功能']:\n", + " xm = item['项目']\n", + " dict2[code].setdefault(xm,{})\n", + " if '结果' in item.keys():\n", + " dict2[code][xm]['结果'] = item['结果']\n", + " if '参考值' in item.keys():\n", + " dict2[code][xm]['参考值'] = item['参考值']\n", + " if '状态' in item.keys():\n", + " dict2[code][xm]['状态'] = item['状态'] \n", + " dict2[code].setdefault('尿微量白蛋白',{})\n", + " xm = v['尿微量白蛋白']\n", + " if '结果' in xm.keys() and len(xm['结果'])>0:\n", + " dict2[code]['尿微量白蛋白']['结果'] = xm['结果']\n", + " if '参考值' in xm.keys() and len(xm['参考值'])>0:\n", + " dict2[code]['尿微量白蛋白']['参考值'] = xm['参考值']\n", + " if '状态' in xm.keys():\n", + " dict2[code]['尿微量白蛋白']['状态'] = xm['状态'] \n", + " \n", + " \n", + "\n", + "filename = 'data/南京化工体检情况.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2, fl, ensure_ascii=False) " + ] + }, + { + "cell_type": "markdown", + "id": "da43ceef-4215-4187-a76d-4e1434e50043", + "metadata": {}, + "source": [ + "## 导出体检报告数据" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "daa1b36e-1b62-49ee-9539-84c2d286fefe", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "\n", + "filename = 'data/南京化工体检情况.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "list1 = [\"总胆固醇\",\"甘油三酯\",\"空腹血糖\",\"糖化血红蛋白\",\"谷丙转氨酶 (ALT)\",\"谷草转氨酶 (AST)\",\"γ- 谷氨酰转肽酶 (GGT)\",\"促甲状腺激素 (TSH)\",\"游离三碘甲状腺原氨酸 (FT3)\",\"游离甲状腺素 (FT4)\",\"肌酐\",\"尿素氮\",\"尿酸\",\"尿微量白蛋白\"]\n", + "title = ['编号','姓名','性别','血压','状态']\n", + "for item in list1:\n", + " title.append(item)\n", + " title.append('状态')\n", + "list3 = []\n", + "for k, v in dict1.items():\n", + " list2 = []\n", + " list2.append(k)\n", + " list2.append(v['name'])\n", + " list2.append(v['sex'])\n", + " if '血压' in v.keys():\n", + " xueya = v['血压']['舒张压']+'/'+v['血压']['收缩压']\n", + " if '状态' in v['血压'].keys():\n", + " zt = v['血压']['状态']\n", + " else:\n", + " zt = ''\n", + " else:\n", + " xueya = ''\n", + " zt = ''\n", + " \n", + " list2.append(xueya)\n", + " list2.append(zt)\n", + " for item in list1:\n", + " if item in v.keys() and '结果' in v[item]:\n", + " list2.append(v[item]['结果'])\n", + " if '状态' in v[item]:\n", + " list2.append(v[item]['状态'])\n", + " else:\n", + " list2.append('')\n", + " else:\n", + " list2.append('')\n", + " list2.append('') \n", + " list3.append(list2)\n", + "\n", + "filename = 'data/南京化工体检相关数据明细.xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "sheet.append(title)\n", + "for row in list3:\n", + " sheet.append(row)\n", + " \n", + "wb.save(filename)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "221b35dc-3a17-4950-993c-b634ee9a53cf", + "metadata": {}, + "outputs": [], + "source": [ + "from spire.pdf.common import *\n", + "from spire.pdf import *\n", + "\n", + "# 创建PdfDocument类的实例\n", + "pdf = PdfDocument()\n", + "\n", + "# 加载PDF文档\n", + "pdf.LoadFromFile(\"file/北海体检报告/2405280074.pdf\")\n", + "\n", + "# 将PDF转换为Markdown文件\n", + "pdf.SaveToFile(\"PDF转Markdown.md\", FileFormat.Markdown)\n", + "pdf.Close()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1b9d4042-5e73-44e3-8079-eee2c5be1858", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/体测单位/通用技术中国医药.ipynb b/体测单位/通用技术中国医药.ipynb index 869fadb..5c5702b 100644 --- a/体测单位/通用技术中国医药.ipynb +++ b/体测单位/通用技术中国医药.ipynb @@ -10,15 +10,15 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 8, "id": "d6449ec6-54af-4f68-8c32-69372e390acf", "metadata": { "execution": { - "iopub.execute_input": "2025-09-22T03:30:37.564857Z", - "iopub.status.busy": "2025-09-22T03:30:37.564250Z", - "iopub.status.idle": "2025-09-22T03:30:37.781384Z", - "shell.execute_reply": "2025-09-22T03:30:37.780531Z", - "shell.execute_reply.started": "2025-09-22T03:30:37.564798Z" + "iopub.execute_input": "2025-09-22T12:07:43.029162Z", + "iopub.status.busy": "2025-09-22T12:07:43.028847Z", + "iopub.status.idle": "2025-09-22T12:07:43.046141Z", + "shell.execute_reply": "2025-09-22T12:07:43.045652Z", + "shell.execute_reply.started": "2025-09-22T12:07:43.029136Z" } }, "outputs": [ @@ -45,7 +45,7 @@ " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", - " #dict1['sex'] = sheet.cell(n, 5).value\n", + " dict1['sex'] = sheet.cell(n, 6).value\n", " dict1['unit'] = sheet.cell(n, 4).value \n", " dict1['birth'] = str(sheet.cell(n, 3).value).replace('/','-').split(' ')[0]\n", " dict1['phone'] = sheet.cell(n, 5).value \n", @@ -66,15 +66,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 15, "id": "c24c957e-6cc5-4cab-81e2-cec86a7498c7", "metadata": { "execution": { - "iopub.execute_input": "2025-09-22T03:48:21.444109Z", - "iopub.status.busy": "2025-09-22T03:48:21.443422Z", - "iopub.status.idle": "2025-09-22T03:48:21.472961Z", - "shell.execute_reply": "2025-09-22T03:48:21.472454Z", - "shell.execute_reply.started": "2025-09-22T03:48:21.444045Z" + "iopub.execute_input": "2025-09-22T12:49:46.218013Z", + "iopub.status.busy": "2025-09-22T12:49:46.217356Z", + "iopub.status.idle": "2025-09-22T12:49:46.243578Z", + "shell.execute_reply": "2025-09-22T12:49:46.242996Z", + "shell.execute_reply.started": "2025-09-22T12:49:46.217955Z" } }, "outputs": [ @@ -82,7 +82,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "33\n" + "31\n" ] } ], @@ -144,11 +144,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "a64ad6b7-b1dd-42ca-9619-3adcb8e0674e", - "metadata": {}, - "outputs": [], - "source": [] + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-22T12:49:52.460408Z", + "iopub.status.busy": "2025-09-22T12:49:52.459655Z", + "iopub.status.idle": "2025-09-22T12:49:52.470790Z", + "shell.execute_reply": "2025-09-22T12:49:52.469571Z", + "shell.execute_reply.started": "2025-09-22T12:49:52.460338Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok!\n" + ] + } + ], + "source": [ + "import json\n", + "import time\n", + "import my_module as My\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_通用技术中国医药.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 'bmi' in v.keys():\n", + " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", + " bmi_data = v['bmi']['成绩']\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'] = My.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(str(v[item_en]['成绩']).split()[0])}\n", + " #print(k,v['name'])\n", + " dict2[k][item_en]['score'] = My.cal_score(data1)\n", + " #print(k,v[item_en]['成绩'],cal_score(data1))\n", + "\n", + "filename = f'data/result_通用技术中国医药.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print('ok!') " + ] }, { "cell_type": "markdown", @@ -160,15 +210,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 17, "id": "020be101-938b-427e-918d-faf2e74b5b7e", "metadata": { "execution": { - "iopub.execute_input": "2025-09-22T03:57:31.502714Z", - "iopub.status.busy": "2025-09-22T03:57:31.501987Z", - "iopub.status.idle": "2025-09-22T03:57:31.516781Z", - "shell.execute_reply": "2025-09-22T03:57:31.515780Z", - "shell.execute_reply.started": "2025-09-22T03:57:31.502649Z" + "iopub.execute_input": "2025-09-22T12:49:55.871938Z", + "iopub.status.busy": "2025-09-22T12:49:55.871204Z", + "iopub.status.idle": "2025-09-22T12:49:55.886755Z", + "shell.execute_reply": "2025-09-22T12:49:55.885950Z", + "shell.execute_reply.started": "2025-09-22T12:49:55.871866Z" } }, "outputs": [], @@ -244,10 +294,103 @@ " json.dump(dict1, fl, ensure_ascii=False)" ] }, + { + "cell_type": "markdown", + "id": "7ec62459-2938-4c0c-b35a-f4341630f1c6", + "metadata": {}, + "source": [ + "## 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "17dd5667-d970-46d2-b241-27338dbba4bb", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-22T12:51:00.278870Z", + "iopub.status.busy": "2025-09-22T12:51:00.278200Z", + "iopub.status.idle": "2025-09-22T12:51:14.234951Z", + "shell.execute_reply": "2025-09-22T12:51:14.233971Z", + "shell.execute_reply.started": "2025-09-22T12:51:00.278810Z" + }, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "31\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_通用技术中国医药-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'] = v['month']\n", + " mydata['fits'] = {}\n", + " survey_list = ['tcm','psy57','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 = str(v[item]['成绩']).split()[0].split('.')[0]\n", + " else:\n", + " mark = str(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": "9560d0ca-4d39-400b-b054-214e243ca4e5", + "id": "4297b542-206e-4f0e-9339-ba88e712443e", "metadata": {}, "outputs": [], "source": [] diff --git a/文件管理.ipynb b/文件管理.ipynb index 6409c47..b6cec13 100644 --- a/文件管理.ipynb +++ b/文件管理.ipynb @@ -114,40 +114,15 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "11ff2c59-5815-42c9-abaf-71c8c2a3b7da", - "metadata": {}, - "outputs": [], - "source": [ - "import os,sys,shutil\n", - "from pathlib import Path\n", - "\n", - "fi_path = 'file/北海/未参加体测人员报告'\n", - "new_path = 'file/北海/new/未参加体测人员'\n", - "pdf_files = list(fi_path.glob('**/*.pdf'))\n", - "\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)\n", - " print(fn)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "id": "62ff063a-5380-4e08-b115-acd967441ca4", "metadata": { "execution": { - "iopub.execute_input": "2025-09-16T02:36:40.592582Z", - "iopub.status.busy": "2025-09-16T02:36:40.591749Z", - "iopub.status.idle": "2025-09-16T02:36:40.635821Z", - "shell.execute_reply": "2025-09-16T02:36:40.635329Z", - "shell.execute_reply.started": "2025-09-16T02:36:40.592518Z" + "iopub.execute_input": "2025-09-17T00:08:50.471131Z", + "iopub.status.busy": "2025-09-17T00:08:50.470548Z", + "iopub.status.idle": "2025-09-17T00:08:51.110490Z", + "shell.execute_reply": "2025-09-17T00:08:51.109925Z", + "shell.execute_reply.started": "2025-09-17T00:08:50.471076Z" } }, "outputs": [], @@ -155,8 +130,9 @@ "import os,sys,shutil\n", "from pathlib import Path\n", "\n", - "fi_path =Path('file/北海/未参加体测人员报告')\n", - "new_path = 'file/北海/new/未参加体测人员'\n", + "fi_path = Path('file/北海/2022年')\n", + "new_path = 'file/北海/new/2022年'\n", + "pdf_files = list(fi_path.glob('**/*.pdf'))\n", "fls = list(fi_path.glob('**/*.pdf'))\n", "for fn in fls:\n", " fi_name =Path(fn).name\n",