This commit is contained in:
512song committed 2023-10-25 07:45:59 +00:00
1 parent 9b8fac651e
commit ceda991559
2 files changed
+917 -4

No files matched your search

+418 -3
View File
@@ -1,5 +1,17 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1c72f0cf-165b-4025-af9d-6771e4a0a5d1",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": [],
"toc-hr-collapsed": true
},
"source": [
"## 2022年体质检测"
]
},
{
"cell_type": "markdown",
"id": "61f4a6eb-797e-4fe2-95df-e27b316c95f1",
@@ -626,10 +638,413 @@
"wb.save(filename) "
]
},
{
"cell_type": "markdown",
"id": "c103301b-d540-4bf5-861a-0eb2e313e26e",
"metadata": {},
"source": [
"## 2023年体质检测"
]
},
{
"cell_type": "markdown",
"id": "1e3f67e9-e332-41c5-89f8-b64ec0bace4c",
"metadata": {},
"source": [
"### 人员信息汇总(批量人员)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "648d597d-2ac4-470c-9562-271e3e2863d6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:27:22.517401Z",
"iopub.status.busy": "2023-10-25T07:27:22.517103Z",
"iopub.status.idle": "2023-10-25T07:27:22.818722Z",
"shell.execute_reply": "2023-10-25T07:27:22.818086Z",
"shell.execute_reply.started": "2023-10-25T07:27:22.517373Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import glob\n",
"from pathlib import Path\n",
"import openpyxl\n",
"\n",
"fi_path = 'data/北海炼化/'\n",
"\n",
"fls = glob.glob(f'{fi_path}/*.xlsx')\n",
"i = 1\n",
"person = {}\n",
"for fl in fls:\n",
" wb = openpyxl.load_workbook(fl)\n",
" sheet = wb.active\n",
" # sheets = wb.sheetnames\n",
" \n",
"\n",
" for n in range(3,sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = str(i)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n,3 ).value\n",
" dict1['婚姻'] = sheet.cell(n, 5).value\n",
" dict1['phone'] = str(sheet.cell(n,6).value)\n",
" dict1['id'] = sheet.cell(n,7 ).value\n",
" dict1['总工龄'] = sheet.cell(n, 8).value\n",
" dict1['损害工龄'] = sheet.cell(n, 9).value\n",
" dict1['既往病史'] = sheet.cell(n,10 ).value\n",
" dict1['有毒因素'] = sheet.cell(n, 11).value\n",
" dict1['unit'] = sheet.cell(n, 12).value\n",
" dict1['工种'] = sheet.cell(n, 13).value\n",
" dict1['防护措施'] = sheet.cell(n,15 ).value \n",
" person[code] = dict1\n",
" i+=1\n",
" \n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "b1f47560-4183-4699-8d63-3d81a3ec002b",
"metadata": {},
"source": [
"### 检查身份证及手机号码唯一性"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "a2c1c315-c522-433a-9611-e08dca2445a9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:39:03.122723Z",
"iopub.status.busy": "2023-10-25T07:39:03.122416Z",
"iopub.status.idle": "2023-10-25T07:39:03.163768Z",
"shell.execute_reply": "2023-10-25T07:39:03.163068Z",
"shell.execute_reply.started": "2023-10-25T07:39:03.122696Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"董红军 18877976757\n",
"苗光浩 13927509537\n",
"440906199104060046 440906199104060046\n",
"黄仁进 13807799565\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"id= []\n",
"phone = [] \n",
"\n",
"for k, v in dict1.items():\n",
" if v['phone'] not in phone:\n",
" phone.append(v['phone'] )\n",
" else:\n",
" print(v['name'] ,v['phone'])\n",
" if v['id'] not in id:\n",
" id.append(v['id'] )\n",
" else:\n",
" print(v['id'] ,v['id'] )\n"
]
},
{
"cell_type": "markdown",
"id": "c1842f66-c81f-423d-bcda-0d49be82b32a",
"metadata": {},
"source": [
"### 查找身份证号码"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "7ba235d2-4638-4479-babb-2f9867c177c2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T06:41:49.969813Z",
"iopub.status.busy": "2023-10-25T06:41:49.969303Z",
"iopub.status.idle": "2023-10-25T06:41:49.984085Z",
"shell.execute_reply": "2023-10-25T06:41:49.982976Z",
"shell.execute_reply.started": "2023-10-25T06:41:49.969767Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"440906199104060046 凌倩\n",
"440906199104060046 陈继杨\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"id= '440906199104060046'\n",
"for k, v in dict1.items():\n",
" if v['id'] == id:\n",
" print(id,v['name'])"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "f9d8aafa-9a00-484a-a3c2-b3e9252b505d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:22:33.048929Z",
"iopub.status.busy": "2023-10-25T07:22:33.048318Z",
"iopub.status.idle": "2023-10-25T07:22:33.073020Z",
"shell.execute_reply": "2023-10-25T07:22:33.070785Z",
"shell.execute_reply.started": "2023-10-25T07:22:33.048870Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"18877976757 刘前程\n",
"13927509537 黄洁强\n",
"18877976757 董红军\n",
"13927509537 苗光浩\n",
"13807799565 谢昌俊\n",
"13807799565 黄仁进\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"phone= ['13807799565','18877976757','13927509537']\n",
"for k, v in dict1.items():\n",
" if v['phone'] in phone:\n",
" print(v['phone'],v['name'])"
]
},
{
"cell_type": "markdown",
"id": "1ea37f21-f03a-4450-8867-71fb8c3eeee7",
"metadata": {},
"source": [
"### 生成出生日期"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "dff13fe9-d5cd-45e3-a3e7-f47d12560699",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:39:16.409162Z",
"iopub.status.busy": "2023-10-25T07:39:16.408552Z",
"iopub.status.idle": "2023-10-25T07:39:16.466833Z",
"shell.execute_reply": "2023-10-25T07:39:16.465723Z",
"shell.execute_reply.started": "2023-10-25T07:39:16.409106Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"for k, v in dict1.items():\n",
" id = str(v['id']) \n",
" #print(id)\n",
" birth = id[6:10] + '-' +id[10:12] + '-' +id[12:14]\n",
" dict1[k]['birth'] = birth\n",
" \n",
" \n",
"filename = 'data/北海炼化2023.json' \n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "de060103-776c-40d8-9704-ece6cc574308",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T06:22:41.417620Z",
"iopub.status.busy": "2023-10-25T06:22:41.417111Z",
"iopub.status.idle": "2023-10-25T06:22:41.439732Z",
"shell.execute_reply": "2023-10-25T06:22:41.437319Z",
"shell.execute_reply.started": "2023-10-25T06:22:41.417575Z"
},
"tags": []
},
"source": [
"### 人员信息汇总(单个文件)"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "61f8d7c3-b7f2-44b7-86f1-5b29d22193cb",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:33:25.703931Z",
"iopub.status.busy": "2023-10-25T07:33:25.703619Z",
"iopub.status.idle": "2023-10-25T07:33:25.762953Z",
"shell.execute_reply": "2023-10-25T07:33:25.762254Z",
"shell.execute_reply.started": "2023-10-25T07:33:25.703903Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" person = json.load(fl)\n",
"i = len(person)+1\n",
"fl = 'data/北海炼化机关名单表(2023年汇总156人).xlsx'\n",
"wb = openpyxl.load_workbook(fl)\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"\n",
"\n",
"for n in range(3,sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = str(i)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n,3 ).value \n",
" dict1['phone'] = sheet.cell(n,6).value\n",
" dict1['id'] = sheet.cell(n,5 ).value \n",
" dict1['婚姻'] = sheet.cell(n, 11).value\n",
" dict1['unit'] = sheet.cell(n, 8).value \n",
" person[code] = dict1\n",
" i+=1\n",
"filename = 'data/北海炼化2023.json' \n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')\n"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "8da8e47d-b62b-4719-82d5-fcfc61473e08",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T07:38:29.475177Z",
"iopub.status.busy": "2023-10-25T07:38:29.474849Z",
"iopub.status.idle": "2023-10-25T07:38:29.554478Z",
"shell.execute_reply": "2023-10-25T07:38:29.553811Z",
"shell.execute_reply.started": "2023-10-25T07:38:29.475149Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" person = json.load(fl)\n",
"i = len(person)+1\n",
"fl = 'data/北海炼化上岗体检人员名单 (2023年).xlsx'\n",
"wb = openpyxl.load_workbook(fl)\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"\n",
"\n",
"for n in range(3,sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = str(i)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n,3 ).value \n",
" dict1['phone'] = str(sheet.cell(n,7).value)\n",
" dict1['id'] = sheet.cell(n,6 ).value\n",
" \n",
" dict1['有毒因素'] = sheet.cell(n, 11).value\n",
" dict1['unit'] = '新上岗'\n",
" dict1['工种'] = sheet.cell(n, 8).value\n",
" dict1['防护措施'] = sheet.cell(n,13 ).value \n",
" person[code] = dict1\n",
" i+=1\n",
"filename = 'data/北海炼化2023.json' \n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2dc319f7-ccca-469a-8db3-2ca82097ab8f",
"id": "fca6186b-9b4d-4bcd-b5ac-1aecfeb2e149",
"metadata": {},
"outputs": [],
"source": []
@@ -637,7 +1052,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -651,7 +1066,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.10.12"
}
},
"nbformat": 4,
+499 -1
View File
@@ -2332,10 +2332,508 @@
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "85a03b00-9624-4ae9-aa6d-386798d457df",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T02:50:56.997544Z",
"iopub.status.busy": "2023-10-25T02:50:56.995911Z",
"iopub.status.idle": "2023-10-25T02:50:57.006678Z",
"shell.execute_reply": "2023-10-25T02:50:57.004773Z",
"shell.execute_reply.started": "2023-10-25T02:50:56.997463Z"
},
"tags": []
},
"source": [
"# 体测数据分析"
]
},
{
"cell_type": "markdown",
"id": "dca06570-73e6-4f60-8cf9-b3f9da64f1c4",
"metadata": {},
"source": [
"## 清理报告数据"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "f9fee64f-41ff-4453-8a32-a33df086022e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:50:48.179535Z",
"iopub.status.busy": "2023-10-25T03:50:48.179245Z",
"iopub.status.idle": "2023-10-25T03:50:48.598995Z",
"shell.execute_reply": "2023-10-25T03:50:48.598421Z",
"shell.execute_reply.started": "2023-10-25T03:50:48.179514Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"\n",
"filename = 'data/result_天津231017.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
" \n",
"#items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"items = {}\n",
"items['lung'] = '肺活量'\n",
"items['grip'] ='握力'\n",
"items['flexion'] ='坐位体前屈'\n",
"items['jump'] ='纵跳'\n",
"items['pushup'] ='俯卧撑'\n",
"items['balance'] ='单脚站立'\n",
"items['reaction'] ='选择反应时'\n",
"items['step'] ='台阶指数'\n",
"items['situp'] ='一分钟仰卧起坐'\n",
"items['bmi'] ='BMI'\n",
"\n",
"\n",
"list1 = []\n",
"fiie_path ='./134/'\n",
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
"i=1\n",
"list2 = []\n",
"dict2 = {}\n",
"for k, v in dict1.items():\n",
" list1 = []\n",
" mydata = {}\n",
" \n",
" id = str(k).rjust(8,\"0\")\n",
" mydata['unit'] = v['unit']\n",
" mydata['name'] = v['name']\n",
" mydata['sex'] = v['sex']\n",
" mydata['month'] = v['month']\n",
" age = int(v['month']/12)\n",
" if age <20:\n",
" mydata['age'] = 20\n",
" else:\n",
" mydata['age'] = int(v['month']/12)\n",
" \n",
" mydata['fits'] = {}\n",
" score = 0\n",
" for item in list_item:\n",
" if item in v.keys():\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'][items[item]] = {'mark':mark,'score':v[item]['score']}\n",
" score = score + v[item]['score']\n",
" mydata['score'] = round(score/len(mydata['fits']),2)\n",
" if len(mydata['fits']) >2:\n",
" dict2[str(k)] = mydata\n",
"filename = f'data/data_天津231017.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "bd1f8f42-c14a-4bb7-8656-14a0f7968cfc",
"metadata": {},
"source": [
"## 计算测试等级"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "006afc6c-2b1f-4edf-be1b-5f60e2029ee8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:50:53.233122Z",
"iopub.status.busy": "2023-10-25T03:50:53.232833Z",
"iopub.status.idle": "2023-10-25T03:50:53.316856Z",
"shell.execute_reply": "2023-10-25T03:50:53.316327Z",
"shell.execute_reply.started": "2023-10-25T03:50:53.233097Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0~255分人数:2524人,男性:2056人,女性:468人\n",
"256~332分人数:2214人,男性:1400人,女性:814人\n",
"333~367分人数:495人,男性:274人,女性:221人\n",
"368~500分人数:150人,男性:58人,女性:92人\n",
"5383\n"
]
}
],
"source": [
"import json\n",
"\n",
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"filename = 'data/data_天津231017.json'\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",
"print(len(dict1))"
]
},
{
"cell_type": "markdown",
"id": "ed3c0653-087a-4a9d-ba21-8cf5f48515d9",
"metadata": {},
"source": [
"## 根据年龄汇总人员信息及成绩"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "949e4c3c-023d-44a4-b99e-c5460da61161",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:50:55.994714Z",
"iopub.status.busy": "2023-10-25T03:50:55.994442Z",
"iopub.status.idle": "2023-10-25T03:50:56.087067Z",
"shell.execute_reply": "2023-10-25T03:50:56.086443Z",
"shell.execute_reply.started": "2023-10-25T03:50:55.994689Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.47分,人数:1044人,男性:706人\n",
"25~29岁平均成绩:2.57分,人数:540人,男性:372人\n",
"30~34岁平均成绩:2.59分,人数:240人,男性:165人\n",
"35~39岁平均成绩:2.63分,人数:475人,男性:328人\n",
"40~44岁平均成绩:2.68分,人数:411人,男性:245人\n",
"45~49岁平均成绩:2.67分,人数:883人,男性:466人\n",
"50~54岁平均成绩:2.57分,人数:1213人,男性:929人\n",
"55~69岁平均成绩:2.48分,人数:577人,男性:577人\n"
]
}
],
"source": [
"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 = 1\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-1}人,男性:{m}人')"
]
},
{
"cell_type": "markdown",
"id": "6a967a44-7c12-4e82-827b-d75926c09e77",
"metadata": {},
"source": [
"### 根据年龄汇总人员信息及成绩(男)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "721977d3-5816-4bf6-82fc-26fd170e5454",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:51:22.393382Z",
"iopub.status.busy": "2023-10-25T03:51:22.393098Z",
"iopub.status.idle": "2023-10-25T03:51:22.503597Z",
"shell.execute_reply": "2023-10-25T03:51:22.502884Z",
"shell.execute_reply.started": "2023-10-25T03:51:22.393358Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.38分,人数:706人\n",
"25~29岁平均成绩:2.5分,人数:372人\n",
"30~34岁平均成绩:2.46分,人数:165人\n",
"35~39岁平均成绩:2.49分,人数:328人\n",
"40~44岁平均成绩:2.56分,人数:245人\n",
"45~49岁平均成绩:2.47分,人数:466人\n",
"50~54岁平均成绩:2.47分,人数:929人\n",
"55~80岁平均成绩:2.48分,人数:577人\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 = 1\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",
" \n",
" \n",
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')"
]
},
{
"cell_type": "markdown",
"id": "3a8f747e-aacd-45bf-b94a-b505cfd31922",
"metadata": {},
"source": [
"### 根据年龄汇总人员信息及成绩(女)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "f493dc0a-d3cd-4dbd-ad35-e06eb96afbc5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:51:25.001730Z",
"iopub.status.busy": "2023-10-25T03:51:25.001459Z",
"iopub.status.idle": "2023-10-25T03:51:25.099310Z",
"shell.execute_reply": "2023-10-25T03:51:25.098566Z",
"shell.execute_reply.started": "2023-10-25T03:51:25.001706Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20~24岁平均成绩:2.65分,人数:338人\n",
"25~29岁平均成绩:2.72分,人数:168人\n",
"30~34岁平均成绩:2.84分,人数:75人\n",
"35~39岁平均成绩:2.93分,人数:147人\n",
"40~44岁平均成绩:2.83分,人数:166人\n",
"45~49岁平均成绩:2.89分,人数:417人\n",
"50~54岁平均成绩:2.88分,人数:284人\n",
"55~80岁平均成绩:0.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",
"\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 = 1\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",
" \n",
" \n",
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')"
]
},
{
"cell_type": "markdown",
"id": "e9c6bd2e-b6ac-4a6f-ba28-aafcabb40c0d",
"metadata": {},
"source": [
"## 计算平均成绩"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "7155f2c2-0719-4558-aa3b-629fb70194d6",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:51:48.682998Z",
"iopub.status.busy": "2023-10-25T03:51:48.682686Z",
"iopub.status.idle": "2023-10-25T03:51:48.834661Z",
"shell.execute_reply": "2023-10-25T03:51:48.834139Z",
"shell.execute_reply.started": "2023-10-25T03:51:48.682964Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"平均成绩:2.4704分,男性:3788人\n",
"平均成绩:2.8269分,女性:1595人\n",
"平均成绩:2.576分,总体:5383人\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/5383,4)}分,总体:5383人')"
]
},
{
"cell_type": "markdown",
"id": "9a544eec-ec58-47dc-aa36-d890b0b309c2",
"metadata": {},
"source": [
"## 计算测试等级"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "a0bbb339-ee4e-4dc1-83ec-b2055e3c670e",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-25T03:52:43.358905Z",
"iopub.status.busy": "2023-10-25T03:52:43.358608Z",
"iopub.status.idle": "2023-10-25T03:52:43.644315Z",
"shell.execute_reply": "2023-10-25T03:52:43.643658Z",
"shell.execute_reply.started": "2023-10-25T03:52:43.358879Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0~255分人数:2524人,男性:2056人,女性:468人\n",
"256~332分人数:2214人,男性:1400人,女性:814人\n",
"333~367分人数:495人,男性:274人,女性:221人\n",
"368~500分人数:150人,男性:58人,女性:92人\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",
"#filename = 'data/result_石家庄.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "92103efb-a3e4-43ec-acfb-e4cb0b07c2fb",
"metadata": {},
"source": [
"## 计算各年龄段测试等级(女)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8157084e-67a1-48d9-a3c2-34ea8b170039",
"id": "f8949993-7501-4359-aa7c-2cd5de348056",
"metadata": {},
"outputs": [],
"source": []