1428 lines
43 KiB
Plaintext
1428 lines
43 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b6ce4321-f82a-4d9d-a110-44a23b95970b",
|
||
"metadata": {
|
||
"jp-MarkdownHeadingCollapsed": true
|
||
},
|
||
"source": [
|
||
"# 2023年体质检测"
|
||
]
|
||
},
|
||
{
|
||
"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": null,
|
||
"id": "7b148f6d-0d6d-4573-9df3-ea02faab165d",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"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": "markdown",
|
||
"id": "d3649684-3eab-49ad-8b3d-ebb452289e51",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 2024年体质检测"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a3f5f78e-6785-48e6-b2b6-b91b8d2aa4ca",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 46,
|
||
"id": "096e2b97-b83c-46bb-a070-c816e47da331",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-10-12T07:01:48.471770Z",
|
||
"iopub.status.busy": "2024-10-12T07:01:48.471014Z",
|
||
"iopub.status.idle": "2024-10-12T07:01:48.503168Z",
|
||
"shell.execute_reply": "2024-10-12T07:01:48.502646Z",
|
||
"shell.execute_reply.started": "2024-10-12T07:01:48.471700Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/东营石油工程设计公司(2024).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, 1).value)\n",
|
||
" person.setdefault(code, {})\n",
|
||
" dict1 = {}\n",
|
||
" dict1['name'] = sheet.cell(n, 3).value\n",
|
||
" dict1['sex'] = sheet.cell(n, 4).value\n",
|
||
" dict1['unit'] = sheet.cell(n, 2).value\n",
|
||
" if sheet.cell(n, 7).value is not None:\n",
|
||
" dict1['gh'] = sheet.cell(n, 7).value\n",
|
||
" #dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0] \n",
|
||
" if sheet.cell(n, 6).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n,6).value)\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \n",
|
||
" #dict1['gh'] = str(sheet.cell(n, 7).value)\n",
|
||
" person[code] = dict1\n",
|
||
"filename = 'data/东营工程设计院2024.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "926e4dc3-fe7a-4b8b-9330-5a9eebc8a766",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 获取人员测试成绩(新格式)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "28afeee6-43c0-4e96-b3aa-dc09c6288425",
|
||
"metadata": {},
|
||
"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/东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20240926.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]['birth'] = dict1[user]['birth'] \n",
|
||
" re_ta[user]['phone'] = dict1[user]['phone'] \n",
|
||
" re_ta[user]['gh'] = dict1[user]['gh'] \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_东营工程设计院2024.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": "78fd57de-eff7-487c-a483-3cf606127f58",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入问卷信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 47,
|
||
"id": "808e65e9-a9e3-44ea-9c0b-359375dceb3d",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-10-12T07:02:11.291002Z",
|
||
"iopub.status.busy": "2024-10-12T07:02:11.290225Z",
|
||
"iopub.status.idle": "2024-10-12T07:02:11.324427Z",
|
||
"shell.execute_reply": "2024-10-12T07:02:11.323742Z",
|
||
"shell.execute_reply.started": "2024-10-12T07:02:11.290926Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import csv\n",
|
||
"import openpyxl\n",
|
||
"import time\n",
|
||
"from datetime import date\n",
|
||
"\n",
|
||
"filename = 'data/result_东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl)\n",
|
||
"\n",
|
||
"phone = {}\n",
|
||
"for k,v in dict3.items():\n",
|
||
" if 'phone' in v.keys():\n",
|
||
" phone[v['phone']] = k\n",
|
||
"list1 = []\n",
|
||
"filename = 'data/Survey_20241008.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",
|
||
" list1.append(line)\n",
|
||
"#print(list1)\n",
|
||
"dict2 = {}\n",
|
||
"psy =[]\n",
|
||
"tcm = []\n",
|
||
"spine = []\n",
|
||
"\n",
|
||
"for i in range(0,60):\n",
|
||
" tcm.append(0)\n",
|
||
"\n",
|
||
"\n",
|
||
"for item in list1:\n",
|
||
" if item[2] in phone.keys(): \n",
|
||
" tcm = [] \n",
|
||
" for i in range(0,60):\n",
|
||
" tcm.append(0)\n",
|
||
" content = json.loads(item[5])\n",
|
||
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||
" if phone[item[2]] not in dict1.keys():\n",
|
||
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
||
" \n",
|
||
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||
" for k, v in content.items(): \n",
|
||
" if 'tcm' in k:\n",
|
||
" i = int(k[3:])\n",
|
||
" tcm[i-1] = int(v)\n",
|
||
" \n",
|
||
" if 'tcm' in item[5]:\n",
|
||
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
||
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
||
" \n",
|
||
" days = (rq-birth).days \n",
|
||
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
||
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
||
"filename = 'data/result_东营工程设计院2024_all.json'\n",
|
||
"\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl, ensure_ascii=False) "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "24b51e8b-a16b-47ac-85a1-b7037e7ce223",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计未参加问卷人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "47f53bdf-ac6a-44f1-9f5f-852eb2d61127",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import csv\n",
|
||
"import openpyxl\n",
|
||
"import time\n",
|
||
"from datetime import date\n",
|
||
"\n",
|
||
"filename = 'data/result_东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl)\n",
|
||
"\n",
|
||
"phone = {}\n",
|
||
"for k,v in dict3.items():\n",
|
||
" if 'phone' in v.keys():\n",
|
||
" phone[v['phone']] = k\n",
|
||
"list1 = []\n",
|
||
"filename = 'data/Survey_20241008.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",
|
||
" list1.append(line)\n",
|
||
"#print(list1)\n",
|
||
"dict2 = {}\n",
|
||
"tcm = []\n",
|
||
"for item in list1:\n",
|
||
" if item[2] in phone.keys(): \n",
|
||
" tcm = [] \n",
|
||
" for i in range(0,60):\n",
|
||
" tcm.append(0)\n",
|
||
" content = json.loads(item[5])\n",
|
||
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||
" if phone[item[2]] not in dict1.keys():\n",
|
||
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
||
" \n",
|
||
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||
" for k, v in content.items(): \n",
|
||
" if 'tcm' in k:\n",
|
||
" i = int(k[3:])\n",
|
||
" tcm[i-1] = int(v)\n",
|
||
" \n",
|
||
" if 'tcm' in item[5]:\n",
|
||
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
||
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
||
" \n",
|
||
" days = (rq-birth).days \n",
|
||
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
||
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
||
" else:\n",
|
||
" print(item[2])\n",
|
||
"filename = 'data/result_东营工程设计院2024_all.json'\n",
|
||
"\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl, ensure_ascii=False) "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "c633a37c-0f0e-4b81-83cb-a9fa49efbe36",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import csv\n",
|
||
"import openpyxl\n",
|
||
"import time\n",
|
||
"from datetime import date\n",
|
||
"\n",
|
||
"filename = 'data/result_东营工程设计院2024_all.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"i = 1\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if 'tcm' not in v.keys():\n",
|
||
" print(i,k,v['name'])\n",
|
||
" i+=1"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "3f68bad7-e2ba-47e1-9ae0-08fce2ad79d1",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import csv\n",
|
||
"import openpyxl\n",
|
||
"import time\n",
|
||
"from datetime import date\n",
|
||
"\n",
|
||
"filename = 'data/result_东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/东营工程设计院2024.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl)\n",
|
||
"\n",
|
||
"phone = {}\n",
|
||
"for k,v in dict3.items():\n",
|
||
" if 'phone' in v.keys():\n",
|
||
" phone[v['phone']] = k\n",
|
||
"list1 = []\n",
|
||
"filename = 'data/Survey_20241008.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",
|
||
" list1.append(line)\n",
|
||
"for item in list1:\n",
|
||
" if item[2] in phone.keys() and phone[item[2]] not in dict1.keys(): \n",
|
||
" print(phone[item[2]])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "f13c93bc-dc11-455f-b90f-07ebabfb0d5a",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导出带得分体测情况明细表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"id": "5cb11459-4719-4cbf-9735-510436b8bd49",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-10-16T05:59:47.130519Z",
|
||
"iopub.status.busy": "2024-10-16T05:59:47.129808Z",
|
||
"iopub.status.idle": "2024-10-16T05:59:47.178226Z",
|
||
"shell.execute_reply": "2024-10-16T05:59:47.177645Z",
|
||
"shell.execute_reply.started": "2024-10-16T05:59:47.130453Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"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_东营工程设计院2024.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]['age'])\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": "4c2bb4c7-a884-4ade-a6a5-b080dc0a3d7a",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 2025年体质检测"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "553ccd00-fcaa-40af-a7fc-fbd157196023",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 体测人员导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 4,
|
||
"id": "3e6da1e5-4b4e-448a-9663-815372da636b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2025-05-30T06:30:09.042788Z",
|
||
"iopub.status.busy": "2025-05-30T06:30:09.041974Z",
|
||
"iopub.status.idle": "2025-05-30T06:30:09.102061Z",
|
||
"shell.execute_reply": "2025-05-30T06:30:09.101519Z",
|
||
"shell.execute_reply.started": "2025-05-30T06:30:09.042708Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/石油工程设计有限公司人员2025.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, 3).value\n",
|
||
" dict1['sex'] = sheet.cell(n, 4).value\n",
|
||
" dict1['unit'] = sheet.cell(n, 6).value\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \n",
|
||
" dict1['phone'] = sheet.cell(n,7).value\n",
|
||
" dict1['id'] = str(sheet.cell(n,2).value)\n",
|
||
" person[code] = dict1\n",
|
||
"filename = 'data/东营石油工程设计院2025.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "bdd3dec8-e443-4365-a03a-7db2e698061e",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成读卡系统文件"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"id": "93610ae6-098d-434a-a19a-6071aaa65500",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2025-05-30T06:32:05.818838Z",
|
||
"iopub.status.busy": "2025-05-30T06:32:05.818215Z",
|
||
"iopub.status.idle": "2025-05-30T06:32:05.831425Z",
|
||
"shell.execute_reply": "2025-05-30T06:32:05.830336Z",
|
||
"shell.execute_reply.started": "2025-05-30T06:32:05.818778Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/东营石油工程设计院2025.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_东营石油工程设计院2025.json\", \"w\",encoding = 'utf-8') as file:\n",
|
||
" file.write(json_data) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "d7bcbeb2-2e6e-40a4-b1ef-35b95462dc44",
|
||
"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
|
||
}
|