2022110302

This commit is contained in:
512song committed 2022-11-03 20:35:41 +08:00
1 parent 973b1b0f0e
commit 21177e0b5a
1 file changed
+365
+365
View File
@@ -0,0 +1,365 @@
{
"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(8,'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/巴陵石化体测情况表(截至20221031).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": "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",
"\n",
"\n",
"fi_path = os.getcwd()+'/file/137'\n",
"old = []\n",
"new = []\n",
"dict2 = {}\n",
"depart = []\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",
" depart.append(m_depart) \n",
" dict2[int(k)] = [m_name,m_depart]\n",
"# 创建部门办公室 \n",
"m_path = os.getcwd()+'/file/137/new'\n",
"for pn in depart:\n",
" if not os.path.exists(m_path + '/' + pn):\n",
" os.mkdir(m_path + '/' + pn)\n",
"#print(dict1)\n",
"\n",
"\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",
" #print(fn)\n",
"old.sort()\n",
" #print(str(nfn)+'.pdf')\n",
"\n",
"for n in old:\n",
" \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" n_name = f'{fi_path}/new/{dict2[n][1]}/{str(n).rjust(5,\"0\")}-{dict2[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": 12,
"id": "22836727-9658-453a-99db-4d270c3253d4",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-02T03:09:46.184215Z",
"iopub.status.busy": "2022-11-02T03:09:46.183065Z",
"iopub.status.idle": "2022-11-02T03:09:46.407389Z",
"shell.execute_reply": "2022-11-02T03:09:46.404489Z",
"shell.execute_reply.started": "2022-11-02T03:09:46.184107Z"
},
"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/巴陵十五部门人员体测情况表(截至20221101).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": "b5c817af-a77e-4968-9a9e-680675f4a646",
"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
}