{ "cells": [ { "cell_type": "markdown", "id": "ade4f5e9-de5f-4926-8e53-c98df98e107a", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 20, "id": "43e14491-bc5c-4e73-89f0-a3ea64a15772", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:11:51.050015Z", "iopub.status.busy": "2025-10-24T03:11:51.049715Z", "iopub.status.idle": "2025-10-24T03:11:51.064152Z", "shell.execute_reply": "2025-10-24T03:11:51.063565Z", "shell.execute_reply.started": "2025-10-24T03:11:51.049989Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "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['unit'] = ''\n", " dict1['birth'] = sheet.cell(n,3).value\n", " dict1['phone'] = 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('ok')" ] }, { "cell_type": "markdown", "id": "21a07528-d09b-4ff3-a7f5-584329e9b306", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 21, "id": "227b85c8-aa2d-4e48-8204-119dffb082be", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:11:54.253047Z", "iopub.status.busy": "2025-10-24T03:11:54.252120Z", "iopub.status.idle": "2025-10-24T03:11:54.263734Z", "shell.execute_reply": "2025-10-24T03:11:54.262670Z", "shell.execute_reply.started": "2025-10-24T03:11:54.252976Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "15\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_20251023.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\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": "2b52e655-f798-45bf-8d64-6c18ba490fc4", "metadata": {}, "source": [ "## 导入手工数据" ] }, { "cell_type": "code", "execution_count": 22, "id": "8249cc9b-e5e1-475b-891c-03075c74de91", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:11:57.248418Z", "iopub.status.busy": "2025-10-24T03:11:57.247688Z", "iopub.status.idle": "2025-10-24T03:11:57.267994Z", "shell.execute_reply": "2025-10-24T03:11:57.267091Z", "shell.execute_reply.started": "2025-10-24T03:11:57.248356Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/延庆区残联.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "filename = 'data/result_延庆区残联.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "for n in range(2, sheet.max_row+1):\n", " code = str(sheet.cell(n, 1).value)\n", " dict1[code].setdefault('bmi',{})\n", " dict1[code]['bmi']['成绩'] = sheet.cell(n,5).value\n", "filename = 'data/result_延庆区残联.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "6210fa76-1e82-40c1-8ec0-0f283e00b76f", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": 23, "id": "2c5d6b79-83ca-4d09-a312-e965c330b09b", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:12:38.674877Z", "iopub.status.busy": "2025-10-24T03:12:38.674120Z", "iopub.status.idle": "2025-10-24T03:12:38.682034Z", "shell.execute_reply": "2025-10-24T03:12:38.681602Z", "shell.execute_reply.started": "2025-10-24T03:12:38.674822Z" } }, "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": "b2347ea7-faca-4e54-8516-fb724f575c61", "metadata": {}, "source": [ "## 获取问卷人员信息" ] }, { "cell_type": "code", "execution_count": 24, "id": "c1317e6c-870f-42e2-8161-e101e43dcd3c", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:12:43.927986Z", "iopub.status.busy": "2025-10-24T03:12:43.927674Z", "iopub.status.idle": "2025-10-24T03:12:43.953550Z", "shell.execute_reply": "2025-10-24T03:12:43.952994Z", "shell.execute_reply.started": "2025-10-24T03:12:43.927961Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "209 ok\n" ] } ], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "dict1 = {}\n", "list1 = []\n", "filename = 'data/sql_20251023.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", "nn = 0\n", "for item in list1:\n", " dict2 = {}\n", " name = item[1]\n", " phone = str(item[2])[2:]\n", " birth = str(item[4])\n", " content = json.loads(item[0])\n", " tcm = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for k, v in content.items(): \n", " if 'tcm' not in k:\n", " dict2[k] = v\n", " else:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " \n", " code = phone\n", " dict1.setdefault(code,{})\n", " dict1[code]['name'] = dict2['name']\n", " if dict2['gender'] == 'm':\n", " dict1[code]['sex'] = '男'\n", " else:\n", " dict1[code]['sex'] = '女'\n", " dict1[code]['birth'] = str(item[4])\n", " \n", " \n", " dict1[code]['tcm'] = tcm\n", "filename = 'data/survey_延庆区残联.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(len(dict1),'ok')" ] }, { "cell_type": "markdown", "id": "b4ad071e-286a-4516-9098-cd7f657cb403", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": 25, "id": "b4a2d6e5-5954-43c0-b744-f8e4a94b3447", "metadata": { "execution": { "iopub.execute_input": "2025-10-24T03:12:46.927452Z", "iopub.status.busy": "2025-10-24T03:12:46.927194Z", "iopub.status.idle": "2025-10-24T03:12:46.935712Z", "shell.execute_reply": "2025-10-24T03:12:46.935211Z", "shell.execute_reply.started": "2025-10-24T03:12:46.927431Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok!\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "filename = 'data/survey_延庆区残联.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/result_延庆区残联.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "for k, v in dict2.items():\n", " phone = str(v['phone'])\n", " if phone in dict1.keys():\n", " dict2[k]['tcm'] = dict1[phone]['tcm']\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": "code", "execution_count": null, "id": "1168c2a9-128a-4252-8ab9-961eae0c0500", "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 }