{ "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/党建出版社2025.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "\n", "for n in range(2, sheet.max_row+1):\n", " code = int(sheet.cell(n, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", " dict1['unit'] = '党建出版社'\n", " dict1['birth'] = sheet.cell(n,3).value\n", " dict1['phone'] = 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('ok')" ] }, { "cell_type": "code", "execution_count": null, "id": "9448933d-527c-410d-ba55-4ce1819a8c1e", "metadata": {}, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/通用卡.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "\n", "for n in range(2, sheet.max_row+1):\n", " code = int(sheet.cell(n, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", " dict1['birth'] = sheet.cell(n,3).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('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':'编号卡'}\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/党建出版社2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/marks_20250530.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\n", "filename = 'data/result_党建出版社2025.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": "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 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_党建出版社2025.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_党建出版社2025.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": "67e63f07-3f20-4e0e-9c07-7bf6024eeb4b", "metadata": {}, "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_党建出版社2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/党建出版社2025.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/党建出版社测试情况表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", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "b1c9377b-0da3-481a-9334-b85aa0487374", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": 21, "id": "e454f645-e593-4619-9fce-eabe0fa9f2a9", "metadata": { "execution": { "iopub.execute_input": "2025-06-05T06:49:32.523392Z", "iopub.status.busy": "2025-06-05T06:49:32.522703Z", "iopub.status.idle": "2025-06-05T06:49:32.550951Z", "shell.execute_reply": "2025-06-05T06:49:32.550460Z", "shell.execute_reply.started": "2025-06-05T06:49:32.523324Z" } }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "#import my_module as My\n", "\n", "dict1 = {}\n", "filename = 'data/result_党建出版社2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "filename = 'data/党建出版社2025.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[str(v['phone'])] = k\n", "\n", "list1 = []\n", "filename = 'data/survey_records_20250605.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", "psy =[]\n", "tcm = []\n", "spine = []\n", "for i in range(0,57):\n", " psy.append(0)\n", "\n", "for i in range(0,60):\n", " tcm.append(0)\n", "for i in range(0,26):\n", " spine.append(0)\n", "i= 1\n", "for item in list1:\n", " if item[3] in phone.keys():\n", " psy =[]\n", " tcm = []\n", " spine = []\n", " for i in range(0,57):\n", " psy.append(0)\n", " #psy[44] = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for i in range(0,26):\n", " spine.append(0)\n", " \n", " content = json.loads(item[4])\n", " if phone[item[3]] not in dict1.keys():\n", " dict1[phone[item[3]]] = dict3[phone[item[3]]]\n", " rq = date.fromisoformat(item[5].replace('/','-').split(' ')[0])\n", " #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " else:\n", " rq = date.fromisoformat('2025-05-30')\n", " for k, v in content.items():\n", " if 'psy' in k:\n", " i = int(k[3:])\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 'psy' in item[4]:\n", " #for i in range(5,26):\n", " # new_valve = 5-psy[i]\n", " # psy[i] = new_valve\n", " \n", " \n", " dict1[phone[item[3]]]['psy57'] = psy\n", " if 'tcm' in item[4]:\n", " dict1[phone[item[3]]]['tcm'] = tcm\n", " if 'spine' in item[4]:\n", " dict1[phone[item[3]]]['spine'] = spine\n", " birth = date.fromisoformat(dict3[phone[item[3]]]['birth'].replace('/','-'))\n", " \n", " days = (rq-birth).days \n", " dict1[phone[item[3]]]['age'] = int(days/365)\n", " dict1[phone[item[3]]]['month'] = int(days/365*12)\n", " \n", "\n", "filename = 'data/result_党建出版社2025-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "#print(data1[1])" ] }, { "cell_type": "markdown", "id": "41a8ef94-57a1-4697-b99b-cb546adb09e5", "metadata": {}, "source": [ "## 统计参加问卷人员" ] }, { "cell_type": "code", "execution_count": 20, "id": "2ea13ff2-a675-41b2-b104-0f5cd1c9a0b5", "metadata": { "execution": { "iopub.execute_input": "2025-06-05T01:06:25.708014Z", "iopub.status.busy": "2025-06-05T01:06:25.707173Z", "iopub.status.idle": "2025-06-05T01:06:25.734176Z", "shell.execute_reply": "2025-06-05T01:06:25.733170Z", "shell.execute_reply.started": "2025-06-05T01:06:25.707934Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "85\n" ] } ], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "filename = 'data/党建出版社2025.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_20250605.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(len(phone1))\n", "i =1\n", "list2 = []\n", "for item in list1:\n", " code = int(item[3])\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/党建出版社问卷情况表2025.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": "7c2ef41d-bba9-4776-9a0e-71e14cd7d3fe", "metadata": {}, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "filename = 'data/党建出版社2025.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_20250605.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(len(phone1))\n", "i =1\n", "list2 = []\n", "for item in list1:\n", " code = int(item[3])\n", " if code not in phone1:\n", " print(code)" ] }, { "cell_type": "markdown", "id": "ffb387e1-41b5-4a4d-a9ca-89e1c5650880", "metadata": {}, "source": [ "## 生成报告" ] }, { "cell_type": "code", "execution_count": 22, "id": "462bc4e8-1659-43a0-9cbf-a87a4dfc5376", "metadata": { "execution": { "iopub.execute_input": "2025-06-05T06:50:13.169871Z", "iopub.status.busy": "2025-06-05T06:50:13.168552Z", "iopub.status.idle": "2025-06-05T06:50:51.648786Z", "shell.execute_reply": "2025-06-05T06:50:51.647689Z", "shell.execute_reply.started": "2025-06-05T06:50:13.169789Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "65\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_党建出版社2025-1.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "file_path ='./党建出版社2025/'\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'] = ' '\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": "f28bb6dd-c8de-4761-a8a1-83b65a504a7d", "metadata": {}, "source": [ "## 计算中医体质" ] }, { "cell_type": "code", "execution_count": 24, "id": "0f393c7d-26b2-4bb2-8f18-702f5ee52abf", "metadata": { "execution": { "iopub.execute_input": "2025-06-05T06:59:54.308502Z", "iopub.status.busy": "2025-06-05T06:59:54.307891Z", "iopub.status.idle": "2025-06-05T06:59:54.340029Z", "shell.execute_reply": "2025-06-05T06:59:54.339248Z", "shell.execute_reply.started": "2025-06-05T06:59:54.308441Z" } }, "outputs": [ { "ename": "NameError", "evalue": "name 'tcm_calc' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[24], line 15\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m tcm:\n\u001b[1;32m 14\u001b[0m list1\u001b[38;5;241m.\u001b[39mappend(item)\n\u001b[0;32m---> 15\u001b[0m score \u001b[38;5;241m=\u001b[39m \u001b[43mtcm_calc\u001b[49m(list1)\n\u001b[1;32m 17\u001b[0m result \u001b[38;5;241m=\u001b[39m tcm_kind(score)\n\u001b[1;32m 18\u001b[0m kind \u001b[38;5;241m=\u001b[39m result[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mkind\u001b[39m\u001b[38;5;124m'\u001b[39m]\n", "\u001b[0;31mNameError\u001b[0m: name 'tcm_calc' is not defined" ] } ], "source": [ "import openpyxl\n", "import my_module as My\n", "\n", "filename = 'data/result_党建出版社2025-1.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(kinds[kind])\n", " list3.append(near)\n", " for item in score:\n", " list3.append(item)\n", " list2.append(list3)\n", "print(list2)\n", "filename = 'data/党建出版社中医情况明细表2025.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": "code", "execution_count": null, "id": "02057c2d-f2e5-4c09-8c2d-508bedb95817", "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 }