Files
jupyter/体测单位/淄博高新区.ipynb
T
2023-04-26 10:09:26 +00:00

461 lines
13 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "9caef37c-26bd-4590-abe6-4c0255c2886f",
"metadata": {},
"source": [
"## 人员基本信息导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ab7bf77-5451-4773-9b13-10e04a48ddfb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/高新区名单.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = int(sheet.cell(n, 1).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value \n",
" sex = str(sheet.cell(n, 3).value)\n",
" dict1['sex'] = sex\n",
" dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]\n",
" if sheet.cell(n,5).value is not None:\n",
" dict1['phone'] = sheet.cell(n,5).value\n",
" person[code] = dict1\n",
"filename = 'data/高新区.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "176b8fca-a7aa-4949-88df-b99158bfd46b",
"metadata": {},
"source": [
"## 补充人员信息(部门)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4baf116-9e8b-4820-98a7-9a468f4abb7f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import csv\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"wb = openpyxl.load_workbook('data/高新区.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = int(sheet.cell(n, 4).value)\n",
" if str(code) in dict1.keys():\n",
" dict1[str(code)]['unit'] = sheet.cell(n, 3).value\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "502638d8-79d0-4392-953e-047c8428c9a5",
"metadata": {},
"source": [
"## 统计测评人员"
]
},
{
"cell_type": "markdown",
"id": "a430da5f-1e5c-447f-96a1-344d03e57b31",
"metadata": {},
"source": [
"### 统计心理测评人员"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7609f3c3-5c52-4b92-a2d5-359bf4a45a10",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import csv\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"cjry = set()\n",
"filename = 'data/Survey_20230424-psy.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",
" cjry.add(line[2])\n",
"print(len(cjry))\n",
"list2 = []\n",
"for k, v in person.items(): \n",
" #if 'phone' in v.keys() and v['phone'] in cjry:\n",
" if 'phone' in v.keys() and v['phone'] not in cjry:\n",
" list2.append([k,dict1[str(k)]['name'],dict1[str(k)]['phone']])\n",
" \n",
"filename = 'data/高新未参加心理评估人员(20230424).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": "519d9b3a-d0d8-44aa-a17d-65e7f21f088b",
"metadata": {},
"source": [
"### 统计中医测评人员"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd2391c1-8d73-4714-8c20-42161b3eb493",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import csv\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"cjry = set()\n",
"filename = 'data/Survey_20230424-tcm1.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",
" cjry.add(line[2])\n",
"print(len(cjry))\n",
"list2 = []\n",
"for k, v in person.items(): \n",
" #if 'phone' in v.keys() and v['phone'] in cjry:\n",
" if 'phone' in v.keys() and v['phone'] not in cjry:\n",
" list2.append([k,dict1[str(k)]['name'],dict1[str(k)]['phone']])\n",
" \n",
"filename = 'data/高新未参加中医评估人员(20230424).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": "0b717a78-52db-4894-83c6-731a4935a02d",
"metadata": {},
"source": [
"### 统计信息缺少人员信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd5af221-9369-4eab-884c-06885c940d88",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import csv\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"cjry = set()\n",
"filename = 'data/Survey_20230424-gx.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",
" cjry.add(line[2])\n",
"print(len(cjry))\n",
"phones = set()\n",
"for k, v in person.items(): \n",
" #if 'phone' in v.keys() and v['phone'] in cjry:\n",
" if 'phone' in v.keys():\n",
" phones.add(v['phone'])\n",
"list2 = []\n",
"for item in cjry: \n",
" if item not in phones:\n",
" list2.append(['','',item])\n",
"filename = 'data/高新缺失信息人员(20230424).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": "9e9dc89c-5ca1-4c2d-997a-6330df544ea0",
"metadata": {},
"source": [
"### 统计生成报告人员情况表"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4c1b32b8-5cbd-430b-81fd-957e3def5155",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import glob\n",
"from pathlib2 import Path\n",
"import openpyxl\n",
"\n",
"\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"list1 = []\n",
"fi_path = 'file/130/20230424'\n",
"fl=glob.glob(f'{fi_path}/*.pdf')\n",
"print(len(fl))\n",
"for fn in fl:\n",
" name = Path(fn).stem\n",
" if name in dict1.keys():\n",
" list1.append([name,dict1[name]['name']])\n",
"filename = 'data/高新报告明细表(20230424).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": "2731b99f-8138-4e9e-baf0-c9c0c375f0eb",
"metadata": {},
"source": [
"### 报告分组重命名"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9f5a1d4-4c01-4656-85f3-bdbf2776b69d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import openpyxl\n",
"\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"list1 = []\n",
"list_bh = []\n",
"depart = []\n",
"dict2 = {}\n",
"for k, v in dict1.items():\n",
" dict2.setdefault(k,{}) \n",
" \n",
" if 'unit' in v.keys():\n",
" m_depart = v['unit']\n",
" else:\n",
" m_depart = '未明确部门'\n",
" dict2[k]['unit'] = m_depart\n",
" if m_depart not in depart:\n",
" depart.append(m_depart)\n",
" dict2[k]['name'] = v['name']\n",
" \n",
"old = []\n",
"\n",
" \n",
"fi_path = 'file/130/20230424'\n",
"\n",
"\n",
"# 创建部门办公室 \n",
"m_path = 'file/130/new'\n",
"for pn in depart:\n",
" if not os.path.exists(m_path + '/' + pn):\n",
" os.mkdir(m_path + '/' + pn)\n",
"fl=os.listdir(fi_path)\n",
"for fn in fl:\n",
" if os.path.isfile(fi_path + '/' + fn):\n",
" ofn = int(fn.split('.')[0])\n",
" old.append(ofn) \n",
"old.sort()\n",
"for n in old: \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" unit = dict2[str(n)]['unit']\n",
" name = dict2[str(n)]['name']\n",
" n_name = f'{m_path}/{unit}/{str(n).rjust(5,\"0\")}-{name}.pdf'\n",
" #print(o_name,n_name)\n",
" if not os.path.exists(n_name):\n",
" shutil.copyfile(o_name,n_name)\n",
" print(n_name)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "3d0268bb-8bce-4887-a745-077a62069675",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-25T07:52:40.990776Z",
"iopub.status.busy": "2023-04-25T07:52:40.989921Z",
"iopub.status.idle": "2023-04-25T07:52:41.056793Z",
"shell.execute_reply": "2023-04-25T07:52:41.055627Z",
"shell.execute_reply.started": "2023-04-25T07:52:40.990734Z"
},
"tags": []
},
"outputs": [],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import openpyxl\n",
"\n",
"filename = 'data/高新区.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"list1 = []\n",
"list_bh = []\n",
"depart = []\n",
"dict2 = {}\n",
"for k, v in dict1.items():\n",
" dict2.setdefault(k,{}) \n",
" \n",
" if 'unit' in v.keys():\n",
" m_depart = v['unit']\n",
" else:\n",
" m_depart = '未明确部门'\n",
" dict2[k]['unit'] = m_depart\n",
" if m_depart not in depart:\n",
" depart.append(m_depart)\n",
" dict2[k]['name'] = v['name']\n",
" \n",
"old = []\n",
"\n",
" \n",
"fi_path = 'file/130/20230424'\n",
"\n",
"\n",
"# 创建部门办公室 \n",
"m_path = 'file/130/new'\n",
"for pn in depart:\n",
" if not os.path.exists(m_path + '/' + pn):\n",
" os.mkdir(m_path + '/' + pn)\n",
"fl=os.listdir(fi_path)\n",
"for fn in fl:\n",
" if os.path.isfile(fi_path + '/' + fn):\n",
" ofn = int(fn.split('.')[0])\n",
" old.append(ofn) \n",
"old.sort()\n",
"\n",
"for n in old: \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" unit = dict2[str(n)]['unit']\n",
" name = dict2[str(n)]['name']\n",
" code = str(n).rjust(5,\"0\")\n",
" list1.append([unit,code,name])\n",
"filename = 'data/高新报告打印明细表.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": "code",
"execution_count": null,
"id": "f5910a5a-05a5-404f-b3e9-eca86226e244",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}