{ "cells": [ { "cell_type": "markdown", "id": "4c41a2bd-7340-4a3b-9257-8d8615a20a09", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 16, "id": "eb9aa782-ce2c-4814-bdf6-92c7e892854d", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:01:26.433165Z", "iopub.status.busy": "2025-06-30T06:01:26.432555Z", "iopub.status.idle": "2025-06-30T06:01:26.459168Z", "shell.execute_reply": "2025-06-30T06:01:26.458635Z", "shell.execute_reply.started": "2025-06-30T06:01:26.433107Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "51\n", "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(3, 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", " dict1['unit'] = '第二期'\n", " dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]\n", " dict1['id'] = sheet.cell(n, 5).value\n", " if sheet.cell(n,6).value is not None:\n", " dict1['phone'] = str(sheet.cell(n,6).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))\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "40f2c77d-1504-4288-9ed0-a0a4678579ee", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": 6, "id": "4e0de75e-6957-434a-9591-da96c21f4659", "metadata": { "execution": { "iopub.execute_input": "2025-03-03T07:21:43.877959Z", "iopub.status.busy": "2025-03-03T07:21:43.877156Z", "iopub.status.idle": "2025-03-03T07:21:43.888327Z", "shell.execute_reply": "2025-03-03T07:21:43.887102Z", "shell.execute_reply.started": "2025-03-03T07:21:43.877887Z" } }, "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/card_海淀区老干部大学.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "188fb9fc-a6e4-4aec-b503-5e96e4981ef5", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 17, "id": "fd005ed3-24ee-4b39-a619-6c83e64c2852", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:01:30.713754Z", "iopub.status.busy": "2025-06-30T06:01:30.713036Z", "iopub.status.idle": "2025-06-30T06:01:30.730192Z", "shell.execute_reply": "2025-06-30T06:01:30.729306Z", "shell.execute_reply.started": "2025-06-30T06:01:30.713687Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "30\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_20250627.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", " 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", " 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": "37c2ccf4-5d95-4f32-a9c2-28669aa90a3d", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": 18, "id": "9481765c-92b7-4a58-b192-582bb001f167", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:01:33.186253Z", "iopub.status.busy": "2025-06-30T06:01:33.185404Z", "iopub.status.idle": "2025-06-30T06:01:33.201547Z", "shell.execute_reply": "2025-06-30T06:01:33.200481Z", "shell.execute_reply.started": "2025-06-30T06:01:33.186179Z" } }, "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": "bb21f690-115d-4b04-8752-5962a7eafeaf", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": 21, "id": "63c81b75-9b3d-4001-a5da-32b7cf992843", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:03:51.688275Z", "iopub.status.busy": "2025-06-30T06:03:51.687558Z", "iopub.status.idle": "2025-06-30T06:03:51.718118Z", "shell.execute_reply": "2025-06-30T06:03:51.717651Z", "shell.execute_reply.started": "2025-06-30T06:03:51.688211Z" } }, "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/海淀区老干部大学第二期.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": "c9bacc5b-6d55-41da-a30e-2862cf544a95", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": 19, "id": "dd8ed4fe-5014-455f-993d-64a41519de6d", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:01:40.122434Z", "iopub.status.busy": "2025-06-30T06:01:40.121692Z", "iopub.status.idle": "2025-06-30T06:01:40.143208Z", "shell.execute_reply": "2025-06-30T06:01:40.142553Z", "shell.execute_reply.started": "2025-06-30T06:01:40.122360Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "28\n" ] } ], "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_20250627.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 item[2] in phone.keys():\n", " psy =[]\n", " tcm = []\n", " spine = []\n", " for i in range(0,30):\n", " psy.append(0)\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[5])\n", " if phone[item[2]] not in dict1.keys():\n", " dict1[phone[item[2]]] = dict3[phone[item[2]]]\n", " rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " dict1[phone[item[2]]]['rq'] = item[6].replace('/','-').split(' ')[0]\n", " for k, v in content.items():\n", " if 'psyOld' in k:\n", " i = int(k[6:])\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 'psyOld' in item[5]:\n", " \n", " \n", " dict1[phone[item[2]]]['psy_yangmiao_old'] = psy\n", " if 'tcm' in item[5]:\n", " \n", " dict1[phone[item[2]]]['tcm'] = tcm\n", " if 'spine' in item[5]:\n", " for ii in range(25,23,-1):\n", " spine[ii] = spine[ii-1]\n", " spine[22] = 0 \n", " dict1[phone[item[2]]]['spine'] = spine\n", " birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n", " \n", " days = (rq-birth).days \n", " dict1[phone[item[2]]]['age'] = int(days/365)\n", " dict1[phone[item[2]]]['month'] = int(days/365*12)\n", " #print(phone[item[2]])\n", " nn+=1\n", "filename = 'data/result_海淀区老干部大学第二期-1.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(nn)" ] }, { "cell_type": "markdown", "id": "6b4ffd63-e38b-4a19-9ed7-5cfcc8a1882a", "metadata": {}, "source": [ "## 生成报告" ] }, { "cell_type": "code", "execution_count": 20, "id": "b8b2fc93-9e8b-4bde-bc13-2de179de2b2d", "metadata": { "execution": { "iopub.execute_input": "2025-06-30T06:01:46.226970Z", "iopub.status.busy": "2025-06-30T06:01:46.226283Z", "iopub.status.idle": "2025-06-30T06:02:03.514203Z", "shell.execute_reply": "2025-06-30T06:02:03.513671Z", "shell.execute_reply.started": "2025-06-30T06:01:46.226904Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "33\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'] = '2025年春季体质提升班'\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": "code", "execution_count": null, "id": "974b19a1-b88e-45a6-9426-9fdb9893101c", "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 }