{ "cells": [ { "cell_type": "markdown", "id": "1c72f0cf-165b-4025-af9d-6771e4a0a5d1", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [], "toc-hr-collapsed": true }, "source": [ "# 2022年体质检测" ] }, { "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": null, "id": "97031317-76ed-4404-b922-6ca749e4fd2a", "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/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": null, "id": "f70a02f2-934e-43ed-93ff-b34cb732dfc6", "metadata": { "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": "9443f552-16a9-4c0d-82f8-279c42fa5e47", "metadata": {}, "source": [ "### 统计报告人员信息表" ] }, { "cell_type": "code", "execution_count": null, "id": "7a0a9111-2f2c-4c5d-bb5e-3e4fbd7ab1aa", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "import os\n", "import glob\n", "\n", "filename = 'data/北海炼化人员_2022.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "m_path = '../file/221103'\n", "fls = glob.glob(f'../file/221103/*.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/北海体测报告情况表.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": null, "id": "c42c5c04-49f3-4b4c-8f77-e37cfa9748f2", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "a9460ee7-1f60-4a3b-a45d-8a1dba04b920", "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", "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": "markdown", "id": "e17b1435-2b31-421f-8755-c11f0a4ac5c9", "metadata": {}, "source": [ "### 北海体检情况汇总" ] }, { "cell_type": "code", "execution_count": null, "id": "26343c71-535f-445b-9274-6492febfd435", "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", "dict1 = {}\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 = sheet.cell(n, 2).value\n", " dict1.setdefault(code, {}) \n", " dict1[code]['name'] = sheet.cell(n, 3).value \n", " \n", " dict1[code]['sex'] = sheet.cell(n, 4).value \n", " dict1[code]['age'] = sheet.cell(n, 5).value \n", " dict1[code].setdefault('bz',[]) \n", " dict1[code]['bz'].append(sheet.cell(n, 6).value) \n", " \n", "filename = 'data/北海炼化2022年健康体检团体报告.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print('ok')\n", "list1 = []\n", "for k, v in dict1.items():\n", " list2 = []\n", " mbz = set(v['bz'])\n", " list2.append(k)\n", " list2.append(v['name'])\n", " list2.append(v['sex'])\n", " list2.append(v['age'])\n", " list2.append(','.join(mbz))\n", " list1.append(list2)\n", "title = ['体检编号','姓名','性别','年龄','体检症状']\n", "filename = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告汇总统计表.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": "a14e0cfc-e2ac-41ff-acd9-69d669ad1fc2", "metadata": {}, "source": [ "### 北海体检情况汇总(文本文件)" ] }, { "cell_type": "code", "execution_count": null, "id": "6f7b0837-a623-47fb-8451-3860df6ec133", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "list2 = []\n", "file_name = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告.txt'\n", "with open(file_name,'r',encoding='utf-8') as fl:\n", " for l in fl:\n", " list1 = []\n", " list1 = l.strip('\\n').split()\n", " del list1[0]\n", " list2.append(list1)\n", " \n", "print(list2) \n", "title = ['体检编号','姓名','性别','年龄','体检症状']\n", "filename = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告统计表.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list2:\n", " sheet.append(row)\n", " \n", "wb.save(filename) \n" ] }, { "cell_type": "markdown", "id": "1a05cd85-32a0-4c91-a281-9e7253562ba3", "metadata": {}, "source": [ "### 北海体检情况统计" ] }, { "cell_type": "code", "execution_count": null, "id": "81fefc86-cd07-446c-ad08-bdb36b9e1722", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import itertools\n", "import operator\n", "\n", "filename = 'data/北海炼化2022年健康体检团体报告.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "bz = set()\n", "for k, v in dict1.items():\n", " for i in v['bz']:\n", " bz.add(i)\n", "print(len(bz))\n", "dict2 = {}\n", "dict3 = {}\n", "i = 1\n", "for n in [2,3,4]:\n", " iter1 = itertools.combinations(bz, n)\n", " list1 = list(iter1)\n", " print(len(list1)) \n", " \n", " list2 = []\n", " for item in list1:\n", " \n", " for k, v in dict1.items(): \n", " list3 = []\n", " if set(item).issubset(v['bz']):\n", " dict3[i] =item \n", " list3 = [k,i]\n", " list2.append(list3)\n", " i = i+1\n", " dict2[n] = list2\n", "dict2['bingzheng'] = dict3\n", "filename = 'data/北海炼化2022年健康体检病症组合.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2, fl, ensure_ascii=False) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "149104bd-76d8-4c42-b325-b0290439c3b2", "metadata": {}, "source": [ "### 北海体检情况分析" ] }, { "cell_type": "code", "execution_count": 46, "id": "e1b2e465-3ebb-448f-a3df-e2aaab70e688", "metadata": { "execution": { "iopub.execute_input": "2023-02-26T02:09:56.640500Z", "iopub.status.busy": "2023-02-26T02:09:56.639970Z", "iopub.status.idle": "2023-02-26T02:10:09.671647Z", "shell.execute_reply": "2023-02-26T02:10:09.670363Z", "shell.execute_reply.started": "2023-02-26T02:09:56.640450Z" }, "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import itertools\n", "import operator\n", "\n", "filename = 'data/北海炼化2022年健康体检病症组合.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "bz = dict1['bingzheng']\n", "bz1 = dict1['2']\n", "list1 = []\n", "for k, v in bz.items():\n", " list2 = []\n", " i = 1\n", " bzs = len(v)\n", " for v1 in dict1[str(bzs)]:\n", " if v1[1] == int(k):\n", " \n", " i+=1\n", " list2 =[bzs,','.join(v),i]\n", " list1.append(list2)\n", "filename = 'data/中国石化北海炼化有限责任公司2022年病症统计表.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": "c103301b-d540-4bf5-861a-0eb2e313e26e", "metadata": {}, "source": [ "# 2023年体质检测" ] }, { "cell_type": "markdown", "id": "1ab2aa22-5cc2-4f53-a28d-b30b1ecab15f", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "## 人员信息处理" ] }, { "cell_type": "markdown", "id": "1e3f67e9-e332-41c5-89f8-b64ec0bace4c", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "### 人员信息汇总(批量人员)" ] }, { "cell_type": "code", "execution_count": 98, "id": "648d597d-2ac4-470c-9562-271e3e2863d6", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T08:13:47.536294Z", "iopub.status.busy": "2023-10-25T08:13:47.535980Z", "iopub.status.idle": "2023-10-25T08:13:47.835840Z", "shell.execute_reply": "2023-10-25T08:13:47.835233Z", "shell.execute_reply.started": "2023-10-25T08:13:47.536267Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import os,sys,shutil\n", "import json\n", "import glob\n", "from pathlib import Path\n", "import openpyxl\n", "\n", "fi_path = 'data/北海炼化/'\n", "\n", "fls = glob.glob(f'{fi_path}/*.xlsx')\n", "i = 1\n", "person = {}\n", "for fl in fls:\n", " wb = openpyxl.load_workbook(fl)\n", " sheet = wb.active\n", " # sheets = wb.sheetnames\n", " \n", "\n", " for n in range(3,sheet.max_row+1):\n", " if sheet.cell(n,1).value is not None:\n", " code = str(i)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n,3 ).value\n", " dict1['婚姻'] = sheet.cell(n, 5).value\n", " dict1['phone'] = str(sheet.cell(n,6).value)\n", " dict1['id'] = sheet.cell(n,7 ).value\n", " dict1['总工龄'] = sheet.cell(n, 8).value\n", " dict1['损害工龄'] = sheet.cell(n, 9).value\n", " dict1['既往病史'] = sheet.cell(n,10 ).value\n", " dict1['有毒因素'] = sheet.cell(n, 11).value\n", " dict1['unit'] = sheet.cell(n, 12).value\n", " dict1['工种'] = sheet.cell(n, 13).value\n", " dict1['防护措施'] = sheet.cell(n,15 ).value \n", " person[code] = dict1\n", " i+=1\n", " \n", "filename = 'data/北海炼化2023.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "b1f47560-4183-4699-8d63-3d81a3ec002b", "metadata": {}, "source": [ "### 检查身份证及手机号码唯一性" ] }, { "cell_type": "code", "execution_count": 75, "id": "a2c1c315-c522-433a-9611-e08dca2445a9", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T07:39:03.122723Z", "iopub.status.busy": "2023-10-25T07:39:03.122416Z", "iopub.status.idle": "2023-10-25T07:39:03.163768Z", "shell.execute_reply": "2023-10-25T07:39:03.163068Z", "shell.execute_reply.started": "2023-10-25T07:39:03.122696Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "董红军 18877976757\n", "苗光浩 13927509537\n", "440906199104060046 440906199104060046\n", "黄仁进 13807799565\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "id= []\n", "phone = [] \n", "\n", "for k, v in dict1.items():\n", " if v['phone'] not in phone:\n", " phone.append(v['phone'] )\n", " else:\n", " print(v['name'] ,v['phone'])\n", " if v['id'] not in id:\n", " id.append(v['id'] )\n", " else:\n", " print(v['id'] ,v['id'] )\n" ] }, { "cell_type": "markdown", "id": "c1842f66-c81f-423d-bcda-0d49be82b32a", "metadata": {}, "source": [ "### 查找身份证号码" ] }, { "cell_type": "code", "execution_count": 48, "id": "7ba235d2-4638-4479-babb-2f9867c177c2", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T06:41:49.969813Z", "iopub.status.busy": "2023-10-25T06:41:49.969303Z", "iopub.status.idle": "2023-10-25T06:41:49.984085Z", "shell.execute_reply": "2023-10-25T06:41:49.982976Z", "shell.execute_reply.started": "2023-10-25T06:41:49.969767Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "440906199104060046 凌倩\n", "440906199104060046 陈继杨\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "id= '440906199104060046'\n", "for k, v in dict1.items():\n", " if v['id'] == id:\n", " print(id,v['name'])" ] }, { "cell_type": "code", "execution_count": 67, "id": "f9d8aafa-9a00-484a-a3c2-b3e9252b505d", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T07:22:33.048929Z", "iopub.status.busy": "2023-10-25T07:22:33.048318Z", "iopub.status.idle": "2023-10-25T07:22:33.073020Z", "shell.execute_reply": "2023-10-25T07:22:33.070785Z", "shell.execute_reply.started": "2023-10-25T07:22:33.048870Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "18877976757 刘前程\n", "13927509537 黄洁强\n", "18877976757 董红军\n", "13927509537 苗光浩\n", "13807799565 谢昌俊\n", "13807799565 黄仁进\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "phone= ['13807799565','18877976757','13927509537']\n", "for k, v in dict1.items():\n", " if v['phone'] in phone:\n", " print(v['phone'],v['name'])" ] }, { "cell_type": "markdown", "id": "1ea37f21-f03a-4450-8867-71fb8c3eeee7", "metadata": {}, "source": [ "### 生成出生日期" ] }, { "cell_type": "code", "execution_count": 101, "id": "dff13fe9-d5cd-45e3-a3e7-f47d12560699", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T08:13:58.275474Z", "iopub.status.busy": "2023-10-25T08:13:58.275157Z", "iopub.status.idle": "2023-10-25T08:13:58.306694Z", "shell.execute_reply": "2023-10-25T08:13:58.305838Z", "shell.execute_reply.started": "2023-10-25T08:13:58.275446Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "for k, v in dict1.items():\n", " id = str(v['id']) \n", " #print(id)\n", " birth = id[6:10] + '-' +id[10:12] + '-' +id[12:14]\n", " dict1[k]['birth'] = birth\n", " \n", " \n", "filename = 'data/北海炼化2023.json' \n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "de060103-776c-40d8-9704-ece6cc574308", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T06:22:41.417620Z", "iopub.status.busy": "2023-10-25T06:22:41.417111Z", "iopub.status.idle": "2023-10-25T06:22:41.439732Z", "shell.execute_reply": "2023-10-25T06:22:41.437319Z", "shell.execute_reply.started": "2023-10-25T06:22:41.417575Z" }, "tags": [] }, "source": [ "### 人员信息汇总(单个文件)" ] }, { "cell_type": "code", "execution_count": 99, "id": "61f8d7c3-b7f2-44b7-86f1-5b29d22193cb", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T08:13:51.263500Z", "iopub.status.busy": "2023-10-25T08:13:51.263208Z", "iopub.status.idle": "2023-10-25T08:13:51.342292Z", "shell.execute_reply": "2023-10-25T08:13:51.341571Z", "shell.execute_reply.started": "2023-10-25T08:13:51.263475Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " person = json.load(fl)\n", "i = len(person)+1\n", "fl = 'data/北海炼化机关名单表(2023年汇总156人).xlsx'\n", "wb = openpyxl.load_workbook(fl)\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "\n", "\n", "for n in range(3,sheet.max_row+1):\n", " if sheet.cell(n,1).value is not None:\n", " code = str(i)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n,3 ).value \n", " dict1['phone'] = sheet.cell(n,6).value\n", " dict1['id'] = sheet.cell(n,5 ).value \n", " dict1['婚姻'] = sheet.cell(n, 11).value\n", " dict1['unit'] = sheet.cell(n, 8).value \n", " person[code] = dict1\n", " i+=1\n", "filename = 'data/北海炼化2023.json' \n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')\n" ] }, { "cell_type": "code", "execution_count": 100, "id": "8da8e47d-b62b-4719-82d5-fcfc61473e08", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T08:13:54.195888Z", "iopub.status.busy": "2023-10-25T08:13:54.195597Z", "iopub.status.idle": "2023-10-25T08:13:54.261587Z", "shell.execute_reply": "2023-10-25T08:13:54.260957Z", "shell.execute_reply.started": "2023-10-25T08:13:54.195864Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " person = json.load(fl)\n", "i = len(person)+1\n", "fl = 'data/北海炼化上岗体检人员名单 (2023年).xlsx'\n", "wb = openpyxl.load_workbook(fl)\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "\n", "\n", "for n in range(5,sheet.max_row+1):\n", " if sheet.cell(n,1).value is not None:\n", " code = str(i)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n,3 ).value \n", " dict1['phone'] = str(sheet.cell(n,7).value)\n", " dict1['id'] = sheet.cell(n,6 ).value\n", " \n", " dict1['有毒因素'] = sheet.cell(n, 11).value\n", " dict1['unit'] = '新上岗'\n", " dict1['工种'] = sheet.cell(n, 8).value\n", " dict1['防护措施'] = sheet.cell(n,13 ).value \n", " person[code] = dict1\n", " i+=1\n", "filename = 'data/北海炼化2023.json' \n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')\n" ] }, { "cell_type": "markdown", "id": "3e890abb-5e49-4a80-b401-602cd2e83533", "metadata": {}, "source": [ "### 人员信息汇总导出" ] }, { "cell_type": "code", "execution_count": 102, "id": "474786b8-e172-4335-aa4d-bb5bde17ceb7", "metadata": { "execution": { "iopub.execute_input": "2023-10-25T08:14:01.457995Z", "iopub.status.busy": "2023-10-25T08:14:01.457489Z", "iopub.status.idle": "2023-10-25T08:14:01.591382Z", "shell.execute_reply": "2023-10-25T08:14:01.590589Z", "shell.execute_reply.started": "2023-10-25T08:14:01.457949Z" }, "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "for k, v in dict1.items():\n", " list2 = []\n", " list2 = [str(k).rjust(4,'0'),v['name'],v['sex'],v['unit'],v['birth'],v['phone']]\n", " list1.append(list2)\n", "filename = 'data/北海炼化人员信息(2023年).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "\n", "for row in list1:\n", " sheet.append(row)\n", " \n", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "e613feb8-b03d-4afc-aa56-c91d80903a22", "metadata": {}, "source": [ "### 生成人员信息" ] }, { "cell_type": "code", "execution_count": 104, "id": "0bafbf66-c909-413e-a9c1-c1a5f9c22953", "metadata": { "execution": { "iopub.execute_input": "2023-11-08T01:55:15.141433Z", "iopub.status.busy": "2023-11-08T01:55:15.141150Z", "iopub.status.idle": "2023-11-08T01:55:15.238893Z", "shell.execute_reply": "2023-11-08T01:55:15.238339Z", "shell.execute_reply.started": "2023-11-08T01:55:15.141408Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/北海炼化人员信息(2023年).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, 2).value\n", " dict1['sex'] = sheet.cell(n, 3).value\n", " dict1['unit'] = sheet.cell(n, 4).value\n", " dict1['birth'] = sheet.cell(n,5).value\n", " if sheet.cell(n,6).value is not None:\n", " dict1['phone'] = sheet.cell(n,6).value \n", " person[code] = dict1\n", "filename = 'data/北海炼化2023年.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "b373563f-0b78-4d37-9428-89d3f4e04883", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": 9, "id": "ff1e0a37-6119-4f64-8e05-4d25cb144817", "metadata": { "execution": { "iopub.execute_input": "2023-11-06T02:45:31.688480Z", "iopub.status.busy": "2023-11-06T02:45:31.688086Z", "iopub.status.idle": "2023-11-06T02:45:31.699445Z", "shell.execute_reply": "2023-11-06T02:45:31.699024Z", "shell.execute_reply.started": "2023-11-06T02:45:31.688449Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化2023年.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_北海炼化.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "405f3461-fcef-47d4-a88b-a2975f8d522f", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 105, "id": "1aa45b35-7376-4c50-8275-79b090a6c758", "metadata": { "execution": { "iopub.execute_input": "2023-11-08T01:55:24.418823Z", "iopub.status.busy": "2023-11-08T01:55:24.418534Z", "iopub.status.idle": "2023-11-08T01:55:24.459533Z", "shell.execute_reply": "2023-11-08T01:55:24.458755Z", "shell.execute_reply.started": "2023-11-08T01:55:24.418802Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "217\n", "217\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", "re_ta = {}\n", "dict1 = {}\n", "list1 = []\n", "filename = 'data/北海炼化2023年.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20231108.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]['unit'] = dict1[user]['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", " re_ta[user]['rq'] = str(result[6]) \n", "print(len(re_ta))\n", "filename = 'data/result_北海炼化2023.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": "code", "execution_count": null, "id": "56ad2623-c435-4161-a55e-18899c6134ea", "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.12" } }, "nbformat": 4, "nbformat_minor": 5 }