1159 lines
33 KiB
Plaintext
1159 lines
33 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "021f4ec4-47cd-433a-9d0a-91176b398f32",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "9bd78072-29e5-4c98-8bbe-97f525cf9e4a",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/student_20140922(石家庄监测花名册2023年).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"person = {}\n",
|
||
"\n",
|
||
"for n in range(2, sheet.max_row+1):\n",
|
||
" if sheet.cell(n,1).value is not None:\n",
|
||
" code = int(sheet.cell(n, 4).value)\n",
|
||
" person.setdefault(code, {})\n",
|
||
" dict1 = {}\n",
|
||
" dict1['name'] = sheet.cell(n, 6).value\n",
|
||
" if sheet.cell(n, 7).value ==1:\n",
|
||
" sex = '男'\n",
|
||
" else:\n",
|
||
" sex = '女'\n",
|
||
" dict1['sex'] = sex\n",
|
||
" dict1['unit'] = sheet.cell(n, 3).value\n",
|
||
" dict1['birth'] = sheet.cell(n, 8).value\n",
|
||
" person[code] = dict1\n",
|
||
"filename = 'data/石家庄2023.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "cb4e0b2a-a17a-470c-afcd-2a532c00f6d0",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 每日成绩导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "dd3c65ea-cc8a-4f1b-8698-d1799f99e101",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"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/石家庄2023.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20230427-sjz.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",
|
||
" \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]['部门'] = dict1[user]['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_石家庄(20230427).json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(re_ta, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a2127ef7-230f-434e-a817-3d4948ed0ca4",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 每日成绩导出"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "97d86ce2-6664-41a1-89d2-ddaa0611bac1",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"filename = 'data/石家庄2023.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",
|
||
" \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/石家庄石化体测情况表.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": "6fae0c4a-f0f6-4abe-bd3a-ea9fef87f2c6",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 总成绩导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e2b68cb1-3a6f-4b51-afbd-d6c9634348b1",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"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/石家庄2023.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20230505-sjz.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",
|
||
" \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]['部门'] = dict1[user]['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",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(re_ta, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "6adeedfe-999a-47c2-aeed-fb4467b27026",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "29ed0a03-72e1-4bee-8d00-95555f129d93",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"filename = 'data/石家庄2023.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",
|
||
" \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/石家庄石化体测情况表.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": "e5de157c-18e2-4a6a-bae8-3db88822b88f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计部门测试情况"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "57b22a08-554b-4b23-b98c-002b4608729f",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"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",
|
||
"dict2 = {}\n",
|
||
"for k, v in dict1.items():\n",
|
||
" unit = v['部门']\n",
|
||
" dict2.setdefault(unit,0)\n",
|
||
" dict2[unit] = dict2[unit] + 1\n",
|
||
"print(dict2)\n",
|
||
"title =['单位','体测人数']\n",
|
||
"list1 = [] \n",
|
||
"for k, v in dict2.items():\n",
|
||
" list2 = []\n",
|
||
" list2 = [k,v]\n",
|
||
" list1.append(list2)\n",
|
||
"filename = 'data/石家庄测试名单部门情况(20230426).xlsx'\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": "187fc3c8-46f6-4d32-9b52-38efbf2403b4",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计未测试人员名单"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "0001a577-3d89-4e3d-be07-51cc74e3640f",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"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",
|
||
"list1 = []\n",
|
||
"filename = 'data/石家庄2023.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"for k, v in dict2.items():\n",
|
||
" if k not in dict1.keys():\n",
|
||
" list1.append([k,v['name'],v['unit']])\n",
|
||
"filename = 'data/石家庄未测试名单(截至20230426).xlsx'\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"title =['测试编号','姓名','单位']\n",
|
||
"sheet.append(title)\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row)\n",
|
||
"wb.save(filename)\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e0c0ada9-1df7-4c7e-9a56-7e224c636764",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成查询文件"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e85c1be2-7859-4b7d-8f67-a9ad12d167d4",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"dict2 = {}\n",
|
||
"for k, v in dict1.items():\n",
|
||
" dict2[k] = v['name']\n",
|
||
"filename = 'data/shijiazhuang.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(dict2, fl, ensure_ascii=False)\n",
|
||
"print('ok')\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "762b7b9d-e4ee-4722-909f-aa8331168b0b",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 报告按部门分类更名"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ce2f56f9-bd85-436f-af14-844c94fa7e86",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import math\n",
|
||
"import glob\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"fi_path = 'file/2023-04-30'\n",
|
||
"old = []\n",
|
||
"dict2 = {}\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"for k, v in dict1.items():\n",
|
||
" m_name = v['name']\n",
|
||
" m_depart = v['unit'] \n",
|
||
" dict2[int(k)] = [m_name,m_depart]\n",
|
||
"\n",
|
||
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
||
"\n",
|
||
"for fn in fls:\n",
|
||
" old.append(os.path.basename(fn).split('.')[0])\n",
|
||
"\n",
|
||
"for n in old: \n",
|
||
" o_name = f'{fi_path}/{n}.pdf'\n",
|
||
" new_path = Path(fi_path,'new',dict1[n]['unit'])\n",
|
||
" new_path.mkdir(parents = True, exist_ok = True)\n",
|
||
" n_name = Path(new_path,f'{str(n).rjust(5,\"0\")}-{dict2[int(n)][0]}.pdf')\n",
|
||
" if not os.path.exists(n_name):\n",
|
||
" shutil.copyfile(o_name,n_name)\n",
|
||
" print(n_name)\n",
|
||
" \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "aa655c35-1765-4a62-aa07-a6b0e7d41c6d",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成电子文件明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"id": "0f049372-de7c-42fd-8ee3-618a894fbabc",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-05-23T07:20:54.552740Z",
|
||
"iopub.status.busy": "2023-05-23T07:20:54.551892Z",
|
||
"iopub.status.idle": "2023-05-23T07:20:54.727460Z",
|
||
"shell.execute_reply": "2023-05-23T07:20:54.726743Z",
|
||
"shell.execute_reply.started": "2023-05-23T07:20:54.552699Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"import glob\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"fi_path = 'file/2023-04-30'\n",
|
||
"old = []\n",
|
||
"dict2 = {}\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"for k, v in dict1.items(): \n",
|
||
" m_name = v['name']\n",
|
||
" m_depart = v['unit'] \n",
|
||
" dict2[int(k)] = [m_name,m_depart]\n",
|
||
" list1.append([k.rjust(5,\"0\"),m_depart,m_name])\n",
|
||
"filename = 'data/石家庄测试报告明细表.xlsx'\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"\n",
|
||
"for row in list1:\n",
|
||
" sheet.append(row)\n",
|
||
"wb.save(filename)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3a3ae88b-a59b-4403-9c98-685afe1f5268",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 数据分析"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "420510cf-c96b-4765-87c2-2911b1d4210a",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 获取清理后报告数据"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "c9e4f67a-a34d-4c81-9ed7-9099d3f283f4",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import time\n",
|
||
"import csv\n",
|
||
"\n",
|
||
"filename = '../item.json'\n",
|
||
"item = {}\n",
|
||
"unit = {}\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for k,v in dict1.items():\n",
|
||
" item[k] = v\n",
|
||
"filename = 'data/石家庄2023.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"re_ta = {}\n",
|
||
"list1 = []\n",
|
||
"#print(\"\\n运动项目信息:\")\n",
|
||
"filename = 'data/places_result_sjz.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",
|
||
" \n",
|
||
" m_item = str(result[3]) \n",
|
||
" re_ta.setdefault(user,{}) \n",
|
||
" re_ta[user]['name'] = dict1[user]['name']\n",
|
||
" re_ta[user]['unit'] = dict1[user]['unit']\n",
|
||
" re_ta[user]['sex'] = dict1[user]['sex']\n",
|
||
" re_ta[user]['birth'] = dict1[user]['birth']\n",
|
||
" item_name = item[m_item]['name']\n",
|
||
" re_ta[user].setdefault(item_name,{}) \n",
|
||
" score = int(result[4])/item[m_item]['divisor'] \n",
|
||
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
||
" re_ta[user][item_name]['得分'] =result[5]\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"print(len(re_ta))\n",
|
||
"liwai = []\n",
|
||
"for k, v in re_ta.items():\n",
|
||
" if (len(v)<8 and '身高' in v and '体重' in v) or (len(v)<7 and '身高' not in v and '体重' not in v) :\n",
|
||
" liwai.append(k)\n",
|
||
"print(liwai)\n",
|
||
"for k in liwai:\n",
|
||
" del re_ta[k]\n",
|
||
"print(len(re_ta))\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(re_ta, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "25bf52c2-0d84-4299-94af-5845d5156a93",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 核对报告"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "3a8f7e29-aff1-4a5b-b31d-1c47aaf1e2fa",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import time\n",
|
||
"import csv\n",
|
||
"import os,sys,shutil\n",
|
||
"import glob\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"m_path = 'file/2023-04-30'\n",
|
||
"old = []\n",
|
||
"fls = glob.glob(f'{m_path}/*.pdf')\n",
|
||
"for fn in fls:\n",
|
||
" #old = os.path.basename(fn).split('.')[0].rjust(8,'0') \n",
|
||
" old.append(os.path.basename(fn).split('.')[0])\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if k not in old and '身高' not in v.keys():\n",
|
||
" print(k,v,'\\n')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "54fb3c1b-b791-4502-a78f-89488d329a94",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算人员年龄"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "70a69705-908f-4c77-948c-c5c781707af5",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import datetime\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"for k, v in dict1.items():\n",
|
||
" birth = v['birth'].split()[0].split('-')\n",
|
||
" \n",
|
||
" nian = int(birth[0].strip())\n",
|
||
" yue = int(birth[1].strip())\n",
|
||
" ri = int(birth[2].strip())\n",
|
||
" #print(k,nian,yue,ri)\n",
|
||
" days = (datetime.date(2023, 4, 23)-datetime.date(nian,yue,ri)).days\n",
|
||
" v['age'] = round(days/365)\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl) \n",
|
||
"print('ok') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a3027c15-aa68-4fb9-9e23-791fa2530209",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 汇总人员信息及成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "01a1c350-ae39-4610-b97d-8bcea11cac09",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for k,v in dict1.items():\n",
|
||
" score = 0\n",
|
||
" i = 0\n",
|
||
" for k1,v1 in v.items(): \n",
|
||
" if k1 in items:\n",
|
||
" score = score + int(v1['得分'])\n",
|
||
" i+=1\n",
|
||
" dict1[k]['score'] = round(score/i,2) \n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3345d0c6-48b5-42c8-98ce-ccb66dd73f87",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算测试等级"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "69b5f5e5-04e4-4509-8518-b7fc54cd4e45",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-05-26T13:50:58.194003Z",
|
||
"iopub.status.busy": "2023-05-26T13:50:58.193208Z",
|
||
"iopub.status.idle": "2023-05-26T13:50:58.371452Z",
|
||
"shell.execute_reply": "2023-05-26T13:50:58.370543Z",
|
||
"shell.execute_reply.started": "2023-05-26T13:50:58.193961Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"0~255分人数:779人,男性:678人,女性:101人\n",
|
||
"256~332分人数:1009人,男性:786人,女性:223人\n",
|
||
"333~367分人数:316人,男性:189人,女性:127人\n",
|
||
"368~500分人数:129人,男性:57人,女性:72人\n",
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.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",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a87e51a1-e5c1-44c2-bc38-efbe108e92bb",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 根据年龄汇总人员信息及成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "cd27296f-2412-4a77-8b74-676c7d0efb30",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in nld:\n",
|
||
" di = item[0]\n",
|
||
" gao = item[1]\n",
|
||
" i = 1\n",
|
||
" score = 0\n",
|
||
" m = 0\n",
|
||
" f = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['age'] in range(di,gao+1):\n",
|
||
" score = score+v['score']\n",
|
||
" i+=1\n",
|
||
" if v['sex'] == '男':\n",
|
||
" m = m +1\n",
|
||
" \n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人,男性:{m}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "5dbdf7cf-9014-448a-ba9e-0aea8afbdd6f",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in nld:\n",
|
||
" di = item[0]\n",
|
||
" gao = item[1]\n",
|
||
" i = 1\n",
|
||
" score = 0\n",
|
||
" m = 0\n",
|
||
" f = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['age'] in range(di,gao+1) and v['sex'] == '男':\n",
|
||
" score = score+v['score']\n",
|
||
" i+=1\n",
|
||
" \n",
|
||
" \n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "cfbb33c5-6740-4226-a792-9ef32e32479e",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in nld:\n",
|
||
" di = item[0]\n",
|
||
" gao = item[1]\n",
|
||
" i = 1\n",
|
||
" score = 0\n",
|
||
" m = 0\n",
|
||
" f = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['age'] in range(di,gao+1) and v['sex'] == '女':\n",
|
||
" score = score+v['score']\n",
|
||
" i+=1\n",
|
||
" \n",
|
||
" \n",
|
||
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "fc4ba2ba-f4c7-4934-8416-500ffd60e662",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 生成平均成绩直方图"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "fb5ccc15-b5bb-4379-88fb-acd8abbe48b6",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import pygal\n",
|
||
"from pygal.style import Style\n",
|
||
"\n",
|
||
"custom_style = Style(\n",
|
||
" colors=('#9BC850', '#ffeb44', '#ff00ff'))\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"pjf = []\n",
|
||
"for k, v in dict1.items(): \n",
|
||
" pjf.append(v['score'])\n",
|
||
"pjf.sort()\n",
|
||
"bar_chart = pygal.Bar(style=custom_style)\n",
|
||
"bar_chart.add('平均分',pjf) # Add some values\n",
|
||
"bar_chart.render_to_file('bar_chart.svg') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "8e7a45fc-94d3-468f-853a-e23573333c08",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算平均成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "41714148-5130-4c83-805f-bb98dbb96dd6",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]\n",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"i = 1\n",
|
||
"m = 0\n",
|
||
"f = 0\n",
|
||
"score = 0\n",
|
||
"t_score = 0\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == '男':\n",
|
||
" m = m +1\n",
|
||
" score = score+v['score']\n",
|
||
"print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')\n",
|
||
"t_score = t_score + score\n",
|
||
"score = 0\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == '女':\n",
|
||
" f = f +1\n",
|
||
" score = score+v['score']\n",
|
||
"print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n",
|
||
"t_score = t_score + score\n",
|
||
"print(f'平均成绩:{round(t_score/2233,4)}分,女性:2233人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "4e854305-a22b-4a0a-a819-988a18424fe7",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算测试等级"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "de6fbd5b-2361-4207-8bf0-08652148b729",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/result_石家庄.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",
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c5b55f21-8f31-4ae7-a75a-4e4bb5faed66",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算各年龄段测试等级(男)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "eae7e34f-df88-4d46-bdb2-9f6bf4cfd357",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]\n",
|
||
"filename = 'data/result_石家庄.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",
|
||
"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": "83a11ed4-127e-497c-a8b0-431c7abb3840",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 按照部门计算平均成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "33bfec2f-3f0c-40b3-81f6-cbbc4a0ce4b4",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"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)\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d28e91b4-3556-47a4-81a4-a3d44777e899",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 计算各项目成绩"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "1626c578-b38d-435b-8c08-45588cd44096",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"filename = 'data/result_石家庄.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"for item in items:\n",
|
||
" score = 0\n",
|
||
" n = 0\n",
|
||
" for k, v in dict1.items():\n",
|
||
" if item in v.keys():\n",
|
||
" n = n + 1\n",
|
||
" score =score + int(v[item]['得分'])\n",
|
||
" print(item,round(score/n,2))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "25b5f474-1f2e-4d6b-a6d7-2c0427a9bcbf",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"filename = 'data/tiangongyuan.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"print(dict1)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "178b485e-8ee2-4173-b7f5-fe2e875452ab",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3 (ipykernel)",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.10.6"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|