Files
jupyter/体测单位/北海炼化.ipynb
T
2022-11-02 10:33:09 +08:00

455 lines
13 KiB
Plaintext
Raw 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": "61f4a6eb-797e-4fe2-95df-e27b316c95f1",
"metadata": {},
"source": [
"### 人员基本信息导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6bc68b5-9ed8-4b28-ab1a-452107b6429a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/北海石化监测花名册2022 .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/北海炼化人员_2022.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "fe54b0b2-0abd-4ee9-827d-0e3a4c9bd1f2",
"metadata": {},
"source": [
"### 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "97031317-76ed-4404-b922-6ca749e4fd2a",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-01T09:18:38.933088Z",
"iopub.status.busy": "2022-11-01T09:18:38.932552Z",
"iopub.status.idle": "2022-11-01T09:18:39.012745Z",
"shell.execute_reply": "2022-11-01T09:18:39.011599Z",
"shell.execute_reply.started": "2022-11-01T09:18:38.933039Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"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/138_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_北海炼化2022.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "be6b6709-a2b0-4c34-aca1-000e1fb45953",
"metadata": {},
"source": [
"### 导出测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f70a02f2-934e-43ed-93ff-b34cb732dfc6",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-01T09:18:42.502192Z",
"iopub.status.busy": "2022-11-01T09:18:42.501603Z",
"iopub.status.idle": "2022-11-01T09:18:42.729776Z",
"shell.execute_reply": "2022-11-01T09:18:42.728671Z",
"shell.execute_reply.started": "2022-11-01T09:18:42.502143Z"
},
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位/部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"filename = 'data/result_北海炼化2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/北海炼化人员_2022.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/北海炼化体测情况表(截至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": "markdown",
"id": "84325f89-1408-4d0a-b877-f4b54bcb22ce",
"metadata": {},
"source": [
"### 统计部门测试人员情况"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "c42c5c04-49f3-4b4c-8f77-e37cfa9748f2",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-01T09:27:40.105525Z",
"iopub.status.busy": "2022-11-01T09:27:40.104998Z",
"iopub.status.idle": "2022-11-01T09:27:40.151243Z",
"shell.execute_reply": "2022-11-01T09:27:40.150059Z",
"shell.execute_reply.started": "2022-11-01T09:27:40.105476Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"title = ['部门','部门人数','已测人数','未测人数']\n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"filename = 'data/result_北海炼化2022.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": "markdown",
"id": "5ec595eb-f979-425e-b7eb-9af094ffb43d",
"metadata": {},
"source": [
"### 导入2021年人员信息"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a9460ee7-1f60-4a3b-a45d-8a1dba04b920",
"metadata": {
"execution": {
"iopub.execute_input": "2022-10-31T11:54:40.324705Z",
"iopub.status.busy": "2022-10-31T11:54:40.324184Z",
"iopub.status.idle": "2022-10-31T11:54:40.626097Z",
"shell.execute_reply": "2022-10-31T11:54:40.624830Z",
"shell.execute_reply.started": "2022-10-31T11:54:40.324656Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/all_result.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"dict3 = {}\n",
"dict3 = dict2['北海炼化']\n",
"\n",
"for k, v in dict1.items():\n",
" name = v['name']\n",
" birth = v['birth']\n",
" for k1, v1 in dict3.items():\n",
" if v1['name'] == name and v1['birth'] == birth:\n",
" dict1[k]['old_code'] = int(k1)\n",
" dict1[k]['record'] = v1['record']\n",
" \n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "0a221ef2-0d86-45a7-916e-bce634a57bfe",
"metadata": {},
"source": [
"### 核对2021体测人员"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61fbd157-f4f0-4c85-98dc-0e79ee99280b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"list1 = []\n",
"for k,v in dict1.items():\n",
" if 'old_code' in v.keys():\n",
" list1.append(v['old_code'])\n",
"filename = 'data/all_result.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"dict3 = {}\n",
"dict3 = dict2['北海炼化']\n",
"for k, v in dict3.items():\n",
" if int(k) not in list1:\n",
" print(k,v['name'],v['birth'])"
]
},
{
"cell_type": "markdown",
"id": "e6698931-04fb-4dd8-a844-55790cbe3eb9",
"metadata": {},
"source": [
"### 比照人员两年成绩"
]
},
{
"cell_type": "markdown",
"id": "727be8d7-8a4c-4cf4-8139-476f407a31b0",
"metadata": {},
"source": [
"#### 比照两年单项成绩"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3ca4d45-6a83-4d50-8419-cf8aa9b3aa4c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"list1 = dict1.keys()\n",
"items = ['台阶指数']\n",
"title = ['编号','姓名','部门','22年台阶指数','21年台阶指数']\n",
"filename = 'data/result_北海炼化2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"list4 = []\n",
"for k, v in dict2.items():\n",
" if k in list1:\n",
" list2 = [k,v['name'],v['unit']]\n",
" list3 = []\n",
" for item in items:\n",
" # 获取2022年成绩\n",
" if item in v.keys(): \n",
" list2.append(v[item]['成绩'].split()[0]) \n",
" else:\n",
" list2.append('')\n",
" # 获取2021年成绩\n",
" if 'record' in dict1[k].keys() and item in dict1[k]['record'].keys():\n",
" list3.append(dict1[k]['record'][item]['成绩']) \n",
" else:\n",
" list3.append('')\n",
" for cj in list3:\n",
" if cj != '':\n",
" list2.append(cj.split()[0]) \n",
" \n",
" list4.append(list2)\n",
"filename = 'data/b北海炼化成绩对照221026.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet.append(title)\n",
"for row in list4:\n",
" sheet.append(row)\n",
" \n",
"wb.save(filename) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70de1be8-e55c-4b7a-bad9-78ad77f199d0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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
}