This commit is contained in:
512song committed 2026-01-22 22:08:19 +08:00
1 parent 72a94b8de3
commit 262b081f94
6 files changed
+958 -650

No files matched your search

+477
View File
@@ -0,0 +1,477 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "579527eb-e2aa-4af6-9668-646e0a997d79",
"metadata": {},
"source": [
"## 体测人员导入"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "272aca0e-b70c-46fe-ae58-ad8aaa5b9fa5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-22T13:27:05.690761Z",
"iopub.status.busy": "2026-01-22T13:27:05.690222Z",
"iopub.status.idle": "2026-01-22T13:27:05.710714Z",
"shell.execute_reply": "2026-01-22T13:27:05.710237Z",
"shell.execute_reply.started": "2026-01-22T13:27:05.690707Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"48 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",
"person = {}\n",
"\n",
"for n in range(2, sheet.max_row+1):\n",
" code = int(sheet.cell(n, 1).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n, 3).value\n",
" \n",
" dict1['unit'] = sheet.cell(n, 4).value\n",
" dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \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": "2c452983-0914-4508-86d6-2d9d5f966a8c",
"metadata": {},
"source": [
"## 生成读卡系统文件"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fde0146f-02e7-4519-9029-5819b2cc1a20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-21T08:58:28.607660Z",
"iopub.status.busy": "2026-01-21T08:58:28.607052Z",
"iopub.status.idle": "2026-01-21T08:58:28.617819Z",
"shell.execute_reply": "2026-01-21T08:58:28.616724Z",
"shell.execute_reply.started": "2026-01-21T08:58:28.607601Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"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": "28875e1d-1c0f-443a-a780-4cbea10a5133",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "32ef3c92-8644-4421-a9dd-8ae901cb2710",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-22T13:30:00.421898Z",
"iopub.status.busy": "2026-01-22T13:30:00.420630Z",
"iopub.status.idle": "2026-01-22T13:30:00.440823Z",
"shell.execute_reply": "2026-01-22T13:30:00.439903Z",
"shell.execute_reply.started": "2026-01-22T13:30:00.421820Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"29\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/中心健康检测人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/marks_20260122.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": "a882cae1-9df1-4267-ba07-82097f67ab05",
"metadata": {},
"source": [
"## 生成测试得分"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "728c6978-bc53-44e4-b986-a13d5e2cd889",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-22T13:30:37.706987Z",
"iopub.status.busy": "2026-01-22T13:30:37.706464Z",
"iopub.status.idle": "2026-01-22T13:30:37.725209Z",
"shell.execute_reply": "2026-01-22T13:30:37.724253Z",
"shell.execute_reply.started": "2026-01-22T13:30:37.706936Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok! 29\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(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 = 'data/result_中心健康检测人员.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!',len(dict2)) "
]
},
{
"cell_type": "markdown",
"id": "64c5731f-ecb2-4524-8be0-0711926fe256",
"metadata": {},
"source": [
"## 导入问卷信息"
]
},
{
"cell_type": "markdown",
"id": "8dcfb696-7031-4647-b142-cf83c30d3a90",
"metadata": {},
"source": [
"### 按照姓名导入"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "5c90241e-b445-431a-8b59-66a40da2d1e6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-22T13:52:46.021181Z",
"iopub.status.busy": "2026-01-22T13:52:46.020643Z",
"iopub.status.idle": "2026-01-22T13:52:46.038655Z",
"shell.execute_reply": "2026-01-22T13:52:46.037963Z",
"shell.execute_reply.started": "2026-01-22T13:52:46.021130Z"
}
},
"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",
"\n",
"\n",
"list1 = []\n",
"filename = 'data/sql_20260122.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",
" \n",
" \n",
"for item in list1:\n",
" content = json.loads(json.loads(item[1]))\n",
" name = content['name']\n",
" for k, v in dict1.items():\n",
" if v['name'] == name:\n",
" tcm = [] \n",
" for i in range(0,60):\n",
" tcm.append(0)\n",
" rq = date.fromisoformat(item[2].replace('/','-').split(' ')[0])\n",
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
" \n",
" for k1, v1 in content.items(): \n",
" if 'tcm' in k1: \n",
" i = int(k1[3:])\n",
" tcm[i-1] = int(v1)\n",
" #print(tcm) \n",
" if 'tcm' in item[1]: \n",
" dict1[k]['tcm'] = tcm \n",
" \n",
" #dict1[k]['rq'] = rq\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": "e6606f92-76c1-434d-be3c-284ceb900f3f",
"metadata": {},
"source": [
"## 生成报告"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "d451cce5-e3a3-4909-bd13-807ddf82059a",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-22T13:55:59.725677Z",
"iopub.status.busy": "2026-01-22T13:55:59.725108Z",
"iopub.status.idle": "2026-01-22T13:56:14.228014Z",
"shell.execute_reply": "2026-01-22T13:56:14.226903Z",
"shell.execute_reply.started": "2026-01-22T13:55:59.725621Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"29\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_中心健康检测人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"list1 = []\n",
"file_path ='./中心健康检测/'\n",
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
"i=0\n",
"list2 = []\n",
"for k, v in dict1.items():\n",
" list1 = []\n",
" mydata = {}\n",
" \n",
" id = str(k).rjust(4,\"0\")\n",
" mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n",
" mydata['title'] = '中心健康体质检测'\n",
" mydata['subtitle'] = v['unit']\n",
" mydata['id'] = id\n",
" mydata['name'] = v['name']\n",
" if v['sex'] == '男':\n",
" mydata['gender'] = 'male'\n",
" else:\n",
" mydata['gender'] = 'female'\n",
" \n",
" mydata['month'] = v['month']\n",
" mydata['fits'] = {}\n",
" survey_list = ['tcm','psy_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",
" 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",
" if len(mydata['fits']) >2 or 'surveys' in mydata.keys():\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": "7dd43a2d-f467-44f1-89d8-b76461925297",
"metadata": {},
"source": [
"## 生成体质检测明细表"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d991b368-46bc-47cc-81d1-591d636364d9",
"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
}