2357 lines
73 KiB
Plaintext
2357 lines
73 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": 39,
|
||
"id": "ba24132c-133f-4508-8fe7-e68d1908b6e9",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:50:51.333490Z",
|
||
"iopub.status.busy": "2024-11-05T05:50:51.333249Z",
|
||
"iopub.status.idle": "2024-11-05T05:50:51.533334Z",
|
||
"shell.execute_reply": "2024-11-05T05:50:51.532707Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:50:51.333467Z"
|
||
}
|
||
},
|
||
"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, 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",
|
||
" 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": null,
|
||
"id": "63ab2d5b-3a0a-4ac7-a3e7-b3a34e621e98",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": 40,
|
||
"id": "5d864909-d10f-461d-8e6e-dc5c43613576",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:50:57.671950Z",
|
||
"iopub.status.busy": "2024-11-05T05:50:57.669968Z",
|
||
"iopub.status.idle": "2024-11-05T05:50:57.814421Z",
|
||
"shell.execute_reply": "2024-11-05T05:50:57.813860Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:50:57.671867Z"
|
||
}
|
||
},
|
||
"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": null,
|
||
"id": "bc79f0d2-62a2-40c8-bd74-9c7ff17bec8e",
|
||
"metadata": {},
|
||
"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",
|
||
" list2.append(dict2[k]['gwxl'])\n",
|
||
" list2.append(dict2[k]['gzz'])\n",
|
||
" list1.append(list2)\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)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0c2dfa71-8680-4ec6-938d-d37eeba4d4f9",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计未体测人员明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "cf22739a-5cf3-47fd-b87a-158a2e2d5a95",
|
||
"metadata": {},
|
||
"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": null,
|
||
"id": "f4dade65-f760-4220-8a65-39843688a60a",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": 41,
|
||
"id": "7f038e8d-dd57-4880-8726-6dfa86fbc4a2",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:51:04.272284Z",
|
||
"iopub.status.busy": "2024-11-05T05:51:04.271551Z",
|
||
"iopub.status.idle": "2024-11-05T05:51:04.391755Z",
|
||
"shell.execute_reply": "2024-11-05T05:51:04.391153Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:51:04.272213Z"
|
||
}
|
||
},
|
||
"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_镇海(合并).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": 42,
|
||
"id": "763aa68a-da54-4745-a759-4399aba10f7e",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:51:27.308482Z",
|
||
"iopub.status.busy": "2024-11-05T05:51:27.307713Z",
|
||
"iopub.status.idle": "2024-11-05T05:51:27.406446Z",
|
||
"shell.execute_reply": "2024-11-05T05:51:27.405880Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:51:27.308411Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok!\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import time\n",
|
||
"\n",
|
||
"filename = '../item.json'\n",
|
||
"item = {}\n",
|
||
"unit = {}\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl) \n",
|
||
"for k,v in dict3.items():\n",
|
||
" item[k] = v\n",
|
||
"item['1']['en'] = 'lung'\n",
|
||
"item['2']['en'] = 'grip'\n",
|
||
"item['3']['en'] = 'flexion'\n",
|
||
"item['4']['en'] = 'jump'\n",
|
||
"item['5']['en'] = 'pushup'\n",
|
||
"item['6']['en'] = 'balance'\n",
|
||
"item['7']['en'] = 'reaction'\n",
|
||
"item['8']['en'] = 'step'\n",
|
||
"item['9']['en'] = 'situp'\n",
|
||
"item['10']['en'] = 'height'\n",
|
||
"item['11']['en'] = 'weight'\n",
|
||
"\n",
|
||
"filename = 'data/体质检测标准 (1).json' \n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"\n",
|
||
"\n",
|
||
"def cal_score(data1):\n",
|
||
" #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n",
|
||
" person = dict1['person']\n",
|
||
" criteria = dict1['criteria']\n",
|
||
" if data1['age'] >59:\n",
|
||
" data1['age'] = 59\n",
|
||
" if data1['age'] <20:\n",
|
||
" data1['age'] = 20\n",
|
||
" info = data1['sex']+str(data1['age'])\n",
|
||
" bz = person[info]\n",
|
||
" mx = criteria[bz][data1['item']]\n",
|
||
" result = data1['result'] \n",
|
||
" if data1['item'] == 'reaction':\n",
|
||
" for bz1 in mx:\n",
|
||
" if result > bz1:\n",
|
||
" #print(bz1)\n",
|
||
" score = mx.index(bz1,0)\n",
|
||
" break\n",
|
||
" else:\n",
|
||
" score = 5\n",
|
||
" else:\n",
|
||
" for bz1 in mx:\n",
|
||
" if result < bz1:\n",
|
||
" #print(bz1)\n",
|
||
" score = mx.index(bz1,0)\n",
|
||
" break\n",
|
||
" else:\n",
|
||
" score = 5\n",
|
||
" return(score)\n",
|
||
"filename = 'data/体质检测标准_BMI.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict4 = json.load(fl) \n",
|
||
" \n",
|
||
"def cal_bmi(data1):\n",
|
||
" # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
|
||
" person = dict4['person']\n",
|
||
" criteria = dict4['criteria']\n",
|
||
" if data1['age'] > 59:\n",
|
||
" data1['age'] = 59\n",
|
||
" if data1['age'] <20:\n",
|
||
" data1['age'] = 20\n",
|
||
" info = data1['sex']+str(data1['age'])\n",
|
||
" bz = person[info]\n",
|
||
" #print(bz)\n",
|
||
" result = data1['result']\n",
|
||
" #print(data1['code'],result)\n",
|
||
" height = int(float(result.split(',')[0]))\n",
|
||
" weight = float(result.split(',')[1])\n",
|
||
" if str(height) not in criteria[bz]:\n",
|
||
" score = 1\n",
|
||
" else: \n",
|
||
" mx = criteria[bz][str(height)]\n",
|
||
" if weight < mx[0]:\n",
|
||
" score = 1\n",
|
||
" elif weight < mx[1]:\n",
|
||
" score = 3\n",
|
||
" elif weight < mx[2]:\n",
|
||
" score = 5 \n",
|
||
" elif weight <= mx[3]:\n",
|
||
" score = 3 \n",
|
||
" elif weight > mx[3]:\n",
|
||
" score = 1\n",
|
||
" return score\n",
|
||
" \n",
|
||
" \n",
|
||
"\n",
|
||
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
|
||
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
|
||
"filename = 'data/result_镇海(合并).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl) \n",
|
||
"for k, v in dict2.items():\n",
|
||
" #print(k)\n",
|
||
" if v['sex'] == '男':\n",
|
||
" sex = 'M'\n",
|
||
" else:\n",
|
||
" sex = 'F' \n",
|
||
" if 'height' in v.keys() and 'weight' in v.keys():\n",
|
||
" bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
|
||
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
|
||
" dict2[k]['bmi'] = {}\n",
|
||
" dict2[k]['bmi']['成绩'] = bmi_data\n",
|
||
" dict2[k]['bmi']['score'] = cal_bmi(data1)\n",
|
||
" for item_en in list_item:\n",
|
||
" if item_en in v.keys(): \n",
|
||
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
|
||
" dict2[k][item_en]['score'] = cal_score(data1)\n",
|
||
" #print(k,v[item_en]['成绩'],cal_score(data1))\n",
|
||
"\n",
|
||
"filename = f'data/result_镇海(合并).json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||
"print('ok!') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "bb0f8c6f-5088-4c4d-a253-9c207745ef25",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成体测成绩明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "5cff3c83-b3cb-4c69-97a9-82e523374f6b",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n",
|
||
"bmi = ['height','weight']\n",
|
||
"title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海(合并).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n",
|
||
" list2 = []\n",
|
||
" list2.append(str(k).rjust(5,'0'))\n",
|
||
" list2.append(dict1[k]['name']) \n",
|
||
" list2.append(dict1[k]['sex'])\n",
|
||
" list2.append(dict1[k]['unit'])\n",
|
||
" i = 0\n",
|
||
" if 'bmi' in dict1[k].keys():\n",
|
||
" list2.append(dict1[k]['height']['成绩'])\n",
|
||
" list2.append(dict1[k]['weight']['成绩'])\n",
|
||
" list2.append(dict1[k]['bmi']['score'])\n",
|
||
" i+=1\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" \n",
|
||
" \n",
|
||
" for item in items:\n",
|
||
" if item in dict1[k].keys():\n",
|
||
" list2.append(dict1[k][item]['成绩'])\n",
|
||
" list2.append(dict1[k][item]['score']) \n",
|
||
" i+=1\n",
|
||
" elif item =='name':\n",
|
||
" list2.append(dict1[k][item])\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" if i>2:\n",
|
||
" list1.append(list2)\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": "723ae3d7-ec16-4dc6-91e2-eeeea6ffe081",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成报告"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "90faac13-492d-4b3d-bb21-c228af6d9864",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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_镇海(合并).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": null,
|
||
"id": "61c731bc-6117-4a9f-8bfa-66f820e49fc4",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": "fc0f353c-1021-4c8c-bb7c-7a4abb609836",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 补充报告人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "fa963fb6-b47d-4b75-9109-6cda89218182",
|
||
"metadata": {
|
||
"scrolled": true
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import glob\n",
|
||
"from pathlib import Path\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"\n",
|
||
"filename = 'data/镇海体测人员.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"wb = openpyxl.load_workbook('data/镇海炼化参加测试人员名单(分析用).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"for n in range(2, sheet.max_row+1):\n",
|
||
" if sheet.cell(n, 12).value is not None:\n",
|
||
" code = int(sheet.cell(n, 1).value)\n",
|
||
" if sheet.cell(n, 12).value is not None:\n",
|
||
" dict1[str(code)]['gwlb'] = sheet.cell(n, 12).value\n",
|
||
" dict1[str(code)]['gwxl'] = sheet.cell(n, 9).value\n",
|
||
" dict1[str(code)]['gzz'] = sheet.cell(n, 11).value\n",
|
||
"\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
||
"print('ok!') \n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "385285b8-fdb3-421d-afbf-c13e4f55bb46",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 核验报告人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "c6195bc3-64bc-4f52-8ebc-ba16fd222f85",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": null,
|
||
"id": "299c1d41-7634-4703-8411-08f175df4e16",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": null,
|
||
"id": "f709fd4a-d0b0-44a9-a782-0c1ffd43f6b8",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": null,
|
||
"id": "7eac364f-0fde-4853-9d2b-8c4c0c59a341",
|
||
"metadata": {},
|
||
"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": null,
|
||
"id": "d88bd5c4-1df3-457b-b65d-61692c45e7bd",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": 43,
|
||
"id": "cccc2e43-7a73-48ec-8540-06b4d59f8ceb",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:52:29.953308Z",
|
||
"iopub.status.busy": "2024-11-05T05:52:29.952999Z",
|
||
"iopub.status.idle": "2024-11-05T05:52:30.049510Z",
|
||
"shell.execute_reply": "2024-11-05T05:52:30.048811Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:52:29.953281Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok!\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海(合并).json'\n",
|
||
"with open(filename,'r',encoding = 'utf-8') 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": "1c0bca93-d8a7-42ba-9a2c-50d3493c802f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 报告按照工作制分类"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "a550ecd7-da8e-41b6-8b8f-8bc144d48bfe",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"\n",
|
||
"filename = 'data/result_镇海2.json'\n",
|
||
"with open(filename,'r',encoding = 'utf-8') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"filename = 'data/镇海体测人员.json'\n",
|
||
"with open(filename,'r',encoding = 'utf-8') as fl:\n",
|
||
" dict3 = 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",
|
||
" if dict3[k]['gzz'] == '倒班':\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(len(dict2)) "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c3bcd7ec-1d66-40c6-a27d-1c73e6eef695",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算平均成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 44,
|
||
"id": "d5721244-b5f5-4577-bae8-2e6c5bd8e4da",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:52:48.379274Z",
|
||
"iopub.status.busy": "2024-11-05T05:52:48.378455Z",
|
||
"iopub.status.idle": "2024-11-05T05:52:48.403648Z",
|
||
"shell.execute_reply": "2024-11-05T05:52:48.403090Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:52:48.379196Z"
|
||
}
|
||
},
|
||
"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": 45,
|
||
"id": "cff50f06-3221-4340-950f-3a24073b8565",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:52:54.954047Z",
|
||
"iopub.status.busy": "2024-11-05T05:52:54.952637Z",
|
||
"iopub.status.idle": "2024-11-05T05:52:55.017683Z",
|
||
"shell.execute_reply": "2024-11-05T05:52:55.017112Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:52:54.953966Z"
|
||
}
|
||
},
|
||
"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": 46,
|
||
"id": "6baf0ff2-cdfa-4396-bcf8-3e23a18670dc",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:52:59.630256Z",
|
||
"iopub.status.busy": "2024-11-05T05:52:59.629491Z",
|
||
"iopub.status.idle": "2024-11-05T05:52:59.656868Z",
|
||
"shell.execute_reply": "2024-11-05T05:52:59.656319Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:52:59.630184Z"
|
||
}
|
||
},
|
||
"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": 47,
|
||
"id": "2979cf80-5268-4754-ab8a-11a539315e92",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:03.265936Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:03.265166Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:03.286342Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:03.285817Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:03.265865Z"
|
||
}
|
||
},
|
||
"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": 48,
|
||
"id": "8a7cb3b0-d7be-44ac-a1ec-40bdcf29e83b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:06.224468Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:06.223694Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:06.252031Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:06.251436Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:06.224396Z"
|
||
}
|
||
},
|
||
"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": 49,
|
||
"id": "c5bb03ca-b7ee-4564-b425-8513e1bff081",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:09.675597Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:09.674880Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:09.702379Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:09.701740Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:09.675531Z"
|
||
}
|
||
},
|
||
"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": 50,
|
||
"id": "bf333998-230c-4365-aadc-b0d1be073b39",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:12.871382Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:12.870644Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:12.898189Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:12.897568Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:12.871316Z"
|
||
}
|
||
},
|
||
"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": 51,
|
||
"id": "352c6c29-8929-4210-84c5-8dbc3d5ffeee",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:17.234892Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:17.234077Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:17.258666Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:17.258170Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:17.234829Z"
|
||
}
|
||
},
|
||
"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": 52,
|
||
"id": "97f5a1cf-341e-4b99-9549-b6a3fb165849",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T05:53:21.152478Z",
|
||
"iopub.status.busy": "2024-11-05T05:53:21.151702Z",
|
||
"iopub.status.idle": "2024-11-05T05:53:21.181419Z",
|
||
"shell.execute_reply": "2024-11-05T05:53:21.180858Z",
|
||
"shell.execute_reply.started": "2024-11-05T05:53:21.152407Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"采购中心 3.39 20\n",
|
||
"炼油三部 3.2 30\n",
|
||
"烯烃一部 3.21 156\n",
|
||
"炼油五部 3.25 73\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.26 113\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.25 26\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",
|
||
" if n>0:\n",
|
||
" print(item,round(score/n,2),n)\n",
|
||
" else:\n",
|
||
" print(item,0,n)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "85b3a695-86db-4aec-95f4-33f3b628e548",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 按照部门计算平均成绩(男性)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 54,
|
||
"id": "3beaab27-ca90-4e09-b2d2-590fd7bac51d",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T06:04:56.213828Z",
|
||
"iopub.status.busy": "2024-11-05T06:04:56.213049Z",
|
||
"iopub.status.idle": "2024-11-05T06:04:56.234107Z",
|
||
"shell.execute_reply": "2024-11-05T06:04:56.233502Z",
|
||
"shell.execute_reply.started": "2024-11-05T06:04:56.213755Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"采购中心 3.22 12\n",
|
||
"炼油三部 3.09 23\n",
|
||
"烯烃一部 3.2 128\n",
|
||
"炼油五部 3.3 56\n",
|
||
"公用工程二部 3.24 57\n",
|
||
"合成材料部 3.05 44\n",
|
||
"质管中心 3.19 43\n",
|
||
"储运一部 3.06 67\n",
|
||
"氢能制造部 3.15 46\n",
|
||
"电气中心 3.13 36\n",
|
||
"公用工程一部 3.1 63\n",
|
||
"仪表和计量中心 3.23 64\n",
|
||
"港储部 3.1 28\n",
|
||
"炼油二部 3.24 49\n",
|
||
"消防支队 3.4 21\n",
|
||
"烯烃二部 2.98 35\n",
|
||
"炼油一部 3.26 36\n",
|
||
"事务中心 3.06 28\n",
|
||
"公司机关 3.22 87\n",
|
||
"化学制品部 3.26 34\n",
|
||
"项目管理部 3.31 9\n",
|
||
"新材料研究院 3.29 12\n",
|
||
"炼油四部 3.06 23\n",
|
||
"油库中心 3.19 18\n",
|
||
"炼油六部 3.08 27\n",
|
||
"储运二部 3.06 11\n",
|
||
"炼油七部 3.21 17\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'] and v['sex'] == '男':\n",
|
||
" score = score + v['score']\n",
|
||
" n = n +1 \n",
|
||
" if n>0:\n",
|
||
" print(item,round(score/n,2),n)\n",
|
||
" else:\n",
|
||
" print(item,0,n)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d8e995d6-3ddb-4b92-8255-530e8a3da179",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算部门成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 58,
|
||
"id": "a959c1b8-86fc-4fca-8595-4278135e95b8",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T06:14:31.595277Z",
|
||
"iopub.status.busy": "2024-11-05T06:14:31.594514Z",
|
||
"iopub.status.idle": "2024-11-05T06:14:31.631931Z",
|
||
"shell.execute_reply": "2024-11-05T06:14:31.631345Z",
|
||
"shell.execute_reply.started": "2024-11-05T06:14:31.595202Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"采购中心\n",
|
||
"BMI 86 20\n",
|
||
"肺活量 72 20\n",
|
||
"握力 59 20\n",
|
||
"坐位体前屈 63 20\n",
|
||
"纵跳 71 20\n",
|
||
"俯卧撑 47 12\n",
|
||
"一分钟仰卧起坐 35 8\n",
|
||
"单脚站立 47 20\n",
|
||
"选择反应时 68 20\n",
|
||
"台阶指数 62 20\n",
|
||
"炼油三部\n",
|
||
"BMI 116 30\n",
|
||
"肺活量 99 30\n",
|
||
"握力 91 30\n",
|
||
"坐位体前屈 84 30\n",
|
||
"纵跳 92 29\n",
|
||
"俯卧撑 92 22\n",
|
||
"一分钟仰卧起坐 29 7\n",
|
||
"单脚站立 78 30\n",
|
||
"选择反应时 85 29\n",
|
||
"台阶指数 86 29\n",
|
||
"烯烃一部\n",
|
||
"BMI 584 156\n",
|
||
"肺活量 547 156\n",
|
||
"握力 517 156\n",
|
||
"坐位体前屈 461 153\n",
|
||
"纵跳 541 147\n",
|
||
"俯卧撑 454 123\n",
|
||
"一分钟仰卧起坐 84 21\n",
|
||
"单脚站立 401 156\n",
|
||
"选择反应时 430 151\n",
|
||
"台阶指数 363 145\n",
|
||
"炼油五部\n",
|
||
"BMI 297 73\n",
|
||
"肺活量 261 73\n",
|
||
"握力 240 73\n",
|
||
"坐位体前屈 208 72\n",
|
||
"纵跳 265 72\n",
|
||
"俯卧撑 206 56\n",
|
||
"一分钟仰卧起坐 48 12\n",
|
||
"单脚站立 184 73\n",
|
||
"选择反应时 210 69\n",
|
||
"台阶指数 173 69\n",
|
||
"公用工程二部\n",
|
||
"BMI 296 72\n",
|
||
"肺活量 238 72\n",
|
||
"握力 243 72\n",
|
||
"坐位体前屈 212 71\n",
|
||
"纵跳 226 69\n",
|
||
"俯卧撑 204 55\n",
|
||
"一分钟仰卧起坐 54 12\n",
|
||
"单脚站立 189 72\n",
|
||
"选择反应时 206 68\n",
|
||
"台阶指数 191 68\n",
|
||
"合成材料部\n",
|
||
"BMI 217 55\n",
|
||
"肺活量 186 55\n",
|
||
"握力 178 53\n",
|
||
"坐位体前屈 149 55\n",
|
||
"纵跳 180 55\n",
|
||
"俯卧撑 164 44\n",
|
||
"一分钟仰卧起坐 43 10\n",
|
||
"单脚站立 137 55\n",
|
||
"选择反应时 146 54\n",
|
||
"台阶指数 129 55\n",
|
||
"质管中心\n",
|
||
"BMI 248 56\n",
|
||
"肺活量 197 56\n",
|
||
"握力 177 56\n",
|
||
"坐位体前屈 149 55\n",
|
||
"纵跳 172 52\n",
|
||
"俯卧撑 141 39\n",
|
||
"一分钟仰卧起坐 49 11\n",
|
||
"单脚站立 136 56\n",
|
||
"选择反应时 151 50\n",
|
||
"台阶指数 141 51\n",
|
||
"储运一部\n",
|
||
"BMI 324 82\n",
|
||
"肺活量 278 82\n",
|
||
"握力 263 82\n",
|
||
"坐位体前屈 219 80\n",
|
||
"纵跳 239 78\n",
|
||
"俯卧撑 218 64\n",
|
||
"一分钟仰卧起坐 45 10\n",
|
||
"单脚站立 201 81\n",
|
||
"选择反应时 227 81\n",
|
||
"台阶指数 209 78\n",
|
||
"氢能制造部\n",
|
||
"BMI 231 59\n",
|
||
"肺活量 214 59\n",
|
||
"握力 190 59\n",
|
||
"坐位体前屈 180 59\n",
|
||
"纵跳 188 58\n",
|
||
"俯卧撑 160 45\n",
|
||
"一分钟仰卧起坐 52 13\n",
|
||
"单脚站立 160 59\n",
|
||
"选择反应时 145 55\n",
|
||
"台阶指数 147 58\n",
|
||
"电气中心\n",
|
||
"BMI 185 45\n",
|
||
"肺活量 158 44\n",
|
||
"握力 137 45\n",
|
||
"坐位体前屈 132 44\n",
|
||
"纵跳 130 42\n",
|
||
"俯卧撑 129 36\n",
|
||
"一分钟仰卧起坐 24 6\n",
|
||
"单脚站立 109 45\n",
|
||
"选择反应时 136 44\n",
|
||
"台阶指数 92 42\n",
|
||
"公用工程一部\n",
|
||
"BMI 307 81\n",
|
||
"肺活量 286 81\n",
|
||
"握力 268 81\n",
|
||
"坐位体前屈 226 80\n",
|
||
"纵跳 262 77\n",
|
||
"俯卧撑 223 63\n",
|
||
"一分钟仰卧起坐 64 16\n",
|
||
"单脚站立 194 81\n",
|
||
"选择反应时 211 77\n",
|
||
"台阶指数 173 73\n",
|
||
"仪表和计量中心\n",
|
||
"BMI 323 81\n",
|
||
"肺活量 302 81\n",
|
||
"握力 273 81\n",
|
||
"坐位体前屈 242 79\n",
|
||
"纵跳 302 81\n",
|
||
"俯卧撑 231 63\n",
|
||
"一分钟仰卧起坐 51 12\n",
|
||
"单脚站立 221 81\n",
|
||
"选择反应时 230 79\n",
|
||
"台阶指数 186 80\n",
|
||
"港储部\n",
|
||
"BMI 142 36\n",
|
||
"肺活量 133 36\n",
|
||
"握力 119 36\n",
|
||
"坐位体前屈 100 36\n",
|
||
"纵跳 114 36\n",
|
||
"俯卧撑 98 28\n",
|
||
"一分钟仰卧起坐 15 4\n",
|
||
"单脚站立 86 36\n",
|
||
"选择反应时 94 35\n",
|
||
"台阶指数 88 33\n",
|
||
"炼油二部\n",
|
||
"BMI 250 60\n",
|
||
"肺活量 211 60\n",
|
||
"握力 196 60\n",
|
||
"坐位体前屈 169 60\n",
|
||
"纵跳 203 57\n",
|
||
"俯卧撑 184 49\n",
|
||
"一分钟仰卧起坐 47 11\n",
|
||
"单脚站立 163 60\n",
|
||
"选择反应时 183 59\n",
|
||
"台阶指数 145 58\n",
|
||
"消防支队\n",
|
||
"BMI 99 25\n",
|
||
"肺活量 81 25\n",
|
||
"握力 87 25\n",
|
||
"坐位体前屈 76 25\n",
|
||
"纵跳 92 25\n",
|
||
"俯卧撑 87 20\n",
|
||
"一分钟仰卧起坐 14 3\n",
|
||
"单脚站立 70 25\n",
|
||
"选择反应时 69 25\n",
|
||
"台阶指数 72 25\n",
|
||
"烯烃二部\n",
|
||
"BMI 154 42\n",
|
||
"肺活量 149 42\n",
|
||
"握力 133 42\n",
|
||
"坐位体前屈 114 42\n",
|
||
"纵跳 132 41\n",
|
||
"俯卧撑 115 34\n",
|
||
"一分钟仰卧起坐 32 7\n",
|
||
"单脚站立 102 42\n",
|
||
"选择反应时 105 41\n",
|
||
"台阶指数 95 41\n",
|
||
"炼油一部\n",
|
||
"BMI 176 42\n",
|
||
"肺活量 140 42\n",
|
||
"握力 141 42\n",
|
||
"坐位体前屈 127 41\n",
|
||
"纵跳 129 37\n",
|
||
"俯卧撑 133 36\n",
|
||
"一分钟仰卧起坐 16 5\n",
|
||
"单脚站立 117 42\n",
|
||
"选择反应时 116 41\n",
|
||
"台阶指数 103 36\n",
|
||
"事务中心\n",
|
||
"BMI 149 35\n",
|
||
"肺活量 115 35\n",
|
||
"握力 103 35\n",
|
||
"坐位体前屈 106 34\n",
|
||
"纵跳 105 34\n",
|
||
"俯卧撑 83 27\n",
|
||
"一分钟仰卧起坐 30 6\n",
|
||
"单脚站立 99 34\n",
|
||
"选择反应时 100 33\n",
|
||
"台阶指数 72 30\n",
|
||
"公司机关\n",
|
||
"BMI 439 113\n",
|
||
"肺活量 405 113\n",
|
||
"握力 361 113\n",
|
||
"坐位体前屈 335 112\n",
|
||
"纵跳 394 111\n",
|
||
"俯卧撑 332 86\n",
|
||
"一分钟仰卧起坐 88 19\n",
|
||
"单脚站立 297 107\n",
|
||
"选择反应时 322 107\n",
|
||
"台阶指数 232 104\n",
|
||
"化学制品部\n",
|
||
"BMI 171 43\n",
|
||
"肺活量 158 43\n",
|
||
"握力 149 43\n",
|
||
"坐位体前屈 132 42\n",
|
||
"纵跳 150 42\n",
|
||
"俯卧撑 131 34\n",
|
||
"一分钟仰卧起坐 32 7\n",
|
||
"单脚站立 104 43\n",
|
||
"选择反应时 116 42\n",
|
||
"台阶指数 114 41\n",
|
||
"项目管理部\n",
|
||
"BMI 85 19\n",
|
||
"肺活量 68 19\n",
|
||
"握力 57 19\n",
|
||
"坐位体前屈 60 19\n",
|
||
"纵跳 57 18\n",
|
||
"俯卧撑 29 7\n",
|
||
"一分钟仰卧起坐 44 10\n",
|
||
"单脚站立 57 18\n",
|
||
"选择反应时 59 19\n",
|
||
"台阶指数 46 18\n",
|
||
"新材料研究院\n",
|
||
"BMI 61 15\n",
|
||
"肺活量 56 15\n",
|
||
"握力 47 15\n",
|
||
"坐位体前屈 48 15\n",
|
||
"纵跳 56 15\n",
|
||
"俯卧撑 39 12\n",
|
||
"一分钟仰卧起坐 14 3\n",
|
||
"单脚站立 45 15\n",
|
||
"选择反应时 43 15\n",
|
||
"台阶指数 37 15\n",
|
||
"炼油四部\n",
|
||
"BMI 103 27\n",
|
||
"肺活量 83 27\n",
|
||
"握力 86 27\n",
|
||
"坐位体前屈 75 27\n",
|
||
"纵跳 77 27\n",
|
||
"俯卧撑 83 23\n",
|
||
"一分钟仰卧起坐 12 3\n",
|
||
"单脚站立 78 27\n",
|
||
"选择反应时 84 27\n",
|
||
"台阶指数 61 26\n",
|
||
"油库中心\n",
|
||
"BMI 113 25\n",
|
||
"肺活量 90 25\n",
|
||
"握力 67 23\n",
|
||
"坐位体前屈 73 25\n",
|
||
"纵跳 66 23\n",
|
||
"俯卧撑 54 15\n",
|
||
"一分钟仰卧起坐 32 7\n",
|
||
"单脚站立 70 25\n",
|
||
"选择反应时 71 24\n",
|
||
"台阶指数 50 21\n",
|
||
"炼油六部\n",
|
||
"BMI 139 33\n",
|
||
"肺活量 118 34\n",
|
||
"握力 109 34\n",
|
||
"坐位体前屈 93 33\n",
|
||
"纵跳 109 32\n",
|
||
"俯卧撑 93 27\n",
|
||
"一分钟仰卧起坐 29 7\n",
|
||
"单脚站立 78 34\n",
|
||
"选择反应时 86 33\n",
|
||
"台阶指数 67 32\n",
|
||
"储运二部\n",
|
||
"BMI 45 13\n",
|
||
"肺活量 49 13\n",
|
||
"握力 45 13\n",
|
||
"坐位体前屈 39 12\n",
|
||
"纵跳 41 13\n",
|
||
"俯卧撑 37 11\n",
|
||
"一分钟仰卧起坐 8 2\n",
|
||
"单脚站立 33 13\n",
|
||
"选择反应时 35 13\n",
|
||
"台阶指数 29 13\n",
|
||
"炼油七部\n",
|
||
"BMI 112 26\n",
|
||
"肺活量 102 26\n",
|
||
"握力 92 26\n",
|
||
"坐位体前屈 75 25\n",
|
||
"纵跳 82 25\n",
|
||
"俯卧撑 59 16\n",
|
||
"一分钟仰卧起坐 33 8\n",
|
||
"单脚站立 68 26\n",
|
||
"选择反应时 71 26\n",
|
||
"台阶指数 52 25\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数'] \n",
|
||
"filename = 'data/data_镇海(合并).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",
|
||
"dict3 = {}\n",
|
||
"\n",
|
||
"for k, v in dict1.items():\n",
|
||
" unit = v['unit']\n",
|
||
" dict3.setdefault(unit,{})\n",
|
||
" for item in items:\n",
|
||
" dict3[unit].setdefault(item,{})\n",
|
||
" dict3[unit][item].setdefault('score',0)\n",
|
||
" dict3[unit][item].setdefault('count',0)\n",
|
||
" for k1,v1 in v['fits'].items():\n",
|
||
" if k1 in items:\n",
|
||
" dict3[unit][k1]['score']+=v1['score']\n",
|
||
" dict3[unit][k1]['count']+=1\n",
|
||
"\n",
|
||
"for k, v in dict3.items():\n",
|
||
" print(k)\n",
|
||
" for k1, v1 in v.items():\n",
|
||
" print(k1,v1['score'],v1['count'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "7092779e-ce30-4d1c-8e7b-a14011daee93",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 计算部门等级"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 57,
|
||
"id": "81195537-5a43-4822-a1b9-a08b7baee05e",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-11-05T06:08:58.060156Z",
|
||
"iopub.status.busy": "2024-11-05T06:08:58.059475Z",
|
||
"iopub.status.idle": "2024-11-05T06:08:58.086227Z",
|
||
"shell.execute_reply": "2024-11-05T06:08:58.085428Z",
|
||
"shell.execute_reply.started": "2024-11-05T06:08:58.060082Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"采购中心 5 7 8 0\n",
|
||
"炼油三部 3 9 18 0\n",
|
||
"烯烃一部 31 36 74 15\n",
|
||
"炼油五部 15 22 26 10\n",
|
||
"公用工程二部 10 29 28 5\n",
|
||
"合成材料部 3 20 25 7\n",
|
||
"质管中心 8 24 17 7\n",
|
||
"储运一部 8 23 38 13\n",
|
||
"氢能制造部 10 16 27 6\n",
|
||
"电气中心 1 20 21 3\n",
|
||
"公用工程一部 12 22 34 13\n",
|
||
"仪表和计量中心 18 25 32 6\n",
|
||
"港储部 6 5 24 1\n",
|
||
"炼油二部 7 25 26 2\n",
|
||
"消防支队 6 10 7 2\n",
|
||
"烯烃二部 7 10 15 10\n",
|
||
"炼油一部 7 12 22 1\n",
|
||
"事务中心 6 10 14 5\n",
|
||
"公司机关 22 38 42 11\n",
|
||
"化学制品部 9 13 19 2\n",
|
||
"项目管理部 3 8 8 0\n",
|
||
"新材料研究院 2 8 5 0\n",
|
||
"炼油四部 3 6 14 4\n",
|
||
"油库中心 4 11 7 3\n",
|
||
"炼油六部 3 9 17 5\n",
|
||
"储运二部 1 4 7 1\n",
|
||
"炼油七部 5 9 10 2\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"items = ['优秀','良好','合格','不合格'] \n",
|
||
"filename = 'data/data_镇海(合并).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"\n",
|
||
"dict3 = {}\n",
|
||
"for k, v in dict1.items():\n",
|
||
" unit = v['unit']\n",
|
||
" dict3.setdefault(unit,{})\n",
|
||
" for item in items:\n",
|
||
" dict3[unit].setdefault(item,0)\n",
|
||
"\n",
|
||
"for k, v in dict1.items():\n",
|
||
" unit = v['unit']\n",
|
||
" #dict3.setdefault(unit,{})\n",
|
||
" #for item in items:\n",
|
||
" #dict3[unit].setdefault(v['level'],0)\n",
|
||
" dict3[unit][v['level']] +=1\n",
|
||
"for k, v in dict3.items():\n",
|
||
" print(k,v['优秀'],v['良好'],v['合格'],v['不合格'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "8fa4c148-3bba-4bb5-b140-a6f1642c42a0",
|
||
"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
|
||
}
|