{ "cells": [ { "cell_type": "markdown", "id": "1c72f0cf-165b-4025-af9d-6771e4a0a5d1", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "# 2022年体质检测" ] }, { "cell_type": "markdown", "id": "61f4a6eb-797e-4fe2-95df-e27b316c95f1", "metadata": { "tags": [] }, "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-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl) \n", "print('ok')" ] }, { "cell_type": "code", "execution_count": null, "id": "d2598172-cede-4baa-920e-3d676c079b7b", "metadata": {}, "outputs": [], "source": [ "import json\n", "import time\n", "import csv\n", "from datetime import date,datetime\n", "\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", "filename = 'data/北海炼化人员_2022.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \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", " \n", " #re_ta[user]['rq'] = str(result[3]).replace('/','-')\n", " date_obj = datetime.strptime(result[3], \"%Y/%m/%d\")\n", " re_ta[user]['rq'] = date_obj.strftime('%Y-%m-%d')\n", " \n", " \n", " \n", " #item_name = item[m_item]['name']\n", " re_ta[user].setdefault(m_item,{}) \n", " score = int(result[1])/item[m_item]['divisor'] \n", " re_ta[user][m_item]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", " #re_ta[user][item_name]['得分'] =result[2]\n", "for k,v in re_ta.items():\n", " v['birth'] = dict2[k]['birth']\n", " birth = date.fromisoformat(dict2[k]['birth'].replace('/','-'))\n", " rq = date.fromisoformat(re_ta[user]['rq'].replace('/','-'))\n", " days = (rq-birth).days \n", " v['days'] = days\n", " v['age'] = int(days/365)\n", " v['sex'] = dict2[k]['sex']\n", " if 'height' in v.keys() and 'height' in v.keys():\n", " v.setdefault('bmi',{})\n", " v['bmi']['成绩'] = v['height']['成绩'].split()[0]+','+v['weight']['成绩'].split()[0]\n", " \n", "filename = 'data/result_北海炼化2022-1.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": null, "id": "e1b2e465-3ebb-448f-a3df-e2aaab70e688", "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 = 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": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "# 2023年体质检测" ] }, { "cell_type": "markdown", "id": "1ab2aa22-5cc2-4f53-a28d-b30b1ecab15f", "metadata": { "tags": [] }, "source": [ "## 人员信息处理" ] }, { "cell_type": "markdown", "id": "1e3f67e9-e332-41c5-89f8-b64ec0bace4c", "metadata": { "tags": [] }, "source": [ "### 人员信息汇总(批量人员)" ] }, { "cell_type": "code", "execution_count": null, "id": "648d597d-2ac4-470c-9562-271e3e2863d6", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "a2c1c315-c522-433a-9611-e08dca2445a9", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "7ba235d2-4638-4479-babb-2f9867c177c2", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "f9d8aafa-9a00-484a-a3c2-b3e9252b505d", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "dff13fe9-d5cd-45e3-a3e7-f47d12560699", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "61f8d7c3-b7f2-44b7-86f1-5b29d22193cb", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "8da8e47d-b62b-4719-82d5-fcfc61473e08", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "474786b8-e172-4335-aa4d-bb5bde17ceb7", "metadata": { "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": null, "id": "0bafbf66-c909-413e-a9c1-c1a5f9c22953", "metadata": { "tags": [] }, "outputs": [], "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'] = str(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": null, "id": "ff1e0a37-6119-4f64-8e05-4d25cb144817", "metadata": { "tags": [] }, "outputs": [], "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": null, "id": "1aa45b35-7376-4c50-8275-79b090a6c758", "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", "filename = 'data/北海炼化2023年.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20231122.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", " \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", " re_ta[user]['phone'] = dict1[user]['phone']\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", " rq = date.fromisoformat(str(result[6]))\n", " birth = date.fromisoformat(dict1[user]['birth'])\n", " days = (rq-birth).days \n", " re_ta[user]['age'] = int(days/365)\n", " re_ta[user]['month'] = int(days/365*12)\n", " \n", " \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": "markdown", "id": "429ed5f7-57cb-4fcd-a267-2d222e08d81c", "metadata": {}, "source": [ "## 统计所有部门未体测人员明细表" ] }, { "cell_type": "code", "execution_count": null, "id": "1172a79c-ec8f-4274-8c43-6ec11d95f8ca", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/北海炼化2023年.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "list1 = []\n", "\n", "i = 1\n", "for k, v in dict2.items():\n", " \n", " if k not in dict1.keys():\n", " list2 = [i,k,v['name'],v['unit']]\n", " i+=1\n", " list1.append(list2)\n", "filename = f'data/北海炼化未测试人员名单(截至20231111).xlsx'\n", "title = ['序号','员工编号','姓名','部门']\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list1:\n", " sheet.append(row) \n", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "c410f403-5c93-4a03-a06b-900ecd08a1b4", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": null, "id": "c0128f52-8697-4258-aba0-89a522fb9cc0", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/北海炼化2023年.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_20231127.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", "for i in range(0,45):\n", " psy.append(0)\n", "psy[44] = []\n", "for i in range(0,60):\n", " tcm.append(0)\n", "for i in range(0,26):\n", " spine.append(0)\n", "\n", "for item in list1:\n", " if item[2] in phone.keys():\n", " psy =[]\n", " tcm = []\n", " spine = []\n", " for i in range(0,45):\n", " psy.append(0)\n", " psy[44] = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for i in range(0,26):\n", " spine.append(0)\n", " \n", " content = json.loads(item[5])\n", " if phone[item[2]] not in dict1.keys():\n", " dict1[phone[item[2]]] = dict3[phone[item[2]]]\n", " rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " for k, v in content.items():\n", " if 'psy' in k:\n", " i = int(k[3:])\n", " psy[i-1] = int(v)\n", " if 'tcm' in k:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " if 'spine' in k:\n", " i = int(k[5:])\n", " spine[i-1] = int(v)\n", " if 'psy' in item[5]:\n", " #for i in range(5,26):\n", " # new_valve = 5-psy[i]\n", " # psy[i] = new_valve\n", " for i in range(26,40):\n", " new_valve = 1+psy[i]\n", " psy[i] = new_valve\n", " \n", " dict1[phone[item[2]]]['psy'] = psy\n", " if 'tcm' in item[5]:\n", " dict1[phone[item[2]]]['tcm'] = tcm\n", " if 'spine' in item[5]:\n", " dict1[phone[item[2]]]['spine'] = spine\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_北海炼化2023.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False) " ] }, { "cell_type": "code", "execution_count": null, "id": "5f222727-d5b4-481f-8f1c-bea74b35936b", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/北海炼化2023年.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_20231114.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", "for i in range(0,44):\n", " psy.append(0)\n", "for i in range(0,60):\n", " tcm.append(0)\n", "for i in range(0,26):\n", " spine.append(0)\n", "print(len(spine))" ] }, { "cell_type": "markdown", "id": "0690df67-fc6b-4386-a18f-a99bd065c894", "metadata": {}, "source": [ "## 统计项目数" ] }, { "cell_type": "code", "execution_count": null, "id": "87e0c0f1-5f07-424d-98b2-aa301fd77c82", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "list1 = []\n", "for k,v in dict1.items():\n", " i = 0\n", " list2 = []\n", " for item in items:\n", " if item in v.keys():\n", " i+=1\n", " print(k)\n", " list2 = [k,v['name'],v['sex'],v['age'],v['unit'],v['phone'],i]\n", " if 'psy' in v.keys():\n", " list2.append(1)\n", " else:\n", " list2.append(0)\n", " if 'tcm' in v.keys():\n", " list2.append(1)\n", " else:\n", " list2.append(0)\n", " if 'spine' in v.keys():\n", " list2.append(1)\n", " else:\n", " list2.append(0)\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) " ] }, { "cell_type": "markdown", "id": "cd06cd33-668f-4b5a-8c98-587d503a39eb", "metadata": {}, "source": [ "## 统计手机号码不明确人员" ] }, { "cell_type": "code", "execution_count": null, "id": "6faef501-54eb-436b-8c51-093a05c38686", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/北海炼化2023年.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_20231119.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", "\n", "for item in list1:\n", " if item[2] not in phone.keys():\n", " print(item[2])\n", " " ] }, { "cell_type": "markdown", "id": "95e2d0f2-c0c7-4647-a34d-1b998ca89293", "metadata": {}, "source": [ "## 统计各部门测试情况" ] }, { "cell_type": "code", "execution_count": null, "id": "d554c400-8f2f-4f60-97ba-ab5ace254d6f", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/北海炼化2023年.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "dict3 = {}\n", "for k, v in dict2.items():\n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " dict3.setdefault(unit,{})\n", " dict3[unit].setdefault('人数',0)\n", " #dict3[unit].setdefault(sub_unit,0)\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] + 1\n", " dict3[unit]['人数'] = dict3[unit]['人数'] + 1\n", "\n", "title =['单位','体测人数']\n", "list1 = []\n", "for k,v in dict1.items(): \n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] - 1\n", " dict3[unit].setdefault('体测人数',0)\n", " dict3[unit]['体测人数'] = dict3[unit]['体测人数'] + 1\n", "for k, v in dict3.items():\n", " list2 = [k,v['人数'],v['体测人数']]\n", " list1.append(list2)\n", "\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": "14101d8f-4e74-4982-a984-c0ebe4099107", "metadata": {}, "source": [ "## 生成新格式测试成绩" ] }, { "cell_type": "code", "execution_count": null, "id": "f21b1c8d-1b2d-45f6-8f35-4a62d5b944f7", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import datetime\n", "import csv\n", "from datetime import date\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", "item['1']['en'] = 'lung'\n", "item['2']['en'] = 'grip'\n", "item['3']['en'] = 'flexion'\n", "item['4']['en'] = 'jump'\n", "item['5']['en'] = 'pushup'\n", "item['6']['en'] = 'balance'\n", "item['7']['en'] = 'reaction'\n", "item['8']['en'] = 'step'\n", "item['9']['en'] = 'situp'\n", "item['10']['en'] = 'height'\n", "item['11']['en'] = 'weight'\n", "\n", "\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_20231122.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", "#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n", "#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n", "for result in list1:\n", " user = str(result[2])\n", " rq = date.fromisoformat(result[6].replace('/','-'))\n", " if user in dict1.keys():\n", " l_xm = []\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]['phone'] = dict1[user]['phone']\n", " if dict1[user]['sex'] == '男':\n", " l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n", " else:\n", " l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n", " re_ta[user]['unit'] = dict1[user]['unit']\n", " birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n", " #nian = int(birth[0].strip())\n", " #yue = int(birth[1].strip())\n", " #ri = int(birth[2].strip())\n", " #print(k,nian,yue,ri)\n", " item_name = item[m_item]['en'] \n", " if item_name in l_xm: \n", " days = (rq-birth).days \n", " re_ta[user]['age'] = int(days/365)\n", " re_ta[user]['month'] = int(days/365*12)\n", " re_ta[user]['rq'] = result[6]\n", "\n", "\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_北海炼化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": "markdown", "id": "89a02e6b-0418-4516-a9e0-12364aa38783", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": null, "id": "9ca97d8f-6320-48f1-9a16-2d34167dac19", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import time\n", "\n", "filename = '../item.json'\n", "item = {}\n", "unit = {}\n", "with open(filename,'r') as fl:\n", " dict3 = json.load(fl) \n", "for k,v in dict3.items():\n", " item[k] = v\n", "item['1']['en'] = 'lung'\n", "item['2']['en'] = 'grip'\n", "item['3']['en'] = 'flexion'\n", "item['4']['en'] = 'jump'\n", "item['5']['en'] = 'pushup'\n", "item['6']['en'] = 'balance'\n", "item['7']['en'] = 'reaction'\n", "item['8']['en'] = 'step'\n", "item['9']['en'] = 'situp'\n", "item['10']['en'] = 'height'\n", "item['11']['en'] = 'weight'\n", "\n", "filename = 'data/体质检测标准 (1).json' \n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "\n", "\n", "def cal_score(data1):\n", " #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n", " person = dict1['person']\n", " criteria = dict1['criteria']\n", " if data1['age'] >59:\n", " data1['age'] = 59\n", " if data1['age'] <20:\n", " data1['age'] = 20\n", " info = data1['sex']+str(data1['age'])\n", " bz = person[info]\n", " mx = criteria[bz][data1['item']]\n", " result = data1['result'] \n", " if data1['item'] == 'reaction':\n", " for bz1 in mx:\n", " if result > bz1:\n", " #print(bz1)\n", " score = mx.index(bz1,0)\n", " break\n", " else:\n", " score = 5\n", " else:\n", " for bz1 in mx:\n", " if result < bz1:\n", " #print(bz1)\n", " score = mx.index(bz1,0)\n", " break\n", " else:\n", " score = 5\n", " return(score)\n", "filename = 'data/体质检测标准_BMI.json'\n", "with open(filename,'r') as fl:\n", " dict4 = json.load(fl) \n", " \n", "def cal_bmi(data1):\n", " # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n", " person = dict4['person']\n", " criteria = dict4['criteria']\n", " if data1['age'] > 59:\n", " data1['age'] = 59\n", " if data1['age'] <20:\n", " data1['age'] = 20\n", " info = data1['sex']+str(data1['age'])\n", " bz = person[info]\n", " #print(bz)\n", " result = data1['result']\n", " #print(data1['code'],result)\n", " height = int(float(result.split(',')[0]))\n", " weight = float(result.split(',')[1])\n", " if str(height) not in criteria[bz]:\n", " score = 1\n", " else: \n", " mx = criteria[bz][str(height)]\n", " if weight < mx[0]:\n", " score = 1\n", " elif weight < mx[1]:\n", " score = 3\n", " elif weight < mx[2]:\n", " score = 5 \n", " elif weight <= mx[3]:\n", " score = 3 \n", " elif weight > mx[3]:\n", " score = 1\n", " return score\n", " \n", " \n", "\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", " #print(k)\n", " if v['sex'] == '男':\n", " sex = 'M'\n", " else:\n", " sex = 'F' \n", " if 'height' in v.keys() and 'weight' in v.keys():\n", " bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n", " dict2[k]['bmi'] = {}\n", " dict2[k]['bmi']['成绩'] = bmi_data\n", " dict2[k]['bmi']['score'] = cal_bmi(data1)\n", " for item_en in list_item:\n", " if item_en in v.keys(): \n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n", " #print(k,v['name'])\n", " dict2[k][item_en]['score'] = cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", "filename = f'data/result_北海炼化2023.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " ] }, { "cell_type": "markdown", "id": "abace6bc-9c99-497d-a1c1-9ff045ccfc03", "metadata": {}, "source": [ "## 生成体测成绩明细表" ] }, { "cell_type": "code", "execution_count": null, "id": "f0608de5-07ae-458c-999e-60968314f058", "metadata": { "tags": [] }, "outputs": [], "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_北海炼化2023.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]['unit'])\n", " #list2.append(dict1[k]['phone'])\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": "5f46d541-c7db-4adf-b452-d901c757e9c5", "metadata": {}, "source": [ "## 查询参加问卷未参加体测人员" ] }, { "cell_type": "code", "execution_count": null, "id": "2c867c7f-00b4-4a41-a6eb-18d6c39fa4cc", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/北海炼化2023年.json'\n", "with open(filename,'r') as fl:\n", " dict3 = json.load(fl)\n", "\n", "phone = set()\n", "phone1 = set()\n", "for k,v in dict3.items():\n", " phone.add(v['phone'])\n", "for k,v in dict1.items():\n", " phone1.add(v['phone'])\n", "list1 = []\n", "filename = 'data/Survey_20231122.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", "\n", "for item in list1:\n", " if item[2] in phone and item[2] not in phone1:\n", " print(item[2])\n", " " ] }, { "cell_type": "markdown", "id": "33b0075e-5b48-44ed-9cc7-f316ad9a0237", "metadata": {}, "source": [ "## 核对报告缺失情况" ] }, { "cell_type": "code", "execution_count": null, "id": "2e5ae18e-c153-4cdf-825e-f969080eea16", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import glob\n", "from pathlib import Path\n", "\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "fi_path = '/home/songyi/pdf-typescript/北海炼化2023_1'\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", "list1 = []\n", "for fl in fls:\n", " fn = Path(fl).stem.split('-')[0]\n", " list1.append(int(fn))\n", "print(len(dict1))\n", "for k ,v in dict1.items():\n", " if int(k) not in list1:\n", " print(k,v['name'])" ] }, { "cell_type": "markdown", "id": "e7e0e29c-0f12-4478-b687-a03486adc85e", "metadata": {}, "source": [ "## 报告按部门分类" ] }, { "cell_type": "code", "execution_count": null, "id": "3ff8ad3c-7868-4eb2-b879-4e8da19407ff", "metadata": {}, "outputs": [], "source": [ "import os,sys,shutil\n", "import json\n", "import glob\n", "from pathlib import Path\n", "\n", "fi_path = '/home/songyi/pdf-typescript/134'\n", "new_path = 'file/134'\n", "old = []\n", "dict2 = {}\n", "\n", "filename = 'data/天津石化人员名单2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", "for fn in fls:\n", " fi_name =Path(fn).stem.split('-')[0]\n", " code = int(fi_name)\n", " unit_path = Path(new_path,dict1[str(code)]['unit'])\n", " unit_path.mkdir(parents = True, exist_ok = True)\n", " n_name = Path(unit_path,Path(fn).stem+'.pdf')\n", " if not os.path.exists(n_name):\n", " shutil.copyfile(fn,n_name)\n", " #print(n_name)" ] }, { "cell_type": "markdown", "id": "abe43620-c456-43a0-905a-b29aad8b2e3c", "metadata": {}, "source": [ "## 核对新部门分类人员" ] }, { "cell_type": "code", "execution_count": null, "id": "a3f1476d-5f70-45c4-aa04-ebc6558033b8", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "filename = 'data/result_北海炼化2023.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "\n", "wb = openpyxl.load_workbook('data/北海炼化新名单.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "list1 = []\n", "\n", "for n in range(5, sheet.max_row+1):\n", " if sheet.cell(n,2).value is not None:\n", " list1.append(sheet.cell(n,2).value)\n", "print(len(list1)) \n", "i = 1\n", "for k, v in dict1.items():\n", " name = v['name']\n", " if name not in list1:\n", " print(i,name)\n", " i+=1" ] }, { "cell_type": "markdown", "id": "a51dadfb-30e7-40f3-a437-321aa986a10f", "metadata": {}, "source": [ "# 北海体检情况汇总" ] }, { "cell_type": "code", "execution_count": null, "id": "7410324c-92c2-4a20-9715-f003d4915c8a", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "wb = openpyxl.load_workbook('data/北海体检报告数据整理2024.xlsx')\n", "#sheet = wb.active\n", "# sheets = wb.sheetnames\n", "sheet = wb['Sheet3']\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, 7).value) \n", " \n", "filename = 'data/北海炼化2023年健康体检团体报告.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/中国石化北海炼化有限责任公司2023年职业体检团体报告汇总统计表.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": "3cb5a5c9-e3d5-4959-a085-b3a34d778334", "metadata": {}, "source": [ "## 统计体检项目" ] }, { "cell_type": "code", "execution_count": null, "id": "28825d80-9123-4ec5-b107-9ad133f11a82", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "wb = openpyxl.load_workbook('data/北海体检报告数据整理2024.xlsx')\n", "#sheet = wb.active\n", "# sheets = wb.sheetnames\n", "sheet = wb['原始']\n", "xm = set()\n", "list1 = []\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:\n", " break\n", " else: \n", " xm.add(sheet.cell(n, 6).value) \n", "for i, item in enumerate(xm):\n", " list1.append([i+1,item])\n", "filename = 'data/中国石化北海炼化有限责任公司2023年体检指标统计表1.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "title = ['序号','项目名称']\n", "sheet.append(title)\n", "for row in list1:\n", " sheet.append(row)\n", " \n", "wb.save(filename) " ] }, { "cell_type": "markdown", "id": "ff38ecf9-0ef5-473e-a253-a29196c00307", "metadata": {}, "source": [ "## 统计北海APP用户信息" ] }, { "cell_type": "code", "execution_count": 15, "id": "5049ac44-3bf8-4759-8e1a-3345cc0bedf6", "metadata": { "execution": { "iopub.execute_input": "2025-12-23T11:34:46.322569Z", "iopub.status.busy": "2025-12-23T11:34:46.322137Z", "iopub.status.idle": "2025-12-23T11:34:46.342939Z", "shell.execute_reply": "2025-12-23T11:34:46.342438Z", "shell.execute_reply.started": "2025-12-23T11:34:46.322545Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "张伟 18419216343\n", "李辉 18278953177\n", "刘涛 18066959139\n", "陈伟 13977908579\n", "沈鹏 13877945246\n", "王勇 13006999505\n", "李华 13949350582\n", "赵敏 13977996075\n", "张健 15278902286\n", "王勇 13397798753\n", "兰俊 13000000400\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "title = []\n", "\n", "filename = 'data/tb_user.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "dict2 = {}\n", "for item in dict1:\n", " id = item['id']\n", " dict2.setdefault(id,{})\n", " dict2[id] ['name']= item['username']\n", " dict2[id] ['phone']= str(item['mobile'])\n", " dict2[id] ['unit']= item['dept']\n", " dict2[id] ['birth']= item['birthday']\n", "for k,v in dict2.items():\n", " if v['name'] in list1:\n", " print(v['name'],v['phone'])\n", " else:\n", " list1.append(v['name'])\n" ] }, { "cell_type": "code", "execution_count": 16, "id": "865ece6f-2d6f-4ae8-a59d-81e2a4bfbbc3", "metadata": { "execution": { "iopub.execute_input": "2025-12-23T11:34:51.869483Z", "iopub.status.busy": "2025-12-23T11:34:51.868754Z", "iopub.status.idle": "2025-12-23T11:34:52.535335Z", "shell.execute_reply": "2025-12-23T11:34:52.534820Z", "shell.execute_reply.started": "2025-12-23T11:34:51.869418Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "995\n", "张伟 18419216343\n", "李辉 18278953177\n", "刘涛 18066959139\n", "陈伟 13977908579\n", "沈鹏 13877945246\n", "王勇 13006999505\n", "李华 13949350582\n", "赵敏 13977996075\n", "张健 15278902286\n", "王勇 13397798753\n", "兰俊 13000000400\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "title = []\n", "\n", "filename = 'data/tb_user.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "dict2 = {}\n", "for item in dict1:\n", " id = item['id']\n", " dict2.setdefault(id,{})\n", " dict2[id] ['name']= item['username']\n", " dict2[id] ['phone']= item['mobile']\n", " dict2[id] ['unit']= item['dept']\n", " dict2[id] ['birth']= item['birthday']\n", "print(len(dict2))\n", "for k,v in dict2.items():\n", " if v['name'] in list1:\n", " print(v['name'],v['phone'])\n", " else:\n", " list1.append(v['name'])\n", "wb = openpyxl.load_workbook('data/北海炼化职业体检数据-11.23.xlsx')\n", "#sheet = wb.active\n", "# sheets = wb.sheetnames\n", "sheet = wb['2024']\n", "\n", "list2 = []\n", "for n in range(2, sheet.max_row+1):\n", " name = sheet.cell(n, 2).value\n", " phone = str(sheet.cell(n, 6).value)\n", " for k,v in dict2.items():\n", " if v['name'] ==name and v['phone']== phone:\n", " list2.append(str(sheet.cell(n, 1).value))\n", "for n in range(2, sheet.max_row+1):\n", " code = str(sheet.cell(n, 1).value)\n", " name = sheet.cell(n, 2).value\n", " phone = str(sheet.cell(n, 6).value)\n", " if code not in list2:\n", " for k,v in dict2.items():\n", " if v['name'] ==name and v['phone']!= phone:\n", " print(code,v['name'],phone,v['phone'],v['birth'])" ] }, { "cell_type": "markdown", "id": "76c5c17a-462d-4a7b-95a5-6b895f5a25dc", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# 2024年体质检测" ] }, { "cell_type": "markdown", "id": "b638855a-6540-44af-8f1c-796535a02a50", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": null, "id": "c9262823-f492-4934-a0ce-f8f80c4a1bea", "metadata": {}, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/北海人员202410.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "\n", "for n in range(3, sheet.max_row+1):\n", " if sheet.cell(n, 1).value is not None:\n", " #print(sheet.cell(n, 1).value)\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, 6).value\n", " dict1['phone'] = sheet.cell(n, 5).value\n", " dict1['birth'] = sheet.cell(n,4).value\n", " person[code] = dict1\n", "\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": "bf58deff-7f90-4828-976d-a78858326853", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": null, "id": "ffd34b08-40fd-45c5-a2d3-33c460c7b1dd", "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/北海炼化人员2024.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", " 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/card_北海炼化人员2024.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "33633f3a-e2ff-4703-850f-a5b82c0a6280", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": null, "id": "e1a1b329-acf1-4be9-bcf0-736dbe7f8e0b", "metadata": {}, "outputs": [], "source": [ "import json\n", "import datetime\n", "import csv\n", "from datetime import date\n", "\n", "\n", "re_ta = {}\n", "list1 = []\n", "filename = 'data/北海炼化人员2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/marks_20241201.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", "\n", "for result in list1:\n", " user = str(result[2])\n", " rq = date.fromisoformat(result[5].replace('/','-'))\n", " if user in dict1.keys():\n", " l_xm = []\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", " if 'phone' in dict1[user].keys():\n", " re_ta[user]['phone'] = dict1[user]['phone']\n", " if dict1[user]['sex'] == '男':\n", " l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step']\n", " else:\n", " l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp']\n", " re_ta[user]['unit'] = dict1[user]['unit']\n", " birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n", " item_name = result[3] \n", " if item_name in l_xm: \n", " days = (rq-birth).days \n", " re_ta[user]['age'] = int(days/365)\n", " re_ta[user]['month'] = int(days/365*12)\n", " re_ta[user]['rq'] = result[5]\n", " re_ta[user].setdefault(item_name,{}) \n", " score = result[4] \n", " re_ta[user][item_name]['成绩'] = score\n", "\n", "filename = 'data/result_北海炼化2024.json'\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": "beaccc86-fddc-4207-b0d6-2124800ff0fd", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": null, "id": "17ebb0fd-9a45-47a4-bbe9-f4fb0a3481f6", "metadata": {}, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\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", " 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", " if 'bmi' in v.keys():\n", " height = v['bmi']['成绩'].split(',')[0]\n", " weight = v['bmi']['成绩'].split(',')[1]\n", " list2.append(height)\n", " list2.append(weight)\n", " else:\n", " list2.append('')\n", " list2.append('')\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", " \n", " list1.append(list2)\n", "filename = 'data/北海炼化体测情况表2024.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": "0be2a006-d1c9-4c0f-b1e0-ed347aa5b7ad", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": null, "id": "dd89efe8-13b9-4db8-8c39-2a48888dd635", "metadata": {}, "outputs": [], "source": [ "import json\n", "import time\n", "import my_module as My\n", "\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", "filename = 'data/result_北海炼化2024.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", " #print(k)\n", " if v['sex'] == '男':\n", " sex = 'M'\n", " else:\n", " sex = 'F' \n", " if 'bmi' in v.keys():\n", " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", " bmi_data = v['bmi']['成绩']\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n", " dict2[k]['bmi'] = {}\n", " dict2[k]['bmi']['成绩'] = bmi_data\n", " dict2[k]['bmi']['score'] = My.cal_bmi(data1)\n", " for item_en in list_item:\n", " if item_en in v.keys(): \n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n", " #print(k,v['name'])\n", " dict2[k][item_en]['score'] = My.cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", "filename = f'data/result_北海炼化2024.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " ] }, { "cell_type": "code", "execution_count": null, "id": "c5846968-1f2e-46b5-a79c-e2f129e5c233", "metadata": {}, "outputs": [], "source": [ "import json\n", "import time\n", "import my_module as My\n", "\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", "filename = 'data/result_北海炼化2022-1.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", " #print(k)\n", " if v['sex'] == '男':\n", " sex = 'M'\n", " else:\n", " sex = 'F' \n", " if 'bmi' in v.keys():\n", " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", " bmi_data = v['bmi']['成绩']\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n", " dict2[k]['bmi'] = {}\n", " dict2[k]['bmi']['成绩'] = bmi_data\n", " dict2[k]['bmi']['score'] = My.cal_bmi(data1)\n", " for item_en in list_item:\n", " if item_en in v.keys(): \n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n", " #print(k,v['name'])\n", " dict2[k][item_en]['score'] = My.cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", "filename = f'data/result_北海炼化2022-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " ] }, { "cell_type": "markdown", "id": "5b9aef88-0341-4af0-8316-c7e2266f4b0c", "metadata": {}, "source": [ "## 统计参加问卷手机号码未提供人员" ] }, { "cell_type": "code", "execution_count": null, "id": "25004a96-c72c-4bbb-91e1-5bfccb7856c3", "metadata": {}, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "filename = 'data/北海炼化人员2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "phone1 = set()\n", "phone2 = set()\n", "for k,v in dict1.items():\n", " phone1.add(v['phone'])\n", "list1 = []\n", "filename = 'data/Survey_20241224.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", "\n", "for item in list1:\n", " if item[2] not in phone1:\n", " phone2.add(item[2])\n", "for item in phone2:\n", " print(i,item)\n", " i+=1\n", " " ] }, { "cell_type": "markdown", "id": "cca613c5-1fe3-465a-ab66-ca395e4bda9c", "metadata": {}, "source": [ "## 统计参加问卷人员" ] }, { "cell_type": "code", "execution_count": null, "id": "601f707b-bd34-4966-b781-c520a0bf69dc", "metadata": {}, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "filename = 'data/北海炼化人员2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "phone1 = set()\n", "phone2 = set()\n", "for k,v in dict1.items():\n", " phone1.add(v['phone'])\n", "list1 = []\n", "filename = 'data/Survey_20241224.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(len(phone1))\n", "i =1\n", "list2 = []\n", "for item in list1:\n", " code = item[2]\n", " for k, v in dict1.items():\n", " list3 = []\n", " if v['phone'] == code: \n", " list3.append(k)\n", " list3.append(v['name'])\n", " list3.append(v['sex'])\n", " list3.append(v['unit'])\n", " list3.append(code)\n", " list2.append(list3)\n", "filename = 'data/北海炼化问卷情况表2024.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) " ] }, { "cell_type": "markdown", "id": "b57447d9-ac3c-47c2-9592-3878c6845918", "metadata": {}, "source": [ "## 导入问卷" ] }, { "cell_type": "code", "execution_count": null, "id": "9563c47b-94e4-44f7-98e1-7d284ad3841c", "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_20241206.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", "for i in range(0,45):\n", " psy.append(0)\n", "psy[44] = []\n", "for i in range(0,60):\n", " tcm.append(0)\n", "for i in range(0,26):\n", " spine.append(0)\n", "\n", "for item in list1:\n", " if item[2] in phone.keys():\n", " psy =[]\n", " tcm = []\n", " spine = []\n", " for i in range(0,45):\n", " psy.append(0)\n", " psy[44] = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for i in range(0,26):\n", " spine.append(0)\n", " \n", " content = json.loads(item[5])\n", " if phone[item[2]] not in dict1.keys():\n", " dict1[phone[item[2]]] = dict3[phone[item[2]]]\n", " rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n", " for k, v in content.items():\n", " if 'psy' in k:\n", " i = int(k[3:])\n", " psy[i-1] = int(v)\n", " if 'tcm' in k:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " if 'spine' in k:\n", " i = int(k[5:])\n", " spine[i-1] = int(v)\n", " if 'psy' in item[5]:\n", " #for i in range(5,26):\n", " # new_valve = 5-psy[i]\n", " # psy[i] = new_valve\n", " for i in range(26,40):\n", " new_valve = 1+psy[i]\n", " psy[i] = new_valve\n", " \n", " dict1[phone[item[2]]]['psy'] = psy\n", " if 'tcm' in item[5]:\n", " dict1[phone[item[2]]]['tcm'] = tcm\n", " if 'spine' in item[5]:\n", " dict1[phone[item[2]]]['spine'] = spine\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.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False) " ] }, { "cell_type": "markdown", "id": "378982cd-8f4a-4b61-a87c-a138eb891342", "metadata": {}, "source": [ "## 生成体测成绩明细表" ] }, { "cell_type": "code", "execution_count": null, "id": "a1a12409-aab8-47af-b10d-7ecb20b3b332", "metadata": {}, "outputs": [], "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]['unit'])\n", " i = 0\n", " if 'bmi' in dict1[k].keys():\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[0])\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[1])\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/北海炼化体测情况明细表(2024年).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": "98e43475-06ca-42bc-b352-5c92a554e2c2", "metadata": {}, "outputs": [], "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_北海炼化2022-1.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]['unit'])\n", " i = 0\n", " if 'bmi' in dict1[k].keys():\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[0])\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[1])\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/北海炼化体测情况明细表(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)\n", "print('ok') " ] }, { "cell_type": "markdown", "id": "b46477dd-f9d0-40b8-ae25-62f3ffb5dc1e", "metadata": {}, "source": [ "## 统计各部门测试情况" ] }, { "cell_type": "code", "execution_count": null, "id": "c4095c79-aeb7-40a7-a3a4-026fb7be8180", "metadata": {}, "outputs": [], "source": [ "import json\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", " dict2 = json.load(fl)\n", "\n", "dict3 = {}\n", "for k, v in dict2.items():\n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " dict3.setdefault(unit,{})\n", " dict3[unit].setdefault('人数',0)\n", " #dict3[unit].setdefault(sub_unit,0)\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] + 1\n", " dict3[unit]['人数'] = dict3[unit]['人数'] + 1\n", "\n", "title =['单位','体测人数']\n", "list1 = []\n", "for k,v in dict1.items(): \n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] - 1\n", " dict3[unit].setdefault('体测人数',0)\n", " dict3[unit]['体测人数'] = dict3[unit]['体测人数'] + 1\n", "for k, v in dict3.items():\n", " list2 = [k,v['人数'],v['体测人数']]\n", " list1.append(list2)\n", "\n", "filename = 'data/北海炼化部门测试情况2024.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": "f65ac3f5-07fd-4191-a9ce-f71312aec993", "metadata": {}, "source": [ "## 统计各部门未参加人员信息" ] }, { "cell_type": "code", "execution_count": null, "id": "974edd35-7203-4387-8673-ffba537ee160", "metadata": {}, "outputs": [], "source": [ "import json\n", "import openpyxl\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", " dict2 = json.load(fl)\n", "\n", "list1 = []\n", "\n", "i = 1\n", "for k, v in dict2.items():\n", " \n", " if k not in dict1.keys():\n", " list2 = [i,k,v['name'],v['unit']]\n", " i+=1\n", " list1.append(list2)\n", "filename = f'data/北海炼化未测试人员名单.xlsx'\n", "title = ['序号','员工编号','姓名','部门']\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list1:\n", " sheet.append(row) \n", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "16bf831a-e725-47d4-87bb-0103ae55f8a6", "metadata": {}, "source": [ "## 清理报告数据" ] }, { "cell_type": "code", "execution_count": null, "id": "6d8a345d-39e0-40cd-9bed-ac4e144b426c", "metadata": {}, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "filename = 'data/result_北海炼化2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", " \n", "#items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "items = {}\n", "items['lung'] = '肺活量'\n", "items['grip'] ='握力'\n", "items['flexion'] ='坐位体前屈'\n", "items['jump'] ='纵跳'\n", "items['pushup'] ='俯卧撑'\n", "items['balance'] ='单脚站立'\n", "items['reaction'] ='选择反应时'\n", "items['step'] ='台阶指数'\n", "items['situp'] ='一分钟仰卧起坐'\n", "items['bmi'] ='BMI'\n", "\n", "\n", "list1 = []\n", "\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", "i=1\n", "list2 = []\n", "dict2 = {}\n", "for k, v in dict1.items():\n", " list1 = []\n", " mydata = {}\n", " \n", " id = str(k).rjust(5,\"0\")\n", " mydata['unit'] = v['unit']\n", " mydata['name'] = v['name']\n", " mydata['sex'] = v['sex']\n", " mydata['month'] = v['month']\n", " age = int(v['month']/12)\n", " if age <20:\n", " mydata['age'] = 20\n", " else:\n", " mydata['age'] = int(v['month']/12)\n", " \n", " mydata['fits'] = {}\n", " score = 0\n", " for item in list_item:\n", " if item in v.keys():\n", " if item in ['lung','pushup','step','situp']:\n", " mark = v[item]['成绩'].split()[0].split('.')[0]\n", " else:\n", " mark = v[item]['成绩'].split()[0]\n", " mydata['fits'][items[item]] = {'mark':mark,'score':v[item]['score']}\n", " score = score + v[item]['score']\n", " mydata['score'] = round(score/len(mydata['fits']),2)\n", " if len(mydata['fits']) >2:\n", " dict2[str(k)] = mydata\n", "filename = f'data/data_北海炼化2024.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print(len(dict2))\n", "print('ok!')" ] }, { "cell_type": "code", "execution_count": null, "id": "6cba8d5e-92fd-4afd-94d2-0dcf42e2e22e", "metadata": {}, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "filename = 'data/result_北海炼化2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list2 = []\n", "for k,v in dict1.items():\n", " #list2 = []\n", " list2.append([k,v['name'],v['sex'],v['age'],v['unit']])\n", " \n", "filename = 'data/北海人员基本情况2024.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "\n", "for row in list2:\n", " sheet.append(row)\n", " \n", "wb.save(filename)\n", "print(len(dict1))\n", "print('ok') " ] }, { "cell_type": "markdown", "id": "75ee44f4-2874-44eb-b071-7666f52a60f1", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# 2025年体质检测" ] }, { "cell_type": "markdown", "id": "78f7f826-1f38-4c8d-8483-ddde43dce321", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 13, "id": "58f6dbab-9ea2-4295-ae78-36951b67c2d3", "metadata": { "execution": { "iopub.execute_input": "2025-11-17T07:32:41.466054Z", "iopub.status.busy": "2025-11-17T07:32:41.465351Z", "iopub.status.idle": "2025-11-17T07:32:41.591984Z", "shell.execute_reply": "2025-11-17T07:32:41.591337Z", "shell.execute_reply.started": "2025-11-17T07:32:41.465990Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "880 ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "from datetime import date\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 = 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['birth'] = str(sheet.cell(n, 7).value).replace('/','-').split(' ')[0] \n", " dict1['unit'] = sheet.cell(n, 6).value\n", " dict1['phone'] = str(sheet.cell(n, 5).value)\n", " dict1['id'] = sheet.cell(n, 4).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(len(person),'ok')" ] }, { "cell_type": "markdown", "id": "ae6b80a0-fe84-42eb-9fb6-c7844b0aa268", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": null, "id": "dbe52ce7-f801-44c6-b675-f0a84867c4d9", "metadata": {}, "outputs": [], "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/card_北海炼化2025.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print(len(list1),'ok')" ] }, { "cell_type": "markdown", "id": "6139bf27-5367-451f-9f1a-f252625eab1d", "metadata": {}, "source": [ "## 合并读卡系统文件" ] }, { "cell_type": "code", "execution_count": null, "id": "2d7f5a24-f247-4199-a84d-dcf611dbeef6", "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/data_北海2025.json'\n", "with open(filename,'r') as fl:\n", " list1 = json.load(fl)\n", "for item in list1:\n", " code = item['id'].lower()\n", " if code not in dict1.keys():\n", " print(code,item['name'],item['unit'])\n", " code = code.lower()\n", " dict1.setdefault(code,{})\n", " dict1[code]['name'] = item['name']\n", " dict1[code]['sex'] = item['gender']\n", " dict1[code]['unit'] = item['unit']\n", " dict1[code]['birth'] = item['birth']\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(len(dict1),'ok')" ] }, { "cell_type": "code", "execution_count": 36, "id": "f143e8d3-9e9a-4c27-be8c-88a3e5f94f51", "metadata": { "execution": { "iopub.execute_input": "2025-11-18T03:19:39.385691Z", "iopub.status.busy": "2025-11-18T03:19:39.385436Z", "iopub.status.idle": "2025-11-18T03:19:39.399964Z", "shell.execute_reply": "2025-11-18T03:19:39.399394Z", "shell.execute_reply.started": "2025-11-18T03:19:39.385668Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "880 ok\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/data_北海2025.json'\n", "with open(filename,'r') as fl:\n", " list1 = json.load(fl)\n", "for item in list1:\n", " code = item['id'].lower()\n", " if code in dict1.keys():\n", " \n", " dict1[code]['unit'] = item['unit']\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(len(dict1),'ok')" ] }, { "cell_type": "markdown", "id": "cccfebad-8fc5-4aa9-b15d-05eff2fa421f", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 37, "id": "7b79c7bb-ce87-44b2-95b1-01e9cb66d5f0", "metadata": { "execution": { "iopub.execute_input": "2025-11-18T03:20:48.522459Z", "iopub.status.busy": "2025-11-18T03:20:48.521987Z", "iopub.status.idle": "2025-11-18T03:20:48.574117Z", "shell.execute_reply": "2025-11-18T03:20:48.573580Z", "shell.execute_reply.started": "2025-11-18T03:20:48.522337Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "759\n" ] } ], "source": [ "import json\n", "import datetime\n", "import csv\n", "from datetime import date\n", "import my_module as My\n", "\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/marks_20251113.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\n", "\n", "filename = 'data/result_北海2025.json'\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": "a7d2b973-cc05-4f06-9be8-54268a29dd84", "metadata": {}, "source": [ "## 导入手工数据" ] }, { "cell_type": "code", "execution_count": 38, "id": "458725a6-3b5b-48a1-af90-cd4d0bda3635", "metadata": { "execution": { "iopub.execute_input": "2025-11-18T03:20:56.396804Z", "iopub.status.busy": "2025-11-18T03:20:56.396056Z", "iopub.status.idle": "2025-11-18T03:20:56.449035Z", "shell.execute_reply": "2025-11-18T03:20:56.448467Z", "shell.execute_reply.started": "2025-11-18T03:20:56.396734Z" } }, "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", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "for n in range(2, sheet.max_row+1):\n", " code = str(sheet.cell(n, 1).value)\n", " dict1[code].setdefault('pushup',{})\n", " dict1[code]['pushup']['成绩'] = str(sheet.cell(n,2).value)\n", "filename = 'data/result_北海2025.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "aff5b1b6-a6af-44dd-beb0-cb2b68999496", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": 39, "id": "ef655e34-635b-4baa-97c3-925022f45949", "metadata": { "execution": { "iopub.execute_input": "2025-11-18T03:21:01.850425Z", "iopub.status.busy": "2025-11-18T03:21:01.849736Z", "iopub.status.idle": "2025-11-18T03:21:01.898524Z", "shell.execute_reply": "2025-11-18T03:21:01.897960Z", "shell.execute_reply.started": "2025-11-18T03:21:01.850354Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok!\n" ] } ], "source": [ "import json\n", "import time\n", "import my_module as My\n", "\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k, v in dict2.items():\n", " #print(k)\n", " if v['sex'] == '男':\n", " sex = 'M'\n", " else:\n", " sex = 'F' \n", " if 'bmi' in v.keys():\n", " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", " bmi_data = v['bmi']['成绩']\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n", " dict2[k]['bmi'] = {}\n", " dict2[k]['bmi']['成绩'] = bmi_data\n", " dict2[k]['bmi']['score'] = My.cal_bmi(data1)\n", " for item_en in list_item:\n", " if item_en in v.keys(): \n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n", " #print(k,v['name'])\n", " dict2[k][item_en]['score'] = My.cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", "filename = f'data/result_北海2025.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " ] }, { "cell_type": "markdown", "id": "12b33ee8-2b4e-4b85-9301-4fbcadf4129c", "metadata": {}, "source": [ "## 统计各部门测试情况" ] }, { "cell_type": "code", "execution_count": 53, "id": "ca079428-2df9-4f15-b141-2c83cd0efaf5", "metadata": { "execution": { "iopub.execute_input": "2025-11-11T09:33:39.776590Z", "iopub.status.busy": "2025-11-11T09:33:39.775794Z", "iopub.status.idle": "2025-11-11T09:33:39.805844Z", "shell.execute_reply": "2025-11-11T09:33:39.805299Z", "shell.execute_reply.started": "2025-11-11T09:33:39.776523Z" } }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "dict3 = {}\n", "for k, v in dict2.items():\n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " dict3.setdefault(unit,{})\n", " dict3[unit].setdefault('人数',0)\n", " dict3[unit].setdefault('体测人数',0)\n", " #dict3[unit].setdefault(sub_unit,0)\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] + 1\n", " dict3[unit]['人数'] = dict3[unit]['人数'] + 1\n", "\n", "title =['单位','报名人数','体测人数']\n", "list1 = []\n", "for k,v in dict1.items(): \n", " unit = v['unit']\n", " #sub_unit = v['sub_unit']\n", " #dict3[unit][sub_unit] = dict3[unit][sub_unit] - 1\n", " dict3[unit].setdefault('体测人数',0)\n", " dict3[unit]['体测人数'] = dict3[unit]['体测人数'] + 1\n", "for k, v in dict3.items():\n", " list2 = [k,v['人数'],v['体测人数']]\n", " list1.append(list2)\n", "\n", "filename = 'data/北海炼化部门测试情况(截至20251111).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": "c3df2ac7-1ef3-4f76-a4ed-a2e8f9ecafcc", "metadata": {}, "source": [ "## 统计未体测人员明细表" ] }, { "cell_type": "code", "execution_count": 54, "id": "482a3a46-31a6-433b-88a8-7cad228f853a", "metadata": { "execution": { "iopub.execute_input": "2025-11-11T09:33:43.302910Z", "iopub.status.busy": "2025-11-11T09:33:43.302201Z", "iopub.status.idle": "2025-11-11T09:33:43.341073Z", "shell.execute_reply": "2025-11-11T09:33:43.339404Z", "shell.execute_reply.started": "2025-11-11T09:33:43.302855Z" } }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "list1 = []\n", "\n", "i = 1\n", "for k, v in dict2.items(): \n", " if k not in dict1.keys():\n", " list2 = [i,k,v['name'],v['unit']]\n", " i+=1\n", " list1.append(list2)\n", "#print(list1)\n", "filename = f'data/北海炼化未测试人员名单(截至20251110).xlsx'\n", "title = ['序号','员工编号','姓名','部门']\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list1:\n", " sheet.append(row) \n", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "bafcb189-a7b4-45bc-977a-9d7893938184", "metadata": {}, "source": [ "## 问卷人员统计" ] }, { "cell_type": "code", "execution_count": 16, "id": "0bbf2cb6-e7d9-4d0d-beba-77ac50082f05", "metadata": { "execution": { "iopub.execute_input": "2025-11-17T07:33:16.521656Z", "iopub.status.busy": "2025-11-17T07:33:16.520913Z", "iopub.status.idle": "2025-11-17T07:33:16.617830Z", "shell.execute_reply": "2025-11-17T07:33:16.617274Z", "shell.execute_reply.started": "2025-11-17T07:33:16.521587Z" } }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "list1 = []\n", "filename = 'data/sql_20251117.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", "filename = 'data/北海炼化人员2025.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[str(v['phone'])] = k\n", "dict2 = {}\n", "list3 = []\n", "for item in list1: \n", " phone_num = str(item[0])[2:] \n", " if phone_num in phone:\n", " list2 = []\n", " content = json.loads(json.loads(item[1])) \n", " code = phone[phone_num]\n", " list2 = [code,dict3[code]['name'],dict3[code]['unit'],phone_num]\n", " list3.append(list2)\n", "title =['测试编号','姓名','部门','手机号码']\n", "filename = 'data/北海炼化问卷人员(截至20251116).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list3:\n", " sheet.append(row)\n", " \n", "wb.save(filename)" ] }, { "cell_type": "markdown", "id": "60d7de83-75aa-44bf-99da-492627032ca1", "metadata": {}, "source": [ "## 问卷不符合信息人员" ] }, { "cell_type": "code", "execution_count": 12, "id": "d3c0061f-fc24-483e-8e93-08872c77547f", "metadata": { "execution": { "iopub.execute_input": "2025-11-17T01:29:17.936230Z", "iopub.status.busy": "2025-11-17T01:29:17.935493Z", "iopub.status.idle": "2025-11-17T01:29:17.974203Z", "shell.execute_reply": "2025-11-17T01:29:17.973659Z", "shell.execute_reply.started": "2025-11-17T01:29:17.936162Z" } }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "list1 = []\n", "filename = 'data/sql_20251117.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", "filename = 'data/北海炼化人员2025.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[str(v['phone'])] = k\n", "dict2 = {}\n", "list3 = []\n", "for item in list1: \n", " phone_num = str(item[0])[2:] \n", " if phone_num not in phone:\n", " list2 = []\n", " content = json.loads(json.loads(item[1])) \n", " code = phone_num\n", " list2 = [code,content['name'],content['birth'],content['gender']]\n", " list3.append(list2)\n", "title =['测试编号','姓名','部门','手机号码']\n", "filename = 'data/北海炼化问卷信息不符合人员(截至20251116).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list3:\n", " sheet.append(row)\n", " \n", "wb.save(filename)" ] }, { "cell_type": "code", "execution_count": 8, "id": "277fce35-2f95-4d52-8cab-4e27c9acd7b8", "metadata": { "execution": { "iopub.execute_input": "2025-11-17T01:22:21.248136Z", "iopub.status.busy": "2025-11-17T01:22:21.247270Z", "iopub.status.idle": "2025-11-17T01:22:21.339031Z", "shell.execute_reply": "2025-11-17T01:22:21.338544Z", "shell.execute_reply.started": "2025-11-17T01:22:21.248063Z" } }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "dict1 = {}\n", "list1 = []\n", "list2 = set()\n", "filename = 'data/sql_20251117.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", "nn = 0\n", "for item in list1:\n", " dict2 = {} \n", " phone = str(item[0])[2:]\n", " content = json.loads(json.loads(item[1]))\n", " tcm = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for k, v in content.items(): \n", " if 'tcm' not in k:\n", " dict2[k] = v\n", " else:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " \n", " code = phone\n", " list2.add(code)\n", " dict1.setdefault(code,{})\n", " dict1[code]['name'] = content['name']\n", " if content['gender'] == 'male':\n", " dict1[code]['sex'] = '男'\n", " else:\n", " dict1[code]['sex'] = '女'\n", " dict1[code]['birth'] = str(content['birth'])\n", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "i = 1\n", "list3 = []\n", "for k,v in dict2.items():\n", " phone = str(v['phone'])\n", " if phone not in list2:\n", " list4 = []\n", " list4 = [phone,v['name'],v['unit']]\n", " list3.append(list4)\n", "title =['手机号码','姓名','部门']\n", "filename = 'data/北海炼化未参加问卷人员(截至20251116).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", "for row in list3:\n", " sheet.append(row)\n", " \n", "wb.save(filename)\n", "\n", " " ] }, { "cell_type": "markdown", "id": "e67ca2e1-a537-4eb4-9494-bfcf77139078", "metadata": {}, "source": [ "## 问卷信息统计" ] }, { "cell_type": "code", "execution_count": 6, "id": "f67f63d1-be8a-47ef-b95f-bdfca9725838", "metadata": { "execution": { "iopub.execute_input": "2025-11-17T01:19:30.426467Z", "iopub.status.busy": "2025-11-17T01:19:30.425891Z", "iopub.status.idle": "2025-11-17T01:19:30.551084Z", "shell.execute_reply": "2025-11-17T01:19:30.550545Z", "shell.execute_reply.started": "2025-11-17T01:19:30.426412Z" } }, "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "\n", "dict1 = {}\n", "list1 = []\n", "filename = 'data/sql_20251117.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", "nn = 0\n", "for item in list1:\n", " dict2 = {}\n", " \n", " phone = str(item[0])[2:]\n", " content = json.loads(json.loads(item[1]))\n", " tcm = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for k, v in content.items(): \n", " if 'tcm' not in k:\n", " dict2[k] = v\n", " else:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " \n", " code = phone\n", " dict1.setdefault(code,{})\n", " dict1[code]['name'] = content['name']\n", " if content['gender'] == 'male':\n", " dict1[code]['sex'] = '男'\n", " else:\n", " dict1[code]['sex'] = '女'\n", " dict1[code]['birth'] = str(content['birth'])\n", " dict1[code]['unit'] = '北海炼化'\n", " #dict1[code]['phone'] = phone\n", " #dict1[code]['weight'] = dict2['weight']\n", " #dict1[code]['waist'] = dict2['waist']\n", " #dict1[code]['hip'] = dict2['hip']\n", " dict1[code]['tcm'] = tcm\n", "list1 = []\n", "for k, v in dict1.items():\n", " list2 = [k,v['name'],v['sex'],v['birth']]\n", " list1.append(list2)\n", "title =['手机号码','姓名','性别','出生年月']\n", "filename = 'data/北海炼化问卷人员(截至20251116).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": "9cb5f45e-15e5-4cf5-b82f-38e33729bad8", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": 61, "id": "3a0f5f5d-2bf0-46c8-b796-661e2f44c60c", "metadata": { "execution": { "iopub.execute_input": "2025-11-13T05:51:13.926738Z", "iopub.status.busy": "2025-11-13T05:51:13.925983Z", "iopub.status.idle": "2025-11-13T05:51:14.123325Z", "shell.execute_reply": "2025-11-13T05:51:14.122772Z", "shell.execute_reply.started": "2025-11-13T05:51:13.926666Z" } }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/北海炼化人员2025.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", " list2.append(dict2[k]['birth'])\n", " if 'phone' in v.keys():\n", " list2.append(dict2[k]['phone'])\n", " else:\n", " list2.append('')\n", " \n", " if 'bmi' in v.keys():\n", " height = v['bmi']['成绩'].split(',')[0]\n", " weight = v['bmi']['成绩'].split(',')[1]\n", " list2.append(height)\n", " list2.append(weight)\n", " else:\n", " list2.append('')\n", " list2.append('')\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", " \n", " list1.append(list2)\n", "filename = 'data/北海炼化体测情况表(2025年).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": "fc7701c1-0ce3-4fb9-a8eb-c9f8f2d44337", "metadata": {}, "source": [ "## 导入问卷信息" ] }, { "cell_type": "code", "execution_count": 40, "id": "4628f644-a571-4f2b-8d7b-e6b60b2ddcfd", "metadata": { "execution": { "iopub.execute_input": "2025-11-18T03:24:38.906208Z", "iopub.status.busy": "2025-11-18T03:24:38.905689Z", "iopub.status.idle": "2025-11-18T03:24:39.068007Z", "shell.execute_reply": "2025-11-18T03:24:39.067392Z", "shell.execute_reply.started": "2025-11-18T03:24:38.906160Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "781\n" ] } ], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "import time\n", "from datetime import date\n", "\n", "list1 = []\n", "filename = 'data/sql_20251117.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", "filename = 'data/北海炼化人员2025.json'\n", "with open(filename,'r') as fl:\n", " dict3 = json.load(fl)\n", "filename = 'data/result_北海2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "phone = {}\n", "for k,v in dict3.items():\n", " if 'phone' in v.keys():\n", " phone[str(v['phone'])] = k\n", "\n", "\n", "\n", "nn = 0\n", "for item in list1:\n", " dict2 = {}\n", " \n", " phone_num = str(item[0])[2:]\n", " if phone_num in phone:\n", " content = json.loads(json.loads(item[1]))\n", " tcm = []\n", " spine = []\n", " psy = []\n", " for i in range(0,45):\n", " psy.append(0)\n", " psy[44] = []\n", " for i in range(0,60):\n", " tcm.append(0)\n", " for i in range(0,26):\n", " spine.append(0)\n", " for k, v in content.items(): \n", " if 'psy' in k:\n", " i = int(k[3:])\n", " psy[i-1] = int(v)\n", " if 'tcm' in k:\n", " i = int(k[3:])\n", " tcm[i-1] = int(v)\n", " if 'spine' in k:\n", " i = int(k[5:])\n", " if i<23:\n", " spine[i-1] = int(v)\n", " else:\n", " spine[i] = int(v)\n", " for i in range(26,40):\n", " new_valve = 1+psy[i]\n", " psy[i] = new_valve \n", " code = phone[phone_num]\n", " if code in dict3.keys() and code in dict1.keys(): \n", " dict1[code]['tcm'] = tcm \n", " dict1[code]['spine'] = spine\n", " dict1[code]['psy'] = psy\n", " elif code not in dict1.keys(): \n", " dict1.setdefault(code,{})\n", " dict1[code] = dict3[code]\n", " birth = date.fromisoformat(dict3[code]['birth'])\n", " rq = date.fromisoformat('2025-11-17')\n", " days = (rq-birth).days \n", " dict1[code]['age'] = int(days/365)\n", " dict1[code]['month'] = int(days/365*12)\n", " dict1[code]['rq'] = '2025-11-17'\n", " dict1[code]['tcm'] = tcm \n", " dict1[code]['spine'] = spine\n", " dict1[code]['psy'] = psy\n", "filename = 'data/result_北海2025-1.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print(len(dict1))" ] }, { "cell_type": "code", "execution_count": null, "id": "013474d1-e2e0-4562-bd72-80ec9425f0c9", "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 }