From 462f74a745cedbc2e0630baa9ce1af0077a3e8df Mon Sep 17 00:00:00 2001 From: 512song Date: Sat, 15 Mar 2025 20:12:08 +0800 Subject: [PATCH] 20250315 --- 体测单位/my_module.py | 93 +++++++++++- 体测单位/延庆.ipynb | 338 +++++++++++++++++++++++------------------- 2 files changed, 278 insertions(+), 153 deletions(-) diff --git a/体测单位/my_module.py b/体测单位/my_module.py index 3139f4a..13f3d8a 100644 --- a/体测单位/my_module.py +++ b/体测单位/my_module.py @@ -3,6 +3,8 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) import json import time +from datetime import date +import csv filename = 'data/体质检测标准 (1).json' with open(filename,'r') as fl: @@ -66,4 +68,93 @@ def cal_bmi(data1): score = 3 elif weight > mx[3]: score = 1 - return score \ No newline at end of file + return score + +def get_wenjuan(list1,phone,dict1,dict3): + + nn = 0 + for item in list1: + if item[2] in phone.keys(): + psy =[] + tcm = [] + spine = [] + for i in range(0,30): + psy.append(0) + for i in range(0,60): + tcm.append(0) + for i in range(0,26): + spine.append(0) + + content = json.loads(item[5]) + if phone[item[2]] not in dict1.keys(): + dict1[phone[item[2]]] = dict3[phone[item[2]]] + rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0]) + dict1[phone[item[2]]]['rq'] = item[6].replace('/','-').split(' ')[0] + else: + rq = dict1[phone[item[2]]]['rq'].replace('/','-').split(' ')[0] + for k, v in content.items(): + if 'psyOld' in k: + i = int(k[6:]) + psy[i-1] = int(v) + if 'tcm' in k: + i = int(k[3:]) + tcm[i-1] = int(v) + if 'spine' in k: + i = int(k[5:]) + spine[i-1] = int(v) + if 'psyOld' in item[5]: + dict1[phone[item[2]]]['psy_yangmiao_old'] = psy + if 'tcm' in item[5]: + + dict1[phone[item[2]]]['tcm'] = tcm + if 'spine' in item[5]: + for ii in range(25,23,-1): + spine[ii] = spine[ii-1] + spine[22] = 0 + dict1[phone[item[2]]]['spine'] = spine + birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-')) + rq = date.fromisoformat(dict1[phone[item[2]]]['rq'].replace('/','-')) + days = (rq-birth).days + dict1[phone[item[2]]]['age'] = int(days/365) + dict1[phone[item[2]]]['month'] = int(days/365*12) + nn+=1 + data1 = [dict1,nn] + return(data1) + +def get_result(filename,dict1): + re_ta = {} + list1 = [] + with open(filename,'r',newline='') as csv_file: + fl = csv.reader(csv_file,delimiter=',') + header = next(fl) + for line in fl: + #line = re.sub('[\r\n\f ]{1,}', '', line) + list1.append(line) + + for result in list1: + user = str(result[2]) + rq = date.fromisoformat(result[5].replace('/','-')) + if user in dict1.keys(): + l_xm = [] + m_item = str(result[3]) + re_ta.setdefault(user,{}) + re_ta[user]['name'] = dict1[user]['name'] + re_ta[user]['sex'] = dict1[user]['sex'] + if 'phone' in dict1[user].keys(): + re_ta[user]['phone'] = dict1[user]['phone'] + if dict1[user]['sex'] == '男': + l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step'] + else: + l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp'] + #re_ta[user]['unit'] = dict1[user]['unit'] + birth = date.fromisoformat(dict1[user]['birth'].replace('/','-')) + item_name = result[3] + if item_name in l_xm: + days = (rq-birth).days + re_ta[user]['age'] = int(days/365) + re_ta[user]['month'] = int(days/365*12) + re_ta[user]['rq'] = result[5] + re_ta[user].setdefault(item_name,{}) + score = result[4] + re_ta[user][item_name]['成绩'] = score + return(re_ta) \ No newline at end of file diff --git a/体测单位/延庆.ipynb b/体测单位/延庆.ipynb index 1480754..017c359 100644 --- a/体测单位/延庆.ipynb +++ b/体测单位/延庆.ipynb @@ -10,15 +10,15 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 5, "id": "3d5ddc7a-a331-438d-aa8d-1ad74c7250d0", "metadata": { "execution": { - "iopub.execute_input": "2025-03-11T12:15:27.766643Z", - "iopub.status.busy": "2025-03-11T12:15:27.765962Z", - "iopub.status.idle": "2025-03-11T12:15:27.793362Z", - "shell.execute_reply": "2025-03-11T12:15:27.792793Z", - "shell.execute_reply.started": "2025-03-11T12:15:27.766564Z" + "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": [ @@ -47,7 +47,7 @@ " 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'] = sheet.cell(n, 5).value\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", @@ -65,15 +65,15 @@ }, { "cell_type": "code", - "execution_count": 30, - "id": "72ec680f-ec0d-44f9-919c-17c8e614b885", + "execution_count": 1, + "id": "36aa14f9-cdfd-4ad4-a84e-9809c9db9958", "metadata": { "execution": { - "iopub.execute_input": "2025-03-11T12:15:59.585308Z", - "iopub.status.busy": "2025-03-11T12:15:59.584674Z", - "iopub.status.idle": "2025-03-11T12:15:59.596989Z", - "shell.execute_reply": "2025-03-11T12:15:59.595883Z", - "shell.execute_reply.started": "2025-03-11T12:15:59.585249Z" + "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": [ @@ -81,7 +81,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "3\n" + "14\n" ] } ], @@ -90,48 +90,13 @@ "import datetime\n", "import csv\n", "from datetime import date\n", + "import my_module as My\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_20250311.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", + "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", @@ -149,15 +114,15 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 7, "id": "8f459ed3-fc14-404f-998b-5ed2a15958c3", "metadata": { "execution": { - "iopub.execute_input": "2025-03-11T12:16:02.677677Z", - "iopub.status.busy": "2025-03-11T12:16:02.677141Z", - "iopub.status.idle": "2025-03-11T12:16:02.688486Z", - "shell.execute_reply": "2025-03-11T12:16:02.687588Z", - "shell.execute_reply.started": "2025-03-11T12:16:02.677626Z" + "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": [ @@ -205,98 +170,6 @@ "print('ok!') " ] }, - { - "cell_type": "markdown", - "id": "f86b0f59-c1f6-4523-aefd-854f04305ec9", - "metadata": {}, - "source": [ - "## 生成报告" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "9e843585-fef3-4f5c-baae-76e711f2a42f", - "metadata": { - "execution": { - "iopub.execute_input": "2025-03-11T12:16:06.507493Z", - "iopub.status.busy": "2025-03-11T12:16:06.506739Z", - "iopub.status.idle": "2025-03-11T12:16:08.382833Z", - "shell.execute_reply": "2025-03-11T12:16:08.381828Z", - "shell.execute_reply.started": "2025-03-11T12:16:06.507425Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\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(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": "markdown", "id": "582e988f-3226-4209-a348-60be2a7750a1", @@ -443,10 +316,171 @@ "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": "4caa7845-9391-4c32-8b34-932d0d5e395b", + "id": "7143c16b-6e45-4a10-a04c-6b90631ddfb0", "metadata": {}, "outputs": [], "source": []