From 3ecb5dc566d93cefad858702e6524dbb7e6b89f1 Mon Sep 17 00:00:00 2001 From: 512song Date: Fri, 15 Mar 2024 19:49:24 +0800 Subject: [PATCH] 20240315 --- 体测单位/体质检测数据处理.ipynb | 167 ++++++++++++++++++++++++++++++-- 1 file changed, 157 insertions(+), 10 deletions(-) diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index 92d856c..1714132 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -538,6 +538,153 @@ "print('ok!') " ] }, + { + "cell_type": "code", + "execution_count": 101, + "id": "30c4c256-a75d-40dd-b9cf-e3102fd4ab5a", + "metadata": { + "execution": { + "iopub.execute_input": "2024-03-15T11:30:51.926110Z", + "iopub.status.busy": "2024-03-15T11:30:51.925642Z", + "iopub.status.idle": "2024-03-15T11:30:51.956746Z", + "shell.execute_reply": "2024-03-15T11:30:51.955818Z", + "shell.execute_reply.started": "2024-03-15T11:30:51.926073Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok!\n" + ] + } + ], + "source": [ + "import json\n", + "import time\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl) \n", + "for k,v in dict3.items():\n", + " item[k] = v\n", + "item['1']['en'] = 'lung'\n", + "item['2']['en'] = 'grip'\n", + "item['3']['en'] = 'flexion'\n", + "item['4']['en'] = 'jump'\n", + "item['5']['en'] = 'pushup'\n", + "item['6']['en'] = 'balance'\n", + "item['7']['en'] = 'reaction'\n", + "item['8']['en'] = 'step'\n", + "item['9']['en'] = 'situp'\n", + "item['10']['en'] = 'height'\n", + "item['11']['en'] = 'weight'\n", + "\n", + "filename = 'data/体质检测标准 (1).json' \n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "\n", + "\n", + "def cal_score(data1):\n", + " #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n", + " person = dict1['person']\n", + " criteria = dict1['criteria']\n", + " if data1['age'] >59:\n", + " data1['age'] = 59\n", + " if data1['age'] <20:\n", + " data1['age'] = 20\n", + " info = data1['sex']+str(data1['age'])\n", + " bz = person[info]\n", + " mx = criteria[bz][data1['item']]\n", + " result = data1['result'] \n", + " if data1['item'] == 'reaction':\n", + " for bz1 in mx:\n", + " if result > bz1:\n", + " #print(bz1)\n", + " score = mx.index(bz1,0)\n", + " break\n", + " else:\n", + " score = 5\n", + " else:\n", + " for bz1 in mx:\n", + " if result < bz1:\n", + " #print(bz1)\n", + " score = mx.index(bz1,0)\n", + " break\n", + " else:\n", + " score = 5\n", + " return(score)\n", + "filename = 'data/体质检测标准_BMI.json'\n", + "with open(filename,'r') as fl:\n", + " dict4 = json.load(fl) \n", + " \n", + "def cal_bmi(data1):\n", + " # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n", + " person = dict4['person']\n", + " criteria = dict4['criteria']\n", + " if data1['age'] > 59:\n", + " data1['age'] = 59\n", + " if data1['age'] <20:\n", + " data1['age'] = 20\n", + " info = data1['sex']+str(data1['age'])\n", + " bz = person[info]\n", + " #print(bz)\n", + " result = data1['result']\n", + " #print(data1['code'],result)\n", + " height = int(float(result.split(',')[0]))\n", + " weight = float(result.split(',')[1])\n", + " if str(height) not in criteria[bz]:\n", + " score = 1\n", + " else: \n", + " mx = criteria[bz][str(height)]\n", + " if weight < mx[0]:\n", + " score = 1\n", + " elif weight < mx[1]:\n", + " score = 3\n", + " elif weight < mx[2]:\n", + " score = 5 \n", + " elif weight <= mx[3]:\n", + " score = 3 \n", + " elif weight > mx[3]:\n", + " score = 1\n", + " return score\n", + " \n", + " \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 'height' in v.keys() and 'weight' in v.keys():\n", + " bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\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'] = 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", + " dict2[k][item_en]['score'] = 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": "ceef0742-f62a-4a7d-b0d5-be7ae7abb741", @@ -548,15 +695,15 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 102, "id": "b123ee6b-85d2-4660-b226-321832a6b796", "metadata": { "execution": { - "iopub.execute_input": "2024-01-03T15:42:44.653385Z", - "iopub.status.busy": "2024-01-03T15:42:44.652940Z", - "iopub.status.idle": "2024-01-03T15:42:59.566347Z", - "shell.execute_reply": "2024-01-03T15:42:59.565824Z", - "shell.execute_reply.started": "2024-01-03T15:42:44.653349Z" + "iopub.execute_input": "2024-03-15T11:34:16.320686Z", + "iopub.status.busy": "2024-03-15T11:34:16.320229Z", + "iopub.status.idle": "2024-03-15T11:34:17.378622Z", + "shell.execute_reply": "2024-03-15T11:34:17.378123Z", + "shell.execute_reply.started": "2024-03-15T11:34:16.320649Z" }, "tags": [] }, @@ -565,7 +712,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "43\n" + "2\n" ] } ], @@ -578,11 +725,11 @@ "headers = {\n", " \"Content-Type\": \"application/json; charset=UTF-8\"\n", " }\n", - "filename = 'data/result_中国石化化工销售.json'\n", + "filename = 'data/result_样本.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", - "fiie_path ='./中国石化化工销售/'\n", + "fiie_path ='./样本/'\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", "i=0\n", "list2 = []\n", @@ -592,7 +739,7 @@ " \n", " id = str(k).rjust(4,\"0\")\n", " mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n", - " mydata['title'] = '中国石化化工销售'\n", + " mydata['title'] = '体质监测报告样本'\n", " mydata['subtitle'] = v['unit']\n", " mydata['id'] = id\n", " mydata['name'] = v['name']\n",