{ "cells": [ { "cell_type": "markdown", "id": "eaf32c48-d935-4780-9272-8f5ddddf80e5", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 5, "id": "3d5ddc7a-a331-438d-aa8d-1ad74c7250d0", "metadata": { "execution": { "iopub.execute_input": "2025-03-15T11:30:29.780788Z", "iopub.status.busy": "2025-03-15T11:30:29.780027Z", "iopub.status.idle": "2025-03-15T11:30:29.813663Z", "shell.execute_reply": "2025-03-15T11:30:29.813167Z", "shell.execute_reply.started": "2025-03-15T11:30:29.780712Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "from datetime import date\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'] = str(sheet.cell(n, 3).value).replace('/','-').split(' ')[0] \n", " dict1['phone'] = str(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('ok')" ] }, { "cell_type": "markdown", "id": "faf346a5-3b0e-414e-ab64-dbde3b8c3dbd", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 1, "id": "36aa14f9-cdfd-4ad4-a84e-9809c9db9958", "metadata": { "execution": { "iopub.execute_input": "2025-03-15T11:53:27.327555Z", "iopub.status.busy": "2025-03-15T11:53:27.327111Z", "iopub.status.idle": "2025-03-15T11:53:27.348436Z", "shell.execute_reply": "2025-03-15T11:53:27.347781Z", "shell.execute_reply.started": "2025-03-15T11:53:27.327503Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "14\n" ] } ], "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_20250315.csv'\n", "re_ta = My.get_result(filename,dict1)\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": "a68d4f7f-d23a-4649-99eb-ce13b6027414", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": 7, "id": "8f459ed3-fc14-404f-998b-5ed2a15958c3", "metadata": { "execution": { "iopub.execute_input": "2025-03-15T11:30:35.367110Z", "iopub.status.busy": "2025-03-15T11:30:35.366428Z", "iopub.status.idle": "2025-03-15T11:30:35.380746Z", "shell.execute_reply": "2025-03-15T11:30:35.379748Z", "shell.execute_reply.started": "2025-03-15T11:30:35.367051Z" } }, "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(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": "582e988f-3226-4209-a348-60be2a7750a1", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": 11, "id": "93feeeb4-85ea-48e9-9358-0efa00725ede", "metadata": { "execution": { "iopub.execute_input": "2025-02-16T15:26:48.864416Z", "iopub.status.busy": "2025-02-16T15:26:48.863673Z", "iopub.status.idle": "2025-02-16T15:26:48.890284Z", "shell.execute_reply": "2025-02-16T15:26:48.889595Z", "shell.execute_reply.started": "2025-02-16T15:26:48.864343Z" } }, "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('延庆')\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/延庆体测情况表250216.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": 5, "id": "f44c57ed-aac8-481a-9126-0dadcbe0190c", "metadata": { "execution": { "iopub.execute_input": "2025-02-23T10:14:06.379557Z", "iopub.status.busy": "2025-02-23T10:14:06.379298Z", "iopub.status.idle": "2025-02-23T10:14:06.424726Z", "shell.execute_reply": "2025-02-23T10:14:06.424184Z", "shell.execute_reply.started": "2025-02-23T10:14:06.379536Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "bmi = ['height','weight']\n", "title = ['编号','姓名','性别','身高','体重','bmi','肺活量','得分','握力','得分','坐位体前屈','得分','纵跳','得分','俯卧撑','得分','一分钟仰卧起坐','得分','单脚站立','得分','选择反应时','得分','台阶指数','得分']\n", "\n", "filename = 'data/result_延庆人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "list1 = []\n", "for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n", " list2 = []\n", " list2.append(str(k).rjust(5,'0'))\n", " list2.append(dict1[k]['name']) \n", " list2.append(dict1[k]['sex'])\n", " i = 0\n", " if 'bmi' in dict1[k].keys():\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[0])\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[1])\n", " list2.append(dict1[k]['bmi']['score'])\n", " i+=1\n", " else:\n", " list2.append('') \n", " list2.append('') \n", " list2.append('') \n", " \n", " \n", " for item in items:\n", " if item in dict1[k].keys():\n", " list2.append(dict1[k][item]['成绩'])\n", " list2.append(dict1[k][item]['score']) \n", " i+=1\n", " elif item =='name':\n", " list2.append(dict1[k][item])\n", " else:\n", " list2.append('') \n", " list2.append('') \n", " if i>2:\n", " list1.append(list2)\n", "filename = 'data/延庆体测情况表250223.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)\n", "print('ok') " ] }, { "cell_type": "markdown", "id": "7a065563-5478-45df-bf7d-3c2654ca1607", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": 8, "id": "7c170e0e-e618-42b2-99ee-7b6f2ee34bb4", "metadata": { "execution": { "iopub.execute_input": "2025-03-15T11:30:50.221964Z", "iopub.status.busy": "2025-03-15T11:30:50.221472Z", "iopub.status.idle": "2025-03-15T11:30:50.229690Z", "shell.execute_reply": "2025-03-15T11:30:50.229155Z", "shell.execute_reply.started": "2025-03-15T11:30:50.221936Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "7\n" ] } ], "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", "\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_20250315.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", "data1 = My.get_wenjuan(list1,phone,dict1,dict3)\n", "\n", "\n", "filename = 'data/result_延庆人员-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(data1[0], fl, ensure_ascii=False)\n", "print(data1[1])\n" ] }, { "cell_type": "markdown", "id": "f86b0f59-c1f6-4523-aefd-854f04305ec9", "metadata": {}, "source": [ "## 生成报告" ] }, { "cell_type": "code", "execution_count": 9, "id": "9e843585-fef3-4f5c-baae-76e711f2a42f", "metadata": { "execution": { "iopub.execute_input": "2025-03-15T11:31:04.247327Z", "iopub.status.busy": "2025-03-15T11:31:04.246569Z", "iopub.status.idle": "2025-03-15T11:31:12.426034Z", "shell.execute_reply": "2025-03-15T11:31:12.425404Z", "shell.execute_reply.started": "2025-03-15T11:31:04.247255Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "14\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(5,\"0\")\n", " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", " mydata['title'] = '延庆'\n", " mydata['subtitle'] = ''#v['unit']\n", " mydata['id'] = id\n", " mydata['name'] = v['name']\n", " if v['sex'] == '男':\n", " mydata['gender'] = 'male'\n", " else:\n", " mydata['gender'] = 'female'\n", " \n", " mydata['month'] = v['month']\n", " mydata['fits'] = {}\n", " survey_list = ['tcm','psy','spine']\n", " for item in survey_list:\n", " if item in v.keys():\n", " mydata.setdefault('surveys',{})\n", " mydata['surveys'][item] = v[item]\n", " \n", " \n", " #mydata['fits'] = {}\n", " for item in list_item:\n", " if item in v.keys():\n", " mydata.setdefault('fits',{})\n", " if item in ['lung','pushup','step','situp']:\n", " mark = v[item]['成绩'].split()[0].split('.')[0]\n", " else:\n", " mark = v[item]['成绩'].split()[0]\n", " mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n", " if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n", " #if len(mydata['fits']) >2 : \n", " list1.append(mydata)\n", " list2.append([k,v['name']])\n", " i+=1\n", " x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n", " #print(id,v['name'],x.text)\n", " #print(mydata)\n", " #x.close()\n", "print(i)" ] }, { "cell_type": "code", "execution_count": null, "id": "7143c16b-6e45-4a10-a04c-6b90631ddfb0", "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 }