1807 lines
56 KiB
Plaintext
1807 lines
56 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "92891af2-e909-4b8e-a08a-b5b5e4a1c732",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 体质测试"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "338fb8da-815a-4536-ae91-4f461ba9401f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 体测人员导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 81,
|
||
"id": "ba24132c-133f-4508-8fe7-e68d1908b6e9",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-23T08:05:35.010497Z",
|
||
"iopub.status.busy": "2024-09-23T08:05:35.009998Z",
|
||
"iopub.status.idle": "2024-09-23T08:05:35.403341Z",
|
||
"shell.execute_reply": "2024-09-23T08:05:35.402730Z",
|
||
"shell.execute_reply.started": "2024-09-23T08:05:35.010448Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"from datetime import date\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",
|
||
" code = int(sheet.cell(n, 1).value)\n",
|
||
" person.setdefault(code, {})\n",
|
||
" dict1 = {}\n",
|
||
" dict1['name'] = sheet.cell(n, 2).value\n",
|
||
" dict1['sex'] = sheet.cell(n, 3).value\n",
|
||
" dict1['unit'] = sheet.cell(n, 7).value\n",
|
||
" if sheet.cell(n, 5).value is not None:\n",
|
||
" dict1['gh'] = sheet.cell(n, 5).value\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0] \n",
|
||
" if sheet.cell(n, 4).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n,4).value)\n",
|
||
" person[code] = dict1\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": "10ddfd3b-697c-4459-8bed-147b22f88239",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成读卡系统文件"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 4,
|
||
"id": "63ab2d5b-3a0a-4ac7-a3e7-b3a34e621e98",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-17T01:49:44.352863Z",
|
||
"iopub.status.busy": "2024-09-17T01:49:44.352020Z",
|
||
"iopub.status.idle": "2024-09-17T01:49:44.374799Z",
|
||
"shell.execute_reply": "2024-09-17T01:49:44.374342Z",
|
||
"shell.execute_reply.started": "2024-09-17T01:49:44.352780Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" dict2 = {}\n",
|
||
" #if dict1['sex'] =='男':\n",
|
||
" # sex = 1\n",
|
||
" \n",
|
||
" dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}\n",
|
||
" list1.append(dict2)\n",
|
||
"json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n",
|
||
"\n",
|
||
"# 将 json 数据写入文件\n",
|
||
"with open(\"data/data_镇海.json\", \"w\",encoding = 'utf-8') as file:\n",
|
||
" file.write(json_data) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b6dd08b0-f58c-4dc1-86a9-e7b2b84478c3",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 获取人员测试成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 58,
|
||
"id": "5d864909-d10f-461d-8e6e-dc5c43613576",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T10:49:09.815998Z",
|
||
"iopub.status.busy": "2024-09-22T10:49:09.815209Z",
|
||
"iopub.status.idle": "2024-09-22T10:49:09.910712Z",
|
||
"shell.execute_reply": "2024-09-22T10:49:09.910125Z",
|
||
"shell.execute_reply.started": "2024-09-22T10:49:09.815926Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1365\n",
|
||
"1365\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_20240922.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",
|
||
" re_ta[user]['unit'] = dict1[user]['unit']\n",
|
||
" #re_ta[user]['sub_unit'] = dict1[user]['sub_unit']\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_镇海.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": "a08c6b65-a390-451b-b1a5-fc474db40035",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导出测试人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 57,
|
||
"id": "bc79f0d2-62a2-40c8-bd74-9c7ff17bec8e",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T10:44:33.765318Z",
|
||
"iopub.status.busy": "2024-09-22T10:44:33.764545Z",
|
||
"iopub.status.idle": "2024-09-22T10:44:33.796972Z",
|
||
"shell.execute_reply": "2024-09-22T10:44:33.796426Z",
|
||
"shell.execute_reply.started": "2024-09-22T10:44:33.765245Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"filename = 'data/镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
" \n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" list2 = []\n",
|
||
" list2.append(str(k).rjust(5,'0'))\n",
|
||
" list2.append(v['name']) \n",
|
||
" list2.append(dict2[k]['sex'])\n",
|
||
" list2.append(dict2[k]['unit']) \n",
|
||
" for item in items:\n",
|
||
" if item in v.keys():\n",
|
||
" list2.append(v[item]['成绩']) \n",
|
||
" elif item =='name':\n",
|
||
" list2.append(v[item])\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list1.append(list2)\n",
|
||
"filename = 'data/镇海体测情况(20240922手工).xlsx'\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"sheet.append(title)\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row)\n",
|
||
" \n",
|
||
"wb.save(filename)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0c2dfa71-8680-4ec6-938d-d37eeba4d4f9",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计未体测人员明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 41,
|
||
"id": "cf22739a-5cf3-47fd-b87a-158a2e2d5a95",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T03:58:55.502517Z",
|
||
"iopub.status.busy": "2024-09-22T03:58:55.501726Z",
|
||
"iopub.status.idle": "2024-09-22T03:58:55.536562Z",
|
||
"shell.execute_reply": "2024-09-22T03:58:55.536063Z",
|
||
"shell.execute_reply.started": "2024-09-22T03:58:55.502442Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"filename = 'data/镇海1.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"i = 1\n",
|
||
"for k, v in dict2.items(): \n",
|
||
" if k not in dict1.keys():\n",
|
||
" list2 = [i,k,v['name'],v['unit']]\n",
|
||
" i+=1\n",
|
||
" list1.append(list2)\n",
|
||
"#print(list1)\n",
|
||
"filename = f'data/镇海未测试人员名单(截至20240922).xlsx'\n",
|
||
"title = ['序号','员工编号','姓名','部门']\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"sheet.append(title)\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row) \n",
|
||
"wb.save(filename)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "286a65eb-995f-4183-a4e5-6d907ba21151",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 清理重复人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 39,
|
||
"id": "f4dade65-f760-4220-8a65-39843688a60a",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T03:58:31.869404Z",
|
||
"iopub.status.busy": "2024-09-22T03:58:31.868639Z",
|
||
"iopub.status.idle": "2024-09-22T03:58:32.098484Z",
|
||
"shell.execute_reply": "2024-09-22T03:58:32.097950Z",
|
||
"shell.execute_reply.started": "2024-09-22T03:58:31.869332Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1462\n",
|
||
"1406\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"print(len(dict1))\n",
|
||
"dict2 = {}\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if 'phone' in v.keys():\n",
|
||
" dict2.setdefault(k,{})\n",
|
||
" dict2[k]['name'] = v['name']\n",
|
||
" dict2[k]['phone'] = v['phone']\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict2.items():\n",
|
||
" i = 0\n",
|
||
" for k1, v1 in dict1.items():\n",
|
||
" if v['name']== v1['name'] and v['phone'] == v1['phone'] and k1 != k:\n",
|
||
" list1.append(max(int(k),int(k1)))\n",
|
||
"for item in set(list1):\n",
|
||
" del dict1[str(item)]\n",
|
||
"print(len(dict1))\n",
|
||
"filename = 'data/镇海1.json'\n",
|
||
"\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl, ensure_ascii=False) \n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e513b5bb-8a4e-412a-880b-1ae36e059bfd",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 转换报告格式"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 59,
|
||
"id": "7f038e8d-dd57-4880-8726-6dfa86fbc4a2",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T10:49:29.510032Z",
|
||
"iopub.status.busy": "2024-09-22T10:49:29.509298Z",
|
||
"iopub.status.idle": "2024-09-22T10:49:29.639707Z",
|
||
"shell.execute_reply": "2024-09-22T10:49:29.639166Z",
|
||
"shell.execute_reply.started": "2024-09-22T10:49:29.509965Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1365\n",
|
||
"1365\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import datetime\n",
|
||
"import csv\n",
|
||
"from datetime import date\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",
|
||
"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",
|
||
"\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_20240922.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",
|
||
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
||
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
||
"for result in list1:\n",
|
||
" user = str(result[2])\n",
|
||
" rq = date.fromisoformat(result[6].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 dict1[user]['sex'] == '男':\n",
|
||
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
||
" else:\n",
|
||
" l_xm = ['weight','height','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",
|
||
" birth = date.fromisoformat(dict1[user]['birth'])\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",
|
||
" item_name = item[m_item]['en'] \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[6]\n",
|
||
"\n",
|
||
"\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_镇海1.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": "de2eec6d-a74e-47e1-ab7a-c7f6eda80a20",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成完善得分"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 60,
|
||
"id": "763aa68a-da54-4745-a759-4399aba10f7e",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T10:49:36.694100Z",
|
||
"iopub.status.busy": "2024-09-22T10:49:36.693314Z",
|
||
"iopub.status.idle": "2024-09-22T10:49:36.784607Z",
|
||
"shell.execute_reply": "2024-09-22T10:49:36.784166Z",
|
||
"shell.execute_reply.started": "2024-09-22T10:49:36.694030Z"
|
||
}
|
||
},
|
||
"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_镇海1.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_镇海2.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||
"print('ok!') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "723ae3d7-ec16-4dc6-91e2-eeeea6ffe081",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成报告"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 61,
|
||
"id": "90faac13-492d-4b3d-bb21-c228af6d9864",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T10:54:16.247571Z",
|
||
"iopub.status.busy": "2024-09-22T10:54:16.246795Z",
|
||
"iopub.status.idle": "2024-09-22T11:05:57.685110Z",
|
||
"shell.execute_reply": "2024-09-22T11:05:57.683956Z",
|
||
"shell.execute_reply.started": "2024-09-22T10:54:16.247498Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1365\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_镇海2.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(4,\"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": "82c1eaea-89ad-444a-8dad-07f438c739cc",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计报告人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 88,
|
||
"id": "61c731bc-6117-4a9f-8bfa-66f820e49fc4",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-23T08:21:40.030772Z",
|
||
"iopub.status.busy": "2024-09-23T08:21:40.030153Z",
|
||
"iopub.status.idle": "2024-09-23T08:21:40.215352Z",
|
||
"shell.execute_reply": "2024-09-23T08:21:40.214783Z",
|
||
"shell.execute_reply.started": "2024-09-23T08:21:40.030713Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1365\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import glob\n",
|
||
"from pathlib import Path\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"filename = 'data/镇海.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files/345321'\n",
|
||
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
||
"dict2 = {}\n",
|
||
"for fn in fls:\n",
|
||
" \n",
|
||
" fi_name =Path(fn).stem.split('-')[0]\n",
|
||
" #fi_name =Path(fn).stem\n",
|
||
" code = int(fi_name)\n",
|
||
" dict2[str(code)] = dict1[str(code)]\n",
|
||
"filename = 'data/镇海体测人员.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||
"print(len(dict2)) \n",
|
||
"list1 = []\n",
|
||
"for k, v in dict2.items(): \n",
|
||
" list2 = []\n",
|
||
" if 'gh' in v.keys():\n",
|
||
" gh = v['gh']\n",
|
||
" else:\n",
|
||
" gh = ''\n",
|
||
" if 'phone' in v.keys():\n",
|
||
" phone = v['phone']\n",
|
||
" else:\n",
|
||
" phone = ''\n",
|
||
" list2 = [k,v['name'],v['sex'],v['birth'],v['unit'],gh,phone]\n",
|
||
" list1.append(list2)\n",
|
||
"#print(list1)\n",
|
||
"filename = 'data/镇海参加测试人员名单.xlsx'\n",
|
||
"title = ['序号','员工编号','姓名','部门']\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"sheet.append(title)\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row) \n",
|
||
"wb.save(filename)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "385285b8-fdb3-421d-afbf-c13e4f55bb46",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 核验报告人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 94,
|
||
"id": "c6195bc3-64bc-4f52-8ebc-ba16fd222f85",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-24T09:46:54.184271Z",
|
||
"iopub.status.busy": "2024-09-24T09:46:54.183550Z",
|
||
"iopub.status.idle": "2024-09-24T09:46:54.365589Z",
|
||
"shell.execute_reply": "2024-09-24T09:46:54.364993Z",
|
||
"shell.execute_reply.started": "2024-09-24T09:46:54.184207Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"71 方法泉\n",
|
||
"125 徐荟杰\n",
|
||
"704 陈鼎\n",
|
||
"1365\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"from datetime import date\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",
|
||
" code = int(sheet.cell(n, 1).value)\n",
|
||
" person.setdefault(code, {})\n",
|
||
" dict1 = {}\n",
|
||
" dict1['name'] = sheet.cell(n, 2).value\n",
|
||
" dict1['sex'] = sheet.cell(n, 3).value\n",
|
||
" dict1['unit'] = sheet.cell(n, 5).value\n",
|
||
" if sheet.cell(n, 6).value is not None:\n",
|
||
" dict1['gh'] = sheet.cell(n, 6).value\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0] \n",
|
||
" if sheet.cell(n, 7).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n,7).value)\n",
|
||
" if len(str(sheet.cell(n,7).value))<11:\n",
|
||
" print(code,sheet.cell(n, 2).value)\n",
|
||
" person[code] = dict1\n",
|
||
"filename = 'data/镇海炼化参加测试人员.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||
"print(len(person))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "7e551660-e85f-4da2-8224-042784033ed5",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成查询信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 98,
|
||
"id": "299c1d41-7634-4703-8411-08f175df4e16",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-24T09:56:29.452711Z",
|
||
"iopub.status.busy": "2024-09-24T09:56:29.451957Z",
|
||
"iopub.status.idle": "2024-09-24T09:56:29.517710Z",
|
||
"shell.execute_reply": "2024-09-24T09:56:29.517153Z",
|
||
"shell.execute_reply.started": "2024-09-24T09:56:29.452638Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import math\n",
|
||
"import glob\n",
|
||
"import random\n",
|
||
"from pathlib import Path\n",
|
||
"import pymongo\n",
|
||
"\n",
|
||
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
||
"mydb = myclient[\"baogao\"]\n",
|
||
"mycol = mydb[\"pdf\"]\n",
|
||
"\n",
|
||
"place_id = 345321\n",
|
||
"\n",
|
||
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
|
||
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
|
||
"\n",
|
||
"filename = 'data/镇海炼化参加测试人员.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"for fn in fls:\n",
|
||
" dict2 = {}\n",
|
||
" fi_name =Path(fn).stem.split('-')[0]\n",
|
||
" #fi_name =Path(fn).stem\n",
|
||
" code = int(fi_name)\n",
|
||
" dxm = dict1[str(code)]['gh']\n",
|
||
" dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n",
|
||
" list2.append(dict2)\n",
|
||
" i +=1\n",
|
||
"x = mycol.insert_many(list2)\n",
|
||
"print('ok') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e923022e-aef7-4c8e-84f9-b853e53ff820",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 根据工号生成查询信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 96,
|
||
"id": "f709fd4a-d0b0-44a9-a782-0c1ffd43f6b8",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-24T09:47:36.612690Z",
|
||
"iopub.status.busy": "2024-09-24T09:47:36.611927Z",
|
||
"iopub.status.idle": "2024-09-24T09:47:36.637765Z",
|
||
"shell.execute_reply": "2024-09-24T09:47:36.637249Z",
|
||
"shell.execute_reply.started": "2024-09-24T09:47:36.612619Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"[]\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"filename = 'data/镇海炼化参加测试人员.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"list1 = []\n",
|
||
"list2 = []\n",
|
||
"set1 = set()\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if 'gh' in v.keys():\n",
|
||
" gh = v['gh']\n",
|
||
" if gh not in list1:\n",
|
||
" list1.append(v['gh'])\n",
|
||
" else:\n",
|
||
" list2.append(gh)\n",
|
||
"print(list2)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d9464f81-9228-403a-9d78-090fb4ce0faa",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 体测报告按部门分类"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 99,
|
||
"id": "7eac364f-0fde-4853-9d2b-8c4c0c59a341",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-24T10:28:39.624502Z",
|
||
"iopub.status.busy": "2024-09-24T10:28:39.623736Z",
|
||
"iopub.status.idle": "2024-09-24T10:28:39.991374Z",
|
||
"shell.execute_reply": "2024-09-24T10:28:39.990804Z",
|
||
"shell.execute_reply.started": "2024-09-24T10:28:39.624428Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import glob\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"fi_path = '/home/songyi/pdf-typescript/镇海石化'\n",
|
||
"new_path = 'file/镇海石化'\n",
|
||
"old = []\n",
|
||
"dict2 = {}\n",
|
||
"\n",
|
||
"filename = 'data/镇海炼化参加测试人员.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
||
"for fn in fls:\n",
|
||
" fi_name =Path(fn).stem.split('-')[0]\n",
|
||
" code = int(fi_name)\n",
|
||
" unit_path = Path(new_path,dict1[str(code)]['unit'])\n",
|
||
" unit_path.mkdir(parents = True, exist_ok = True)\n",
|
||
" n_name = Path(unit_path,Path(fn).stem+'.pdf')\n",
|
||
" if not os.path.exists(n_name):\n",
|
||
" shutil.copyfile(fn,n_name)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d7bb270c-cc9e-413b-af36-17c33692e289",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成体测报告打印明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 100,
|
||
"id": "d88bd5c4-1df3-457b-b65d-61692c45e7bd",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-24T10:30:51.115176Z",
|
||
"iopub.status.busy": "2024-09-24T10:30:51.114431Z",
|
||
"iopub.status.idle": "2024-09-24T10:30:51.335424Z",
|
||
"shell.execute_reply": "2024-09-24T10:30:51.334870Z",
|
||
"shell.execute_reply.started": "2024-09-24T10:30:51.115089Z"
|
||
}
|
||
},
|
||
"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 = '/home/songyi/pdf-typescript/镇海石化'\n",
|
||
"\n",
|
||
"filename = 'data/镇海炼化参加测试人员.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
||
"list1 = []\n",
|
||
"title = ['测试编号','姓名','性别','部门']\n",
|
||
"for fn in fls:\n",
|
||
" list2 = []\n",
|
||
" fi_name =Path(fn).stem.split('-')[0] \n",
|
||
" code = int(fi_name)\n",
|
||
" sex = dict1[str(code)]['sex']\n",
|
||
" unit = dict1[str(code)]['unit']\n",
|
||
" list2 = [fi_name,Path(fn).stem.split('-')[1],sex,unit]\n",
|
||
" \n",
|
||
" list1.append(list2)\n",
|
||
"\n",
|
||
"filename = 'data/镇海石化体测报告明细表.xlsx'\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"sheet.append(title)\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row)\n",
|
||
" \n",
|
||
"wb.save(filename) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "6b521daf-f9dc-4579-9400-d8ab857bb166",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 体质测试综合报告数据分析"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "83203d08-46ca-45f6-8204-0c8e35f754b6",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 清理报告数据"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 62,
|
||
"id": "cccc2e43-7a73-48ec-8540-06b4d59f8ceb",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:06:13.897106Z",
|
||
"iopub.status.busy": "2024-09-22T11:06:13.896366Z",
|
||
"iopub.status.idle": "2024-09-22T11:06:13.985127Z",
|
||
"shell.execute_reply": "2024-09-22T11:06:13.984566Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:06:13.897035Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok!\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海2.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 ='./138/'\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_镇海.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||
"print('ok!') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c3bcd7ec-1d66-40c6-a27d-1c73e6eef695",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算平均成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 63,
|
||
"id": "d5721244-b5f5-4577-bae8-2e6c5bd8e4da",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:07:17.674314Z",
|
||
"iopub.status.busy": "2024-09-22T11:07:17.673571Z",
|
||
"iopub.status.idle": "2024-09-22T11:07:17.699078Z",
|
||
"shell.execute_reply": "2024-09-22T11:07:17.698099Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:07:17.674240Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"平均成绩:3.1739分,男性:1074人\n",
|
||
"平均成绩:3.3303分,女性:291人\n",
|
||
"平均成绩:3.2072分,总体:1365人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n",
|
||
"filename = 'data/data_镇海.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/(f+m),4)}分,总体:{(f+m)}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a7ba7d25-b7a0-4641-a218-b4569d31acb1",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算测试等级"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 64,
|
||
"id": "cff50f06-3221-4340-950f-3a24073b8565",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:09:10.042162Z",
|
||
"iopub.status.busy": "2024-09-22T11:09:10.041458Z",
|
||
"iopub.status.idle": "2024-09-22T11:09:10.113085Z",
|
||
"shell.execute_reply": "2024-09-22T11:09:10.112552Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:09:10.042084Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"0~255分人数:134人,男性:118人,女性:16人\n",
|
||
"256~332分人数:585人,男性:472人,女性:113人\n",
|
||
"333~367分人数:431人,男性:333人,女性:98人\n",
|
||
"368~500分人数:215人,男性:151人,女性:64人\n",
|
||
"1365\n",
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"\n",
|
||
"#filename = 'data/data_长炼医院.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))\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "16a0d09b-2128-4df4-9745-954f48384244",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算各年龄段测试等级(女)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 65,
|
||
"id": "6baf0ff2-cdfa-4396-bcf8-3e23a18670dc",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:11:36.729958Z",
|
||
"iopub.status.busy": "2024-09-22T11:11:36.729223Z",
|
||
"iopub.status.idle": "2024-09-22T11:11:36.759840Z",
|
||
"shell.execute_reply": "2024-09-22T11:11:36.759298Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:11:36.729889Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"20-24 {'良好': 29, '合格': 60, '优秀': 22, '不合格': 8}\n",
|
||
"25-29 {'良好': 24, '合格': 32, '不合格': 3, '优秀': 14}\n",
|
||
"30-34 {'不合格': 3, '优秀': 6, '合格': 11, '良好': 15}\n",
|
||
"35-39 {'合格': 5, '不合格': 2, '良好': 13, '优秀': 6}\n",
|
||
"40-44 {'良好': 6, '合格': 1, '优秀': 1, '不合格': 0}\n",
|
||
"45-49 {'良好': 8, '合格': 4, '优秀': 12, '不合格': 0}\n",
|
||
"50-54 {'良好': 3, '不合格': 0, '合格': 0, '优秀': 2}\n",
|
||
"55-80 {'优秀': 1, '合格': 0, '良好': 0, '不合格': 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": "79fb3eab-e8d4-42bb-9ba4-8402f3b82b54",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算各年龄段测试等级(男)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 66,
|
||
"id": "2979cf80-5268-4754-ab8a-11a539315e92",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:14:29.282315Z",
|
||
"iopub.status.busy": "2024-09-22T11:14:29.281554Z",
|
||
"iopub.status.idle": "2024-09-22T11:14:29.310507Z",
|
||
"shell.execute_reply": "2024-09-22T11:14:29.309894Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:14:29.282244Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"20-24 {'良好': 97, '合格': 177, '优秀': 38, '不合格': 53}\n",
|
||
"25-29 {'良好': 57, '合格': 97, '不合格': 21, '优秀': 21}\n",
|
||
"30-34 {'不合格': 15, '优秀': 13, '合格': 43, '良好': 29}\n",
|
||
"35-39 {'合格': 57, '不合格': 11, '良好': 45, '优秀': 22}\n",
|
||
"40-44 {'良好': 27, '合格': 18, '优秀': 12, '不合格': 2}\n",
|
||
"45-49 {'良好': 26, '合格': 28, '优秀': 17, '不合格': 1}\n",
|
||
"50-54 {'良好': 33, '不合格': 10, '合格': 29, '优秀': 16}\n",
|
||
"55-80 {'优秀': 12, '合格': 23, '良好': 19, '不合格': 5}\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": "9a38fc15-579c-42e9-a23c-1050a96e0cf8",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 根据年龄汇总人员信息及成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 67,
|
||
"id": "8a7cb3b0-d7be-44ac-a1ec-40bdcf29e83b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:16:13.093509Z",
|
||
"iopub.status.busy": "2024-09-22T11:16:13.092890Z",
|
||
"iopub.status.idle": "2024-09-22T11:16:13.121521Z",
|
||
"shell.execute_reply": "2024-09-22T11:16:13.120918Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:16:13.093450Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"16~24岁平均成绩:3.11分,人数:484人,男性:365人\n",
|
||
"25~29岁平均成绩:3.16分,人数:269人,男性:196人\n",
|
||
"30~34岁平均成绩:3.15分,人数:135人,男性:100人\n",
|
||
"35~39岁平均成绩:3.3分,人数:161人,男性:135人\n",
|
||
"40~44岁平均成绩:3.39分,人数:67人,男性:59人\n",
|
||
"45~49岁平均成绩:3.48分,人数:96人,男性:72人\n",
|
||
"50~54岁平均成绩:3.29分,人数:93人,男性:88人\n",
|
||
"55~69岁平均成绩:3.27分,人数:60人,男性:59人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"nld = [[16,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",
|
||
" if i ==0:\n",
|
||
" print(f'{di}~{gao}岁平均成绩:0分,人数:0人,男性:{m}人')\n",
|
||
" else:\n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人,男性:{m}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "48debe3b-d0ec-41e8-93ef-921b8e013aa7",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 根据年龄汇总人员信息及成绩(男)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 68,
|
||
"id": "c5bb03ca-b7ee-4564-b425-8513e1bff081",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:18:31.953834Z",
|
||
"iopub.status.busy": "2024-09-22T11:18:31.953204Z",
|
||
"iopub.status.idle": "2024-09-22T11:18:31.982787Z",
|
||
"shell.execute_reply": "2024-09-22T11:18:31.982216Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:18:31.953775Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"20~24岁平均成绩:3.08分,人数:365人\n",
|
||
"25~29岁平均成绩:3.1分,人数:196人\n",
|
||
"30~34岁平均成绩:3.1分,人数:100人\n",
|
||
"35~39岁平均成绩:3.27分,人数:135人\n",
|
||
"40~44岁平均成绩:3.39分,人数:59人\n",
|
||
"45~49岁平均成绩:3.4分,人数:72人\n",
|
||
"50~54岁平均成绩:3.27分,人数:88人\n",
|
||
"55~80岁平均成绩:3.25分,人数:59人\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}岁平均成绩:0分,人数:{i}人') \n",
|
||
" else:\n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "92bb0683-81ea-4b90-8b74-4a2f43b4835c",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 根据年龄汇总人员信息及成绩(女)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 69,
|
||
"id": "bf333998-230c-4365-aadc-b0d1be073b39",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:20:46.582055Z",
|
||
"iopub.status.busy": "2024-09-22T11:20:46.581306Z",
|
||
"iopub.status.idle": "2024-09-22T11:20:46.606923Z",
|
||
"shell.execute_reply": "2024-09-22T11:20:46.606298Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:20:46.581983Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"20~24岁平均成绩:3.21分,人数:119人\n",
|
||
"25~29岁平均成绩:3.32分,人数:73人\n",
|
||
"30~34岁平均成绩:3.32分,人数:35人\n",
|
||
"35~39岁平均成绩:3.44分,人数:26人\n",
|
||
"40~44岁平均成绩:3.4分,人数:8人\n",
|
||
"45~49岁平均成绩:3.73分,人数:24人\n",
|
||
"50~54岁平均成绩:3.71分,人数:5人\n",
|
||
"55~80岁平均成绩:4.0分,人数: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",
|
||
"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}岁平均成绩:0分,人数:{i}人') \n",
|
||
" else:\n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "026d11e4-7f3d-4be5-9fa0-fa3699969c6b",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算各项目成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 70,
|
||
"id": "352c6c29-8929-4210-84c5-8dbc3d5ffeee",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:21:51.501623Z",
|
||
"iopub.status.busy": "2024-09-22T11:21:51.500851Z",
|
||
"iopub.status.idle": "2024-09-22T11:21:51.526895Z",
|
||
"shell.execute_reply": "2024-09-22T11:21:51.526331Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:21:51.501553Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"BMI 4.0 1364\n",
|
||
"肺活量 3.52 1364\n",
|
||
"握力 3.25 1361\n",
|
||
"坐位体前屈 2.93 1346\n",
|
||
"纵跳 3.4 1316\n",
|
||
"俯卧撑 3.65 1047\n",
|
||
"一分钟仰卧起坐 4.27 240\n",
|
||
"单脚站立 2.6 1356\n",
|
||
"选择反应时 2.88 1317\n",
|
||
"台阶指数 2.5 1286\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"for item in items:\n",
|
||
" score = 0\n",
|
||
" n = 0\n",
|
||
" for k, v in dict1.items(): \n",
|
||
" if item in v['fits'].keys():\n",
|
||
" n = n + 1\n",
|
||
" score =score + int(v['fits'][item]['score'])\n",
|
||
" print(item,round(score/n,2),n)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a13d5644-7cd1-4943-bce9-c6863f75b986",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 按照部门计算平均成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 71,
|
||
"id": "97f5a1cf-341e-4b99-9549-b6a3fb165849",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-22T11:23:46.840351Z",
|
||
"iopub.status.busy": "2024-09-22T11:23:46.839524Z",
|
||
"iopub.status.idle": "2024-09-22T11:23:46.865572Z",
|
||
"shell.execute_reply": "2024-09-22T11:23:46.865072Z",
|
||
"shell.execute_reply.started": "2024-09-22T11:23:46.840276Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"采购中心 3.39 20\n",
|
||
"炼油三部 3.2 30\n",
|
||
"烯烃一部 3.21 156\n",
|
||
"炼油五部 3.26 72\n",
|
||
"公用工程二部 3.26 72\n",
|
||
"合成材料部 3.12 55\n",
|
||
"质管中心 3.24 56\n",
|
||
"储运一部 3.1 82\n",
|
||
"氢能制造部 3.18 59\n",
|
||
"电气中心 3.14 45\n",
|
||
"公用工程一部 3.12 81\n",
|
||
"仪表和计量中心 3.29 81\n",
|
||
"港储部 3.13 36\n",
|
||
"炼油二部 3.28 60\n",
|
||
"消防支队 3.35 25\n",
|
||
"烯烃二部 3.03 42\n",
|
||
"炼油一部 3.29 42\n",
|
||
"事务中心 3.17 35\n",
|
||
"公司机关 3.3 102\n",
|
||
"化学制品部 3.31 43\n",
|
||
"项目管理部 3.38 19\n",
|
||
"新材料研究院 3.31 15\n",
|
||
"炼油四部 3.08 27\n",
|
||
"油库中心 3.22 25\n",
|
||
"炼油六部 3.08 34\n",
|
||
"储运二部 3.12 13\n",
|
||
"宣传部 3.11 1\n",
|
||
"财务部 3.0 1\n",
|
||
"生产部 3.04 3\n",
|
||
"发展部 2.78 4\n",
|
||
"项目部 2.7 2\n",
|
||
"炼油七部 3.25 26\n",
|
||
"公用工程五部 2.8 1\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"depart = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if v['unit'] not in depart:\n",
|
||
" depart.append(v['unit'])\n",
|
||
"\n",
|
||
"for item in depart:\n",
|
||
" score = 0\n",
|
||
" n = 0\n",
|
||
" for k, v in dict1.items():\n",
|
||
" if item == v['unit']:\n",
|
||
" score = score + v['score']\n",
|
||
" n = n +1 \n",
|
||
" print(item,round(score/n,2),n)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "0d043ccc-a241-4b72-912f-7609d3f794a7",
|
||
"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.12.3"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|