Files
jupyter/体测单位/巴陵石化.ipynb
2022-11-17 07:50:05 +08:00

467 lines
14 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "37eee6b1-ddbc-414c-ac74-e831c53c9bdb",
"metadata": {},
"source": [
"### 人员基本信息导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a27e986c-0c40-4792-b24d-03b19df707a9",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/巴陵石化监测花名册.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = int(sheet.cell(n, 4).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 6).value \n",
" xb = str(sheet.cell(n, 7).value)\n",
" if xb == '1':\n",
" sex = '男'\n",
" elif xb =='2':\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" dict1['unit'] = sheet.cell(n, 3).value\n",
" dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]\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": "b1384a8f-36f4-483e-afb4-65a56a064dd3",
"metadata": {},
"source": [
"### 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5e4145b-d575-46b5-a530-c722668f76f3",
"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 FROM places_result AS a,_zgshhgxs AS b WHERE a.place_id=135 AND a.avatar_id=b.id AND a.avatar_id < 4999\n",
"\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/137_2210.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": "3c911994-2ce1-4412-8d56-39b195e66457",
"metadata": {},
"source": [
"### 导出测试成绩"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0582bc84-7234-415f-9715-66c27b6b8f91",
"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/巴陵石化体测情况表(截至20221108).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": "8e8dc85d-7ed7-4146-98c6-8d2dc64026ea",
"metadata": {},
"source": [
"### 统计测试成绩"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b40ff7f-68c1-4c04-9bdc-3af16980fc25",
"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",
"dict3 = {}\n",
"i = 0\n",
"for k, v in dict1.items():\n",
" sex = dict2[k]['sex']\n",
" dict3.setdefault(sex,{}) \n",
" for item in v.keys():\n",
" if item in items:\n",
" dict3[sex].setdefault(item,[]) \n",
" if v[item]['得分'].isdigit() :\n",
" dict3[sex][item].append(v[item]['得分']) \n",
"#print(dict3) \n",
"for k, v in dict3.items():\n",
" sex = k\n",
" for k1, v1 in v.items():\n",
" df = 0\n",
" if len(v1) >0:\n",
" \n",
" for i in range(0,len(v1)-1):\n",
" df = df + int(v1[i])\n",
" print(sex,k1,df,i)\n",
" \n",
" \n"
]
},
{
"cell_type": "markdown",
"id": "3c282594-4be4-4321-ae0b-c183ab844518",
"metadata": {},
"source": [
"### 根据报告统计人员成绩得分"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7102f36a-f92d-4896-b7c7-ef57f88c2f3e",
"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",
" dict2 = json.load(fl)\n",
"filename = 'data/巴陵石化人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"list1 = []\n",
"fn = []\n",
"m_path = os.getcwd()+'/file/137'\n",
"fls = glob.glob(f'file/137/*.pdf')\n",
"for fl in fls:\n",
" fn.append(os.path.basename(fl).split('.')[0])\n",
"for k in fn:\n",
" #print(k,dict2[str(k)]['name'])\n",
" list2 = []\n",
" list2.append(str(k).rjust(5,'0'))\n",
" list2.append(dict2[k]['name']) \n",
" list2.append(dict1[k]['sex'])\n",
" list2.append(dict1[k]['unit']) \n",
" \n",
" for item in items:\n",
" if item in dict2[k].keys():\n",
" list2.append(dict2[k][item]['成绩'])\n",
" list2.append(dict2[k][item]['得分']) \n",
" elif item =='name':\n",
" list2.append(dict2[k][item])\n",
" else:\n",
" list2.append('') \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)\n",
"print('ok') "
]
},
{
"cell_type": "markdown",
"id": "19947e33-64f8-4855-8b28-60e2a8c3543c",
"metadata": {},
"source": [
"### 报告按照部门分组"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7930c77b-7a99-4bd0-b998-b9801ed3b257",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import glob\n",
"\n",
"fi_path = '../file/221116'\n",
"old = []\n",
"dict2 = {}\n",
"\n",
"\n",
"filename = 'data/巴陵石化人员.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",
"\n",
"m_path = '../file/221116'\n",
"fls = glob.glob(f'../file/221116/*.pdf')\n",
"\n",
"for fn in fls:\n",
" old.append(os.path.basename(fn).split('.')[0])\n",
" #print(fn)\n",
"\n",
"\n",
"for n in old: \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" if not os.path.exists(f'{fi_path}/new/{dict2[int(n)][1]}'):\n",
" os.mkdir(f'{fi_path}/new/{dict2[int(n)][1]}') \n",
" n_name = f'{fi_path}/new/{dict2[int(n)][1]}/{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)"
]
},
{
"cell_type": "markdown",
"id": "b09a3236-e540-4a49-bd19-e11e3de77a71",
"metadata": {},
"source": [
"### 统计报告人员信息表"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22836727-9658-453a-99db-4d270c3253d4",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"import os\n",
"import glob\n",
"\n",
"filename = 'data/巴陵石化人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"m_path = os.getcwd()+'/file/137'\n",
"fls = glob.glob(f'file/137/*.pdf')\n",
"list1 = []\n",
"for fn in fls:\n",
" list2 = []\n",
" code = os.path.basename(fn).split('.')[0]\n",
" list2 = [code.rjust(5,\"0\"),dict1[code]['name'],dict1[code]['unit']]\n",
" list1.append(list2)\n",
"title = ['编号','姓名','部门'] \n",
"filename = 'data/巴陵二部门人员体测情况表(截至20221103).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": "2f392a9a-0ffd-48c2-a9d7-7af99ca0f5f6",
"metadata": {},
"source": [
"### 统计部门测试人员情况"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8e04af4-978a-463f-83e3-c015e1e72938",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"title = ['部门','部门人数','已测人数','未测人数']\n",
"filename = 'data/巴陵石化人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"filename = 'data/result_巴陵.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"\n",
"dict3 = {}\n",
"for k, v in dict1.items():\n",
" dict3.setdefault(v['unit'],{})\n",
" dict3[v['unit']].setdefault('人数',0)\n",
" dict3[v['unit']].setdefault('已测人数',0)\n",
" dict3[v['unit']]['人数'] = dict3[v['unit']]['人数']+1\n",
"for k, v in dict2.items():\n",
" if len(v.keys())>5: \n",
" dict3[v['unit']]['已测人数'] = dict3[v['unit']]['已测人数'] + 1\n",
"list1 = []\n",
"\n",
"for k, v in dict3.items():\n",
" list2 = []\n",
" list2 = [k,v['人数'],v['已测人数'],v['人数']-v['已测人数']]\n",
" \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": "code",
"execution_count": null,
"id": "9cfed761-0251-47b5-831b-e005b6675452",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}