874 lines
26 KiB
Plaintext
874 lines
26 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "28695364-38de-442e-818d-cfab45902763",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导入人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2f2feca4-e0bf-4d68-af95-d3cfe5ac28bb",
|
|
"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",
|
|
"\n",
|
|
"\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": "76caa442-de4f-41eb-8743-b4a9d6c749d0",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取人员测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ab77e97a-de62-44dc-874e-72e9c8aaecf2",
|
|
"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",
|
|
"#print(\"\\n运动项目信息:\")\n",
|
|
"filename = 'data/141.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[4])\n",
|
|
" m_item = str(result[0]) \n",
|
|
" re_ta.setdefault(user,{}) \n",
|
|
" re_ta[user]['name'] = str(result[6])\n",
|
|
" re_ta[user]['unit'] = str(result[5]) \n",
|
|
" item_name = item[m_item]['name']\n",
|
|
" re_ta[user].setdefault(item_name,{}) \n",
|
|
" score = int(result[1])/item[m_item]['divisor'] \n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
" re_ta[user][item_name]['得分'] =result[2]\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": "6fc0bfbd-a5cd-4720-bc66-14d74d730fc7",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 获取人员测试成绩(新格式)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4ffa6cd8-98a2-4975-af00-8647a0888bdd",
|
|
"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",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"list1 = []\n",
|
|
"#print(\"\\n运动项目信息:\")\n",
|
|
"filename = 'data/141.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",
|
|
"list2 = []\n",
|
|
"re_ta = {}\n",
|
|
"for result in list1:\n",
|
|
" user = str(result[4])\n",
|
|
" m_item = str(result[0]) \n",
|
|
" re_ta.setdefault(user,{}) \n",
|
|
" re_ta[user]['name'] = str(result[6])\n",
|
|
" re_ta[user]['unit'] = str(result[5]) \n",
|
|
" item_name = item[m_item]['name']\n",
|
|
" re_ta[user].setdefault(item_name,{}) \n",
|
|
" score = int(result[1])/item[m_item]['divisor'] \n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
" re_ta[user][item_name]['得分'] =result[2]\n",
|
|
"for k, v in re_ta.items():\n",
|
|
" dict2 = {}\n",
|
|
" dict2['code'] = k\n",
|
|
" for k1, v1 in v.items():\n",
|
|
" dict2[k1] = v1\n",
|
|
" list2.append(dict2)\n",
|
|
"dict3 = {}\n",
|
|
"dict3['result'] = list2\n",
|
|
"filename = 'data/result_东营石油工程设计院(new).json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict3, fl) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c4107446-c0c6-4d76-9062-284ff806ec86",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ee6db59f-dcc3-4a85-8dba-2e212c2b5be0",
|
|
"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/东营工程设计院人员名单.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": "code",
|
|
"execution_count": null,
|
|
"id": "579fd3c1-7fe3-49ef-8875-0d823b7d0546",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\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",
|
|
"#SQL语句为:\n",
|
|
"#SELECT a.item_id,a.performance,a.score,a.date AS DATE1,a.avatar_id,b.unit,b.name,a.date_joined FROM places_result AS a,_tianjin AS b WHERE a.place_id=134 AND a.avatar_id=b.id\n",
|
|
"filename = 'data/东营工程设计院人员名单.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl) \n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"#print(\"\\n运动项目信息:\")\n",
|
|
"filename = 'data/141.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",
|
|
"dict3 = {}\n",
|
|
"for result in list1:\n",
|
|
" user = result[2]\n",
|
|
" if user in dict2.keys():\n",
|
|
" dict3.setdefault(user,{}) \n",
|
|
" dict3[user]['name'] = dict2[user]['name']\n",
|
|
" dict3[user]['unit'] = dict2[user]['unit']\n",
|
|
"\n",
|
|
"print(len(dict3))\n",
|
|
"list1 = []\n",
|
|
"for k, v in dict3.items():\n",
|
|
" list2 = [k,v['name'],v['unit']]\n",
|
|
" list1.append(list2)\n",
|
|
"filename = 'data/东营工程设计院参加测试人员情况表.xlsx'\n",
|
|
"wb = openpyxl.Workbook()\n",
|
|
"sheet = wb.active\n",
|
|
"\n",
|
|
"for row in list1:\n",
|
|
" sheet.append(row)\n",
|
|
" \n",
|
|
"wb.save(filename) \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "441db522-6774-4868-bb43-3de8ffc3f1ef",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 体测报告更名按部门分组"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3a26fdfb-b28f-42c9-9479-57e210c0b8ae",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import math\n",
|
|
"import openpyxl\n",
|
|
"wb = openpyxl.load_workbook('data/东营工程设计院参加测试人员情况表.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"dict1 = {}\n",
|
|
"list_bh = []\n",
|
|
"depart = []\n",
|
|
"for n in range(1,sheet.max_row+1):\n",
|
|
" dict1.setdefault(sheet.cell(n, 1).value,{}) \n",
|
|
" m_depart = sheet.cell(n, 3).value\n",
|
|
" dict1[sheet.cell(n, 1).value]['unit'] = m_depart\n",
|
|
" dict1[sheet.cell(n, 1).value]['name'] = sheet.cell(n, 2).value\n",
|
|
" if m_depart not in depart:\n",
|
|
" depart.append(m_depart)\n",
|
|
"old = []\n",
|
|
"\n",
|
|
" \n",
|
|
"fi_path = 'file/141'\n",
|
|
"\n",
|
|
"\n",
|
|
"# 创建部门办公室 \n",
|
|
"m_path = 'file/141/new'\n",
|
|
"for pn in depart:\n",
|
|
" if not os.path.exists(m_path + '/' + pn):\n",
|
|
" os.mkdir(m_path + '/' + pn)\n",
|
|
"fl=os.listdir(fi_path)\n",
|
|
"for fn in fl:\n",
|
|
" if os.path.isfile(fi_path + '/' + fn):\n",
|
|
" ofn = int(fn.split('.')[0])\n",
|
|
" old.append(ofn) \n",
|
|
"old.sort()\n",
|
|
"for n in old: \n",
|
|
" o_name = f'{fi_path}/{n}.pdf'\n",
|
|
" unit = dict1[str(n)]['unit']\n",
|
|
" name = dict1[str(n)]['name']\n",
|
|
" n_name = f'{m_path}/{unit}/{str(n).rjust(5,\"0\")}-{name}.pdf'\n",
|
|
" #print(o_name,n_name)\n",
|
|
" if not os.path.exists(n_name):\n",
|
|
" shutil.copyfile(o_name,n_name)\n",
|
|
" print(n_name)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6f372af-b4a6-4815-b251-d15ff26ee480",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 体测报告分析"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7a23d436-a49f-4e39-bbf3-bf92be6ea072",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 获取人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e6aed1b3-5825-4aed-83ec-08c50c5276f1",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import pymysql\n",
|
|
"import datetime\n",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"dict2 = {}\n",
|
|
"dict3 = {}\n",
|
|
"\n",
|
|
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
|
"cursor = db.cursor()\n",
|
|
"sql = \"SELECT b.avatar_id, a.name ,a.sex,a.birth FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 141\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"results = cursor.fetchall()\n",
|
|
"for result in results:\n",
|
|
" bh = result[0]\n",
|
|
" \n",
|
|
" name = str(result[1]).strip()\n",
|
|
" dict2.setdefault(bh,{})\n",
|
|
" dict2[bh]['name'] = name\n",
|
|
" dict2[bh]['sex'] = result[2]\n",
|
|
" #dict2[bh]['birth'] = result[3]\n",
|
|
" #print(result[3])\n",
|
|
" days = (datetime.date(2023, 3, 6)-result[3]).days\n",
|
|
" dict2[bh]['age'] = round(days/365)\n",
|
|
"\n",
|
|
"filename = 'data/东营工程设计院人员信息.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(dict2, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "300ffd45-7bb4-4e8f-bfb1-d0a5114f396f",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 获取人员及体测成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "34cc0d44-7567-4263-9fa2-3fc47d643f00",
|
|
"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",
|
|
"#SQL语句为:\n",
|
|
"#SELECT a.item_id,a.performance,a.score,a.date AS DATE1,a.avatar_id,b.unit,b.name,a.date_joined FROM places_result AS a,_tianjin AS b WHERE a.place_id=134 AND a.avatar_id=b.id\n",
|
|
"\n",
|
|
"re_ta = {}\n",
|
|
"dict1 = {}\n",
|
|
"list1 = []\n",
|
|
"#print(\"\\n运动项目信息:\")\n",
|
|
"filename = 'data/141.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[4])\n",
|
|
" m_item = str(result[0]) \n",
|
|
" re_ta.setdefault(user,{}) \n",
|
|
" re_ta[user]['name'] = str(result[6])\n",
|
|
" re_ta[user]['unit'] = str(result[5]) \n",
|
|
" item_name = item[m_item]['name']\n",
|
|
" re_ta[user].setdefault(item_name,{}) \n",
|
|
" score = int(result[1])/item[m_item]['divisor'] \n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
" re_ta[user][item_name]['得分'] =result[2]\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": "908b8339-07bf-48a9-b8f3-327c79e38a28",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 汇总人员信息及成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "83c471e6-f2af-4ec8-abc2-a9dfa2de5e22",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"filename = 'data/result_东营设计院.json'\n",
|
|
"\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",
|
|
"for k,v in dict1.items():\n",
|
|
" print(k)\n",
|
|
" score = 0\n",
|
|
" i = 0\n",
|
|
" for k1,v1 in v.items():\n",
|
|
" \n",
|
|
" \n",
|
|
" if k1 in items:\n",
|
|
" score = score + int(v1['得分'])\n",
|
|
" i+=1\n",
|
|
" \n",
|
|
" dict1[k]['age'] = dict2[k]['age']\n",
|
|
" dict1[k]['sex'] = dict2[k]['sex']\n",
|
|
" dict1[k]['score'] = round(score/i,2)\n",
|
|
" \n",
|
|
"filename = 'data/result_东营设计院.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "dce39907-39cd-40ec-8588-2ec6a15c3aa2",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 根据年龄汇总人员信息及成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e1d9be91-7201-435b-8683-838056beca42",
|
|
"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'] == 0:\n",
|
|
" m = m +1\n",
|
|
" \n",
|
|
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人,男性:{m}人')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5b78012f-35c2-4b1d-a3e7-5b332e7c4b66",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算平均成绩及等级"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "785620af-e60c-4f17-b261-cae1de7240b2",
|
|
"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",
|
|
"\n",
|
|
"i = 1\n",
|
|
"score = 0\n",
|
|
"\n",
|
|
"m = 0\n",
|
|
"f = 0\n",
|
|
"for k,v in dict1.items():\n",
|
|
" if v['sex'] == 0:\n",
|
|
" m = m+v['score']\n",
|
|
" else:\n",
|
|
" f = f+v['score']\n",
|
|
" score = score + v['score']\n",
|
|
"\n",
|
|
"print(f'平均成绩:{round(score/336,2)}分,男性:{round(m/203,2)}分,女性:{round(f/133,2)}')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "17e9be28-563c-46ee-a457-51deb085cb55",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算测试等级"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "aa32ab25-6cb7-4a1b-87f9-5ec2b11d9715",
|
|
"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",
|
|
"filename = 'data/result_东营设计院.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \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'] == 0:\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": "5a07a92d-b81f-42f0-b3d0-13d1c452781a",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算各年龄段测试等级(男)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1759fc30-f390-4ed1-8d48-5eacc050e18f",
|
|
"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'] == 0:\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": "c91526fb-8686-49b8-8fee-bbcf8a932952",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算各年龄段测试等级(女)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b7b44be3-8cf1-48e6-a4a6-adfccdb8c0a9",
|
|
"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'] == 1:\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": "4fdbe127-494d-463b-8dc2-4c5126a48dcc",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 按照部门计算平均成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "975bb98b-a00c-4a34-b9a3-fe9975c12641",
|
|
"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": "1d5eb757-3dc0-407d-9281-23fa3de037e2",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算各项目成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f51baed5-8d03-4d33-8d68-37ac13f9a47d",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"for item in items:\n",
|
|
" score = 0\n",
|
|
" n = 0\n",
|
|
" for k, v in dict1.items():\n",
|
|
" if item in v.keys():\n",
|
|
" n = n + 1\n",
|
|
" score =score + int(v[item]['得分'])\n",
|
|
" print(item,round(score/n,2))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "adb043d9-4e1f-49eb-b051-84e4efbc3c72",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 使用JMESPath查询"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 70,
|
|
"id": "7b148f6d-0d6d-4573-9df3-ea02faab165d",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-04-15T12:32:09.317495Z",
|
|
"iopub.status.busy": "2023-04-15T12:32:09.316589Z",
|
|
"iopub.status.idle": "2023-04-15T12:32:09.333606Z",
|
|
"shell.execute_reply": "2023-04-15T12:32:09.332528Z",
|
|
"shell.execute_reply.started": "2023-04-15T12:32:09.317454Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[['张东红', '建筑设计所'], ['孙淑华', '建筑设计所'], ['靳永东', '建筑设计所'], ['张浩', '建筑设计所'], ['宁聪聪', '建筑设计所'], ['李磊', '建筑设计所'], ['尚华凯', '建筑设计所'], ['王修龙', '建筑设计所'], ['王剑', '建筑设计所'], ['李天萌', '建筑设计所'], ['崔华强', '建筑设计所'], ['王乙臻', '建筑设计所'], ['刘小燕', '建筑设计所'], ['韦盛', '建筑设计所'], ['张跃', '建筑设计所']]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from jmespath import search\n",
|
|
"filename = 'data/result_东营石油工程设计院(new).json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"unit = \"建筑设计所\"\n",
|
|
"data = search(\"result[?unit== '建筑设计所'].[name,unit]\",dict1)\n",
|
|
"print(data)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c5ef31b6-ceed-4167-bec7-58e92b3698e1",
|
|
"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
|
|
}
|