Files
jupyter/体测单位/西藏.ipynb
T
2023-07-12 16:54:09 +08:00

1168 lines
35 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "70c15816-2ad5-4486-be33-378963d70934",
"metadata": {},
"source": [
"## 人员信息导入"
]
},
{
"cell_type": "code",
"execution_count": 94,
"id": "07f7e97e-670e-4301-b83d-1304514f15d5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:10.229928Z",
"iopub.status.busy": "2023-07-05T02:45:10.229085Z",
"iopub.status.idle": "2023-07-05T02:45:10.320665Z",
"shell.execute_reply": "2023-07-05T02:45:10.319936Z",
"shell.execute_reply.started": "2023-07-05T02:45:10.229888Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/xizang.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = int(sheet.cell(n, 5).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 1).value\n",
" if sheet.cell(n, 2).value ==0:\n",
" sex = '男'\n",
" else:\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" birth = str(sheet.cell(n, 3).value).split()[0]\n",
" dict1['birth'] = birth\n",
" \n",
" if sheet.cell(n,5).value is not None:\n",
" dict1['phone'] = str(sheet.cell(n, 4).value) \n",
" person[code] = dict1\n",
"\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": "962f6edd-c8d1-42a2-aaff-58f92ccf8d56",
"metadata": {},
"source": [
"## 问卷人员信息导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80d51661-e306-477a-84e8-8b9daf9cdb21",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import datetime\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",
" if sheet.cell(n,7).value is not None and sheet.cell(n,4).value is not None:\n",
" bh = int(sheet.cell(n, 7).value)\n",
" person.setdefault(bh, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['code'] = sheet.cell(n, 1).value\n",
" if sheet.cell(n, 3).value ==1:\n",
" sex = '男'\n",
" else:\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" birth = str(sheet.cell(n, 4).value).split()[0]\n",
" \n",
" if len(birth) == 2:\n",
" dict1['age'] = int(birth)\n",
" else:\n",
" birth.replace('/','-')\n",
" \n",
" birth = birth.split('-') \n",
" nian = int(birth[0].strip())\n",
" yue = int(birth[1].strip())\n",
" ri = int(birth[2].strip())\n",
" #print(k,nian,yue,ri)\n",
" days = (datetime.date(2023, 5, 31)-datetime.date(nian,yue,ri)).days\n",
" dict1['age'] = round(days/365)\n",
" if sheet.cell(n,5).value is not None:\n",
" dict1['phone'] = str(sheet.cell(n, 5).value) \n",
" person[bh] = dict1\n",
"\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": "25ffcc7a-5709-4377-b821-bce5097cbd78",
"metadata": {},
"source": [
"## 导入脊柱问卷信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "85599cf2-3673-4d3b-ae77-f5ef77217f71",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/西藏手工记录.xlsx')\n",
"sheet = wb['Sheet1']\n",
"\n",
"dict1 = {}\n",
"data1 =list(sheet.values)\n",
"list_bh = data1[0][1:]\n",
"del data1[0]\n",
"for i in range(1,len(list_bh)+1):\n",
" list2 = []\n",
" dict1.setdefault(int(list_bh[i-1]),{})\n",
" for item in data1:\n",
" list2.append(item[i])\n",
" dict1[int(list_bh[i-1])]['wenjuan'] = list2\n",
"print(dict1)\n",
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "56538b71-aedc-4880-b655-a814778bda07",
"metadata": {},
"source": [
"## 导入体测信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa2fe417-cd1d-47c1-bcf6-2e711d49af20",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/西藏手工记录.xlsx')\n",
"sheet = wb['Sheet2']\n",
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"data1 =list(sheet.values)\n",
"\n",
"for item in data1:\n",
" bh = str(item[0])\n",
" dict1.setdefault(bh,{})\n",
" xm = item[1]\n",
" result = item[2]\n",
" dict1[bh][xm] = result\n",
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "0a66d37f-6436-4e3c-abe1-d5fd4796e683",
"metadata": {},
"source": [
"## 导出手工信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59b31b70-2af4-40ba-af8c-e72354508c19",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"\n",
"filename = 'data/西藏手工问卷人员名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"for k, v in dict1.items():\n",
" s = ''\n",
" if k in dict2.keys():\n",
" if dict2[str(k)]['sex'] =='男':\n",
" sex = \"m\"\n",
" else:\n",
" sex = \"f\"\n",
" dict3 = {}\n",
" list_mx = []\n",
" name = dict2[str(k)]['name'] \n",
" list_mx.append(f'\"name\":\"{name}\"')\n",
" list_mx.append(f'\"Gender\":\"{sex}\"')\n",
" age = dict2[str(k)]['age']\n",
" list_mx.append(f'\"Age\":{age}')\n",
" dict3['surveyId'] = \"zsyxz1\"\n",
" dict3['name'] = dict2[str(k)]['name'] \n",
" code = dict2[str(k)]['code']\n",
" for item in v.keys():\n",
" if item == 'wenjuan':\n",
" for i in range(0,21):\n",
" if v[item][i] ==1:\n",
" result = 'ture'\n",
" else:\n",
" result ='false' \n",
" item_name = 'q'+str(i+1)\n",
" list_mx.append(f'\"{item_name}\":{result}')\n",
" for i in range(23,25):\n",
" if v[item][i] ==1:\n",
" result = 'ture'\n",
" else:\n",
" result ='false' \n",
" item_name = 'q'+str(i)\n",
" list_mx.append(f'\"{item_name}\":{result}')\n",
" if sex == 'f':\n",
" item_name = 'q25a'\n",
" if v[item][21] ==1:\n",
" result = 'ture'\n",
" else:\n",
" result ='false'\n",
" list_mx.append(f'\"{item_name}\":{result}')\n",
" else:\n",
" item_name = 'q22'\n",
" if v[item][22] ==1:\n",
" result = 'ture'\n",
" else:\n",
" result ='false'\n",
" list_mx.append(f'\"{item_name}\":{result}')\n",
" item_name = 'q25b'\n",
" if v[item][25] ==1:\n",
" result = 'ture'\n",
" else:\n",
" result ='false'\n",
" list_mx.append(f'\"{item_name}\":{result}')\n",
" else: \n",
" item_name = item \n",
" list_mx.append(f'\"{item_name}\":{v[item]}')\n",
" ss = ','.join(list_mx)\n",
" ss ='{'+ss+'}'\n",
" dict3['data'] = ss\n",
" sj = '2023-06-01 20:00:00'\n",
" s= s+f'(\"zsyxz1\",\"{name}\",\"{code}\",\\'{ss}\\',\"{sj}\"),'\n",
" print(s)"
]
},
{
"cell_type": "markdown",
"id": "3d7ab69c-941d-4f73-8708-2aab850ae2e1",
"metadata": {},
"source": [
"## 导入体测信息"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "e19a4c58-df1e-4136-bf10-33e9ed885e50",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-04T13:02:15.967924Z",
"iopub.status.busy": "2023-07-04T13:02:15.967138Z",
"iopub.status.idle": "2023-07-04T13:02:16.005279Z",
"shell.execute_reply": "2023-07-04T13:02:16.004236Z",
"shell.execute_reply.started": "2023-07-04T13:02:15.967883Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"165\n",
"165\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"filename = 'data/西藏人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20230704.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",
"#print(list1)\n",
"for result in list1:\n",
" user = str(result[2])\n",
" if user in dict1.keys(): \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",
" item_name = item[m_item]['name']\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[4])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
"print(len(re_ta))\n",
"filename = 'data/result_xizang.json'\n",
"\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": "52597677-83a0-447e-95b2-7e8c4296bec7",
"metadata": {},
"source": [
"## 报告更名"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a84f2536-9e03-442f-8931-53c9fdc57395",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import glob\n",
"from pathlib import Path\n",
"\n",
"fi_path = 'file/2023-06-06'\n",
"old = []\n",
"dict2 = {}\n",
"\n",
"filename = 'data/result_xizang.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"for k, v in dict1.items():\n",
" m_name = v['name']\n",
" dict2[int(k)] = [m_name]\n",
"\n",
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
"\n",
"for fn in fls:\n",
" old.append(os.path.basename(fn).split('.')[0])\n",
"\n",
"for n in old: \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" new_path = Path(fi_path,'new')\n",
" new_path.mkdir(parents = True, exist_ok = True)\n",
" n_name = Path(new_path,f'{str(n).rjust(5,\"0\")}-{dict2[int(n)][0]}.pdf')\n",
" if not os.path.exists(n_name):\n",
" shutil.copyfile(o_name,n_name)\n",
" print(n_name)\n",
" \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "682c45e3-2e07-4fb0-844c-c837b1a2602c",
"metadata": {},
"source": [
"## 数据分析"
]
},
{
"cell_type": "markdown",
"id": "8c8faef4-c0d1-441e-ab64-3b8223afa3bd",
"metadata": {},
"source": [
"### 获取清理后数据"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "3696d7e1-afb8-4f9d-ba29-9aaa977b52de",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:28.348666Z",
"iopub.status.busy": "2023-07-05T02:45:28.348242Z",
"iopub.status.idle": "2023-07-05T02:45:28.389486Z",
"shell.execute_reply": "2023-07-05T02:45:28.388452Z",
"shell.execute_reply.started": "2023-07-05T02:45:28.348638Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"165\n",
"[]\n",
"165\n",
"ok\n",
"165\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"filename = 'data/西藏人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"re_ta = {}\n",
"list1 = []\n",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/places_result_20230704.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",
"#print(list1)\n",
"for result in list1:\n",
" user = str(result[2])\n",
" if user in dict1.keys(): \n",
" m_item = str(result[3]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" \n",
" re_ta[user]['sex'] = dict1[user]['sex']\n",
" re_ta[user]['birth'] = dict1[user]['birth'].replace('-','/')\n",
" item_name = item[m_item]['name']\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[4])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" re_ta[user][item_name]['得分'] =result[5]\n",
"\n",
"print(len(re_ta))\n",
"liwai = []\n",
"for k, v in re_ta.items():\n",
" if (len(v)<8 and '身高' in v and '体重' in v) or (len(v)<7 and '身高' not in v and '体重' not in v) :\n",
" liwai.append(k)\n",
"print(liwai)\n",
"for k in liwai:\n",
" del re_ta[k]\n",
"print(len(re_ta))\n",
"filename = 'data/result_xizang.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')\n",
"print(len(re_ta))"
]
},
{
"cell_type": "markdown",
"id": "e9408f20-15cc-4827-bc34-f340f2e8b70f",
"metadata": {},
"source": [
"### 计算人员年龄"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "b71c8bf6-2530-425f-9516-8757b40e3dc5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:31.683237Z",
"iopub.status.busy": "2023-07-05T02:45:31.682418Z",
"iopub.status.idle": "2023-07-05T02:45:31.710877Z",
"shell.execute_reply": "2023-07-05T02:45:31.709811Z",
"shell.execute_reply.started": "2023-07-05T02:45:31.683198Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import datetime\n",
"\n",
"filename = 'data/result_xizang.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"for k, v in dict1.items(): \n",
" birth = v['birth'].split()[0].split('/') \n",
" nian = int(birth[0].strip())\n",
" yue = int(birth[1].strip())\n",
" ri = int(birth[2].strip())\n",
" #print(k,nian,yue,ri)\n",
" days = (datetime.date(2023, 6, 10)-datetime.date(nian,yue,ri)).days\n",
" v['age'] = int(days/365)\n",
"filename = 'data/result_xizang.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) \n",
"print('ok') "
]
},
{
"cell_type": "markdown",
"id": "36461621-bd49-4eac-b055-9c421604d5fe",
"metadata": {},
"source": [
"### 汇总人员信息及成绩"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "0e75cfbb-2b63-4163-831c-933fff1481c2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:50.311946Z",
"iopub.status.busy": "2023-07-05T02:45:50.311092Z",
"iopub.status.idle": "2023-07-05T02:45:50.340231Z",
"shell.execute_reply": "2023-07-05T02:45:50.339150Z",
"shell.execute_reply.started": "2023-07-05T02:45:50.311906Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"\n",
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" score = 0\n",
" i = 0 \n",
" for k1,v1 in v.items(): \n",
" if k1 in items:\n",
" score = score + int(v1['得分'])\n",
" i+=1\n",
" dict1[k]['score'] = round(score/i,2) \n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "eb2b6efa-206a-4afe-8380-86970162b519",
"metadata": {},
"source": [
"### 计算测试等级"
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "99f02e37-3a03-4d7d-a2b9-7bf5563c253c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:52.771879Z",
"iopub.status.busy": "2023-07-05T02:45:52.771043Z",
"iopub.status.idle": "2023-07-05T02:45:52.802079Z",
"shell.execute_reply": "2023-07-05T02:45:52.801054Z",
"shell.execute_reply.started": "2023-07-05T02:45:52.771839Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0~255分人数:115人,男性:67人,女性:48人\n",
"256~332分人数:42人,男性:27人,女性:15人\n",
"333~367分人数:8人,男性:4人,女性:4人\n",
"368~500分人数:0人,男性:0人,女性:0人\n",
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"dict2['不合格'] = [0,255]\n",
"dict2['合格'] = [256,332]\n",
"dict2['良好'] = [333,367]\n",
"dict2['优秀'] = [368,500]\n",
"\n",
"for k1, v1 in dict2.items():\n",
" di = v1[0]\n",
" gao = v1[1]\n",
" i = 0 \n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if int(v['score']*100) in range(di,gao+1):\n",
" dict1[k]['level'] = k1\n",
" i+=1\n",
" if v['sex'] == '男':\n",
" m = m +1\n",
" else:\n",
" f = f+1\n",
" print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "386c1365-81e1-40a5-bcb1-c63b5ab7b52f",
"metadata": {},
"source": [
"### 根据年龄汇总人员信息及成绩"
]
},
{
"cell_type": "code",
"execution_count": 99,
"id": "1435c8af-094d-44b3-a024-af3615c07c21",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:45:57.071802Z",
"iopub.status.busy": "2023-07-05T02:45:57.070977Z",
"iopub.status.idle": "2023-07-05T02:45:57.086551Z",
"shell.execute_reply": "2023-07-05T02:45:57.085522Z",
"shell.execute_reply.started": "2023-07-05T02:45:57.071762Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.43分,人数:9人,男性:7人\n",
"25~29岁平均成绩:2.14分,人数:49人,男性:27人\n",
"30~34岁平均成绩:2.26分,人数:38人,男性:22人\n",
"35~39岁平均成绩:2.39分,人数:27人,男性:12人\n",
"40~44岁平均成绩:2.37分,人数:26人,男性:15人\n",
"45~49岁平均成绩:2.52分,人数:10人,男性:9人\n",
"50~54岁平均成绩:2.48分,人数:5人,男性:5人\n",
"55~69岁平均成绩:2.67分,人数:1人,男性:1人\n"
]
}
],
"source": [
"import json\n",
"\n",
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for item in nld:\n",
" di = item[0]\n",
" gao = item[1]\n",
" i = 0\n",
" score = 0\n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if v['age'] in range(di,gao+1):\n",
" score = score+v['score']\n",
" i+=1\n",
" if v['sex'] == '男':\n",
" m = m +1\n",
" \n",
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人,男性:{m}人')"
]
},
{
"cell_type": "markdown",
"id": "0119fb2f-417d-4753-b3da-fac2be8546e3",
"metadata": {},
"source": [
"#### 根据年龄汇总人员信息及成绩(男)"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "650cf1eb-8681-4911-9b04-80468fe6bf64",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:47:11.272824Z",
"iopub.status.busy": "2023-07-05T02:47:11.271965Z",
"iopub.status.idle": "2023-07-05T02:47:11.287782Z",
"shell.execute_reply": "2023-07-05T02:47:11.286539Z",
"shell.execute_reply.started": "2023-07-05T02:47:11.272783Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.45分,人数:7人\n",
"25~29岁平均成绩:2.0分,人数:27人\n",
"30~34岁平均成绩:2.39分,人数:22人\n",
"35~39岁平均成绩:2.36分,人数:12人\n",
"40~44岁平均成绩:2.53分,人数:15人\n",
"45~49岁平均成绩:2.54分,人数:9人\n",
"50~54岁平均成绩:2.48分,人数:5人\n",
"55~80岁平均成绩:2.67分,人数:1人\n"
]
}
],
"source": [
"import json\n",
"\n",
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for item in nld:\n",
" di = item[0]\n",
" gao = item[1]\n",
" i = 0\n",
" score = 0\n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if v['age'] in range(di,gao+1) and v['sex'] == '男':\n",
" score = score+v['score']\n",
" i+=1\n",
" if i >0:\n",
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')\n",
" else:\n",
" print(f'{di}~{gao}岁平均成绩:0分,人数:0人') "
]
},
{
"cell_type": "markdown",
"id": "9a7d06f0-32e4-4148-93f8-a81abfcd81a6",
"metadata": {},
"source": [
"#### 根据年龄汇总人员信息及成绩(女)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "9ccb9b3c-de57-49f4-a4c6-10a24737e857",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-04T13:08:22.477549Z",
"iopub.status.busy": "2023-07-04T13:08:22.476783Z",
"iopub.status.idle": "2023-07-04T13:08:22.492628Z",
"shell.execute_reply": "2023-07-04T13:08:22.491401Z",
"shell.execute_reply.started": "2023-07-04T13:08:22.477510Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.33分,人数:2人\n",
"25~29岁平均成绩:2.32分,人数:22人\n",
"30~34岁平均成绩:2.07分,人数:16人\n",
"35~39岁平均成绩:2.41分,人数:15人\n",
"40~44岁平均成绩:2.15分,人数:11人\n",
"45~49岁平均成绩:2.33分,人数:1人\n",
"50~54岁平均成绩:0分,人数:0人\n",
"55~80岁平均成绩:0分,人数:0人\n"
]
}
],
"source": [
"import json\n",
"\n",
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for item in nld:\n",
" di = item[0]\n",
" gao = item[1]\n",
" i = 0\n",
" score = 0\n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if v['age'] in range(di,gao+1) and v['sex'] == '女':\n",
" score = score+v['score']\n",
" i+=1\n",
" if i >0:\n",
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')\n",
" else:\n",
" print(f'{di}~{gao}岁平均成绩:0分,人数:0人') "
]
},
{
"cell_type": "markdown",
"id": "90f534af-f370-4184-922a-a4a0444f59c3",
"metadata": {},
"source": [
"### 计算平均成绩"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "c8cd897e-0d41-4faa-860f-395d42208674",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T03:18:05.849161Z",
"iopub.status.busy": "2023-07-05T03:18:05.848313Z",
"iopub.status.idle": "2023-07-05T03:18:05.864430Z",
"shell.execute_reply": "2023-07-05T03:18:05.863382Z",
"shell.execute_reply.started": "2023-07-05T03:18:05.849120Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"平均成绩:2.3266分,男性:98人\n",
"平均成绩:2.2533分,女性:67人\n",
"平均成绩:2.2968分,总体:165人\n"
]
}
],
"source": [
"import json\n",
"\n",
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
"#filename = 'data/result_石家庄.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"i = 1\n",
"m = 0\n",
"f = 0\n",
"score = 0\n",
"t_score = 0\n",
"for k,v in dict1.items():\n",
" if v['sex'] == '男':\n",
" m = m +1\n",
" score = score+v['score']\n",
"print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')\n",
"t_score = t_score + score\n",
"score = 0\n",
"for k,v in dict1.items():\n",
" if v['sex'] == '女':\n",
" f = f +1\n",
" score = score+v['score']\n",
"print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n",
"t_score = t_score + score\n",
"print(f'平均成绩:{round(t_score/165,4)}分,总体:165人')"
]
},
{
"cell_type": "markdown",
"id": "c09369b2-0a21-4a61-b3c8-681906f74250",
"metadata": {},
"source": [
"### 计算各年龄段测试等级(女)"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "28b418f2-2324-450f-9684-4df15e012694",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:43:38.489757Z",
"iopub.status.busy": "2023-07-05T02:43:38.488929Z",
"iopub.status.idle": "2023-07-05T02:43:38.506679Z",
"shell.execute_reply": "2023-07-05T02:43:38.505448Z",
"shell.execute_reply.started": "2023-07-05T02:43:38.489716Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20-24 {'合格': 1, '不合格': 1}\n",
"25-29 {'良好': 2, '不合格': 15, '合格': 5}\n",
"30-34 {'合格': 3, '不合格': 12, '良好': 1}\n",
"35-39 {'合格': 4, '良好': 1, '不合格': 10}\n",
"40-44 {'不合格': 9, '良好': 0, '合格': 2}\n",
"45-49 {'不合格': 1, '合格': 0, '良好': 0}\n",
"50-54 {'合格': 0, '良好': 0, '不合格': 0}\n",
"55-80 {'合格': 0}\n"
]
}
],
"source": [
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"dict2['不合格'] = [0,255]\n",
"dict2['合格'] = [256,332]\n",
"dict2['良好'] = [333,367]\n",
"dict2['优秀'] = [368,500]\n",
"dict3 = {}\n",
"for item in nld:\n",
" di = item[0]\n",
" gao = item[1]\n",
" age = f'{di}-{gao}'\n",
" dict3.setdefault(age,{})\n",
" i = 0 \n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if v['age'] in range(di,gao+1): \n",
" dict3[age].setdefault(v['level'],0)\n",
" if v['sex'] == '女':\n",
" dict3[age][v['level']] = dict3[age][v['level']]+1\n",
" \n",
"for k, v in dict3.items():\n",
" print(k,v)"
]
},
{
"cell_type": "markdown",
"id": "40a7d9fb-cb74-4747-b6fe-9f8bc235d620",
"metadata": {},
"source": [
"### 计算各年龄段测试等级(男)"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "a80224fb-1726-4370-9d3d-6e0a27afa8b2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:47:19.469192Z",
"iopub.status.busy": "2023-07-05T02:47:19.468357Z",
"iopub.status.idle": "2023-07-05T02:47:19.486494Z",
"shell.execute_reply": "2023-07-05T02:47:19.485227Z",
"shell.execute_reply.started": "2023-07-05T02:47:19.469153Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20-24 {'合格': 3, '不合格': 4}\n",
"25-29 {'良好': 0, '不合格': 24, '合格': 3}\n",
"30-34 {'合格': 7, '不合格': 15, '良好': 0}\n",
"35-39 {'合格': 5, '良好': 0, '不合格': 7}\n",
"40-44 {'不合格': 9, '良好': 1, '合格': 5}\n",
"45-49 {'不合格': 5, '合格': 2, '良好': 2}\n",
"50-54 {'合格': 1, '良好': 1, '不合格': 3}\n",
"55-80 {'合格': 1}\n"
]
}
],
"source": [
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"dict2 = {}\n",
"dict2['不合格'] = [0,255]\n",
"dict2['合格'] = [256,332]\n",
"dict2['良好'] = [333,367]\n",
"dict2['优秀'] = [368,500]\n",
"dict3 = {}\n",
"for item in nld:\n",
" di = item[0]\n",
" gao = item[1]\n",
" age = f'{di}-{gao}'\n",
" dict3.setdefault(age,{})\n",
" i = 0 \n",
" m = 0\n",
" f = 0\n",
" for k,v in dict1.items():\n",
" if v['age'] in range(di,gao+1): \n",
" dict3[age].setdefault(v['level'],0)\n",
" if v['sex'] == '男':\n",
" dict3[age][v['level']] = dict3[age][v['level']]+1\n",
" \n",
"for k, v in dict3.items():\n",
" print(k,v)"
]
},
{
"cell_type": "markdown",
"id": "7870236d-dc80-4c36-ab24-d880155d376b",
"metadata": {},
"source": [
"### 计算各项目成绩"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "945b9bec-247b-498b-96f6-a52fabbf6c89",
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-05T02:47:22.379999Z",
"iopub.status.busy": "2023-07-05T02:47:22.379167Z",
"iopub.status.idle": "2023-07-05T02:47:22.392962Z",
"shell.execute_reply": "2023-07-05T02:47:22.391756Z",
"shell.execute_reply.started": "2023-07-05T02:47:22.379959Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"体重 3.46 164\n",
"肺活量 2.22 164\n",
"握力 1.19 164\n",
"坐位体前屈 1.9 163\n",
"单脚站立 2.19 165\n",
"选择反应时 2.8 165\n"
]
}
],
"source": [
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"items = ['体重','肺活量','握力','坐位体前屈','单脚站立','选择反应时']\n",
"for item in items:\n",
" score = 0\n",
" n = 0\n",
" for k, v in dict1.items():\n",
" if item in v.keys():\n",
" n = n + 1\n",
" score =score + int(v[item]['得分'])\n",
" print(item,round(score/n,2),n)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c840e9b2-ce95-40c5-9f67-438a88ae0736",
"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
}