This commit is contained in:
512song committed 2025-10-30 08:24:56 +08:00
1 parent a10492f0ad
commit 9ec7907bde
4 files changed
+1062 -1793

No files matched your search

+219 -618
View File
@@ -10,33 +10,48 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"id": "bbba6efc-73cd-4db6-bae7-014724fee731",
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-23T04:40:11.186792Z",
"iopub.status.busy": "2025-10-23T04:40:11.186527Z",
"iopub.status.idle": "2025-10-23T04:40:11.243321Z",
"shell.execute_reply": "2025-10-23T04:40:11.242693Z",
"shell.execute_reply.started": "2025-10-23T04:40:11.186767Z"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"412 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-22T05:36:04.807935Z",
"iopub.status.busy": "2025-10-22T05:36:04.807038Z",
"iopub.status.idle": "2025-10-22T05:36:04.823769Z",
"shell.execute_reply": "2025-10-22T05:36:04.822605Z",
"shell.execute_reply.started": "2025-10-22T05:36:04.807861Z"
},
"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,11 +105,78 @@
"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')"
]
},
{
"cell_type": "markdown",
"id": "a627e5b1-15c7-405b-9c81-2022e1173ed3",
"metadata": {},
"source": [
"## 合并读卡系统文件"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "82526579-8902-458d-a097-c2446983fa3f",
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-23T04:40:17.340605Z",
"iopub.status.busy": "2025-10-23T04:40:17.339457Z",
"iopub.status.idle": "2025-10-23T04:40:17.357806Z",
"shell.execute_reply": "2025-10-23T04:40:17.356944Z",
"shell.execute_reply.started": "2025-10-23T04:40:17.340544Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"496834 李继升 QHSE监督中心\n",
"3532664 谭嘉辰 人力资源(组织)部\n",
"496657 张秀成 企业管理部(三基工作办公室)\n",
"495136 闫福霞 公共事业服务中心\n",
"494062 赵霞 公共事业服务中心\n",
"495293 赵振华 \n",
"689404 马科 胜利采油厂\n",
"498782 封莹 胜利采油厂\n",
"999999 孙振峰 \n",
"445607 王大明 \n",
"490000 陆岩玮 信息化服务中心\n",
"000000 焦瀛 胜利采油厂\n",
"424 ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/胜利采油厂人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/data_胜利采油厂人员(1).json'\n",
"with open(filename,'r') as fl:\n",
" list1 = json.load(fl)\n",
"for item in list1:\n",
" code = item['id']\n",
" if code not in dict1.keys():\n",
" print(code,item['name'],item['unit'])\n",
" dict1.setdefault(code,{})\n",
" dict1[code]['name'] = item['name']\n",
" dict1[code]['sex'] = item['gender']\n",
" dict1[code]['unit'] = item['unit']\n",
" dict1[code]['birth'] = item['birth']\n",
"filename = 'data/胜利采油厂人员.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print(len(dict1),'ok')"
]
},
{
"cell_type": "markdown",
"id": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f",
@@ -90,12 +187,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"id": "970e171e-1360-448f-a28c-520ccb8f314a",
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-23T04:40:34.626526Z",
"iopub.status.busy": "2025-10-23T04:40:34.625771Z",
"iopub.status.idle": "2025-10-23T04:40:34.653754Z",
"shell.execute_reply": "2025-10-23T04:40:34.653195Z",
"shell.execute_reply.started": "2025-10-23T04:40:34.626453Z"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"216\n"
]
}
],
"source": [
"import json\n",
"import datetime\n",
@@ -103,14 +215,14 @@
"from datetime import date\n",
"import my_module as My\n",
"\n",
"filename = 'data/南京化工人员.json'\n",
"filename = 'data/胜利采油厂人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"filename = 'data/marks_20250703.csv'\n",
"filename = 'data/marks_20251023.csv'\n",
"re_ta = My.get_result(filename,dict1)\n",
"\n",
"\n",
"filename = 'data/result_南京化工.json'\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))"
@@ -128,8 +240,21 @@
"cell_type": "code",
"execution_count": null,
"id": "0905ad6a-f7e4-43ed-ae29-c4850deb946b",
"metadata": {},
"outputs": [],
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-27T01:50:10.738997Z",
"iopub.status.busy": "2025-10-27T01:50:10.738633Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import json\n",
"import time\n",
@@ -137,7 +262,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_南京化工.json'\n",
"filename = 'data/result_胜利采油厂1.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"for k, v in dict2.items():\n",
@@ -160,12 +285,73 @@
" 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",
"filename = f'data/result_胜利采油厂1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "3f7a810e-2a5f-4856-8119-bfe299b71f92",
"metadata": {},
"source": [
"## 补充人员信息"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "9c3b7195-b7f3-4355-90bc-9f1ae322641d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-27T01:22:18.116597Z",
"iopub.status.busy": "2025-10-27T01:22:18.116000Z",
"iopub.status.idle": "2025-10-27T01:22:18.187150Z",
"shell.execute_reply": "2025-10-27T01:22:18.186557Z",
"shell.execute_reply.started": "2025-10-27T01:22:18.116559Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"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",
"dict1 = {}\n",
"\n",
"filename = 'data/result_胜利采油厂.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"list1 = []\n",
"for n in range(2, sheet.max_row+1):\n",
" code = int(sheet.cell(n, 1).value)\n",
" unit = sheet.cell(n, 4).value\n",
" dict1[code] = unit\n",
"for k, v in dict2.items():\n",
" if int(k) not in dict1.keys():\n",
" list1.append(k)\n",
" else:\n",
" dict2[k]['unit'] = dict1[int(k)]\n",
"for item in list1:\n",
" del dict2[item]\n",
"filename = f'data/result_胜利采油厂1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') \n"
]
},
{
"cell_type": "markdown",
"id": "d034a61d-1fbd-417b-99bd-277e43ebb678",
@@ -176,9 +362,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890",
"metadata": {
"execution": {
"iopub.execute_input": "2025-10-23T04:41:25.970953Z",
"iopub.status.busy": "2025-10-23T04:41:25.969895Z",
"iopub.status.idle": "2025-10-23T04:41:26.058240Z",
"shell.execute_reply": "2025-10-23T04:41:26.057610Z",
"shell.execute_reply.started": "2025-10-23T04:41:25.970875Z"
},
"tags": []
},
"outputs": [],
@@ -189,18 +382,18 @@
"items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n",
"title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"filename = 'data/result_南京化工.json'\n",
"filename = 'data/result_胜利采油厂.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/南京化工人员.json'\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(str(k).rjust(8,'0'))\n",
" list2.append(v['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit'])\n",
@@ -221,7 +414,7 @@
" list2.append('')\n",
" \n",
" list1.append(list2)\n",
"filename = 'data/南京化工测试情况明细表(截至20250630).xlsx'\n",
"filename = 'data/胜利采油厂测试情况明细表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet.append(title)\n",
@@ -231,598 +424,6 @@
"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",