This commit is contained in:
512song@sina.com committed 2022-12-15 09:13:59 +08:00
1 parent 2043c814a1
commit a039732d62
1 file changed
+351
+351
View File
@@ -0,0 +1,351 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "19280f5c-8e34-4a64-8dfb-6353cbf597d2",
"metadata": {},
"source": [
"# 体质检测数据处理"
]
},
{
"cell_type": "markdown",
"id": "112d80f4-607b-41f9-bb30-ac2eb8f52ee2",
"metadata": {},
"source": [
"## 基础数据管理"
]
},
{
"cell_type": "markdown",
"id": "b7dfd50f-a614-497d-8f0a-fa1e4c89168a",
"metadata": {},
"source": [
"### 体测项目标准导入"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "8cd73044-56a8-409b-a873-085feb63af17",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-11T04:12:38.717398Z",
"iopub.status.busy": "2022-12-11T04:12:38.716743Z",
"iopub.status.idle": "2022-12-11T04:12:38.819382Z",
"shell.execute_reply": "2022-12-11T04:12:38.818678Z",
"shell.execute_reply.started": "2022-12-11T04:12:38.717334Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"tcbz ={\n",
" 'HeightWeigh':'身高体重',\n",
" 'StepExperiment':'台阶指数',\n",
" 'Lung':'肺活量',\n",
" 'Proneness':'坐位体前屈',\n",
" 'PowerfullGrip':'握力',\n",
" 'OneMinutePushUp':'一分钟仰卧起坐',\n",
" 'PushUp':'俯卧撑',\n",
" 'VerticalJump':'纵跳',\n",
" 'ReactionTime':'选择反应时',\n",
" 'FootStand':'单脚站立'\n",
"}\n",
"wb = openpyxl.load_workbook('data/体质检测标准.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"dict1 = {}\n",
"dict3 = {}\n",
"for k, v in tcbz.items():\n",
" dict3[v] = k\n",
"sheet = wb.active\n",
"data1 =list(sheet.values)\n",
"del data1[0]\n",
"for item in data1:\n",
" sex = item[0][6:]\n",
" if sex =='男':\n",
" age_sex = 'M'+item[0][:5]\n",
" else:\n",
" age_sex = 'F'+item[0][:5]\n",
" dict1.setdefault(age_sex,{})\n",
" if item[1] in dict3.keys():\n",
" xm = dict3[item[1]]\n",
" dict1[age_sex].setdefault(xm,[])\n",
" dict1[age_sex][xm].append(item[3]/item[4])\n",
"dict2 = {}\n",
"#print(dict1)\n",
"for k, v in dict1.items():\n",
" i1 = int(k[1:3])\n",
" i2 = int(k[-2:])\n",
" m_sex = k[:1]\n",
" for i in range(i1,i2+1):\n",
" dict2[m_sex+str(i)] = k\n",
"dict3 = {}\n",
"dict3['person'] = dict2\n",
"dict3['criteria'] = dict1\n",
"filename = 'data/体质检测标准.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict3, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "c36641d8-c54b-43d2-ad9d-ff4cb72deba9",
"metadata": {},
"source": [
"### 身高标准导入"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "2ca52d7b-d77e-452f-98f6-95072a5a1934",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-11T08:20:52.050056Z",
"iopub.status.busy": "2022-12-11T08:20:52.049496Z",
"iopub.status.idle": "2022-12-11T08:20:52.311023Z",
"shell.execute_reply": "2022-12-11T08:20:52.310420Z",
"shell.execute_reply.started": "2022-12-11T08:20:52.049977Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"tcbz ={\n",
" 'HeightWeigh':'身高体重',\n",
" 'StepExperiment':'台阶指数',\n",
" 'Lung':'肺活量',\n",
" 'Proneness':'坐位体前屈',\n",
" 'PowerfullGrip':'握力',\n",
" 'OneMinutePushUp':'一分钟仰卧起坐',\n",
" 'PushUp':'俯卧撑',\n",
" 'VerticalJump':'纵跳',\n",
" 'ReactionTime':'选择反应时',\n",
" 'FootStand':'单脚站立'\n",
"}\n",
"wb = openpyxl.load_workbook('data/体质检测标准_BMI.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"dict1 = {}\n",
"dict3 = {}\n",
"for k, v in tcbz.items():\n",
" dict3[v] = k\n",
"sheet = wb.active\n",
"data1 =list(sheet.values)\n",
"del data1[0]\n",
"for item in data1:\n",
" min_age = int(item[1]/12)\n",
" max_age = int((item[2]+1)/12) - 1\n",
" sex = item[0]\n",
" height = int(item[3])\n",
" if sex ==0:\n",
" age_sex = 'M'+str(min_age)+'~'+str(max_age)\n",
" else:\n",
" age_sex = 'F'+str(min_age)+'~'+str(max_age)\n",
" dict1.setdefault(age_sex,{})\n",
" \n",
" dict1[age_sex].setdefault(height,[])\n",
" dict1[age_sex][height].append(item[5]/1000)\n",
"dict2 = {}\n",
"#print(dict1)\n",
"for k, v in dict1.items():\n",
" i1 = int(k[1:3])\n",
" i2 = int(k[-2:])\n",
" m_sex = k[:1]\n",
" for i in range(i1,i2+1):\n",
" dict2[m_sex+str(i)] = k\n",
"dict3 = {}\n",
"dict3['person'] = dict2\n",
"dict3['criteria'] = dict1\n",
"filename = 'data/体质检测标准_BMI.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict3, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "59f5708d-c2d0-4470-b2f4-b9face431865",
"metadata": {},
"source": [
"### 计算分数"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "f32b266a-7e46-4703-ab61-7cbbc81b5ab1",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-11T05:22:41.852604Z",
"iopub.status.busy": "2022-12-11T05:22:41.852315Z",
"iopub.status.idle": "2022-12-11T05:22:41.865812Z",
"shell.execute_reply": "2022-12-11T05:22:41.864367Z",
"shell.execute_reply.started": "2022-12-11T05:22:41.852578Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[25.9, 31.5, 38.6, 44.0, 50.8]\n",
"25.9\n",
"0\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = 'data/体质检测标准.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"person = dict1['person']\n",
"criteria = dict1['criteria']\n",
"data = {'name':'张三','sex':'M','age':59,'item':'PowerfullGrip','result':12.0}\n",
"info = data['sex']+str(data['age'])\n",
"bz = person[info]\n",
"mx = criteria[bz][data['item']]\n",
"result = data['result']\n",
"score = -1\n",
"print(mx)\n",
"for bz1 in mx:\n",
" if result < bz1:\n",
" print(bz1)\n",
" score = mx.index(bz1,0)\n",
" break\n",
"if score == -1:\n",
" score = 5\n",
"print(score)"
]
},
{
"cell_type": "markdown",
"id": "755f8b66-c71c-4138-bd12-dff24e85e36a",
"metadata": {},
"source": [
"### 计算BMI分数"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "b32fbbdd-eb0a-4f0d-8901-e39a727c3ff8",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-11T08:42:02.334236Z",
"iopub.status.busy": "2022-12-11T08:42:02.333952Z",
"iopub.status.idle": "2022-12-11T08:42:02.357384Z",
"shell.execute_reply": "2022-12-11T08:42:02.355513Z",
"shell.execute_reply.started": "2022-12-11T08:42:02.334210Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"M50~59\n",
"175.5,90.2\n",
"1\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = 'data/体质检测标准_BMI.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"person = dict1['person']\n",
"criteria = dict1['criteria']\n",
"data = {'name':'张三','sex':'M','age':59,'item':'HeightWeight','result':'175.5,90.2'}\n",
"info = data['sex']+str(data['age'])\n",
"\n",
"bz = person[info]\n",
"print(bz)\n",
"result = data['result']\n",
"print(result)\n",
"height = int(float(result.split(',')[0]))\n",
"weight = float(result.split(',')[1])\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",
"print(score)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5167ef1b-8ea5-4079-9468-33ec52f2317e",
"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.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}