{ "cells": [ { "cell_type": "markdown", "id": "9aa09f7b-6a13-471b-91ed-c56d1ccc4d2c", "metadata": { "execution": { "iopub.execute_input": "2022-10-10T02:37:38.847757Z", "iopub.status.busy": "2022-10-10T02:37:38.847228Z", "iopub.status.idle": "2022-10-10T02:37:38.853747Z", "shell.execute_reply": "2022-10-10T02:37:38.852087Z", "shell.execute_reply.started": "2022-10-10T02:37:38.847708Z" }, "tags": [] }, "source": [ "## 人员信息导入" ] }, { "cell_type": "markdown", "id": "53b09d89-0cd6-4d84-b493-d47918664201", "metadata": {}, "source": [ "### 人员基本信息导入" ] }, { "cell_type": "code", "execution_count": null, "id": "ce9b96fd-4bc1-4fd3-8339-5992a86c7001", "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", " \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/交警支队名单221010.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "f684616c-98f2-4f37-81c8-77ab5a7389fa", "metadata": {}, "source": [ "### 小鹅通人员信息导入" ] }, { "cell_type": "code", "execution_count": null, "id": "e610a572-8699-4f35-a3db-de4c0b971686", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import os\n", "import glob\n", "import csv\n", "\n", "fi_path = 'data/小鹅通/'\n", "dict1 = {}\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='',encoding='gb18030') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " header = next(fl1) \n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " list1.append(line)\n", "for item in list1:\n", " dict1.setdefault(item[0],{})\n", " dict1[item[0]]['nick'] = item[1]\n", " dict1[item[0]]['name'] = item[4] \n", " dict1[item[0]]['phone'] = item[5] \n", "filename = 'data/小鹅通人员信息221010.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl,ensure_ascii=False) " ] }, { "cell_type": "markdown", "id": "fa233427-c1ea-4005-a2bd-b2b9e94604d0", "metadata": {}, "source": [ "### 人员手机号码导入" ] }, { "cell_type": "code", "execution_count": null, "id": "2fd5b96c-0bbd-4a8f-8d72-002445101c92", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "wb = openpyxl.load_workbook('data/新部门排序-淄博交警支队人员名单 _56473.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", " phone = sheet.cell(n, 5).value\n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " dict1['birth'] = str(sheet.cell(n,4).value).split(' ')[0]\n", " person[phone] = dict1\n", "filename = 'data/交警支队手机号码221010.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "c61f18ab-7411-44d4-9741-3dd50283f4bb", "metadata": {}, "source": [ "### 关联人员手机号码及测试编号" ] }, { "cell_type": "code", "execution_count": null, "id": "73895efd-0d5e-4872-aca9-a697c3a0e774", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/交警支队名单221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "list2 = []\n", "filename = 'data/交警支队手机号码221010.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "for k, v in dict2.items(): \n", " list1 = [k,v['name'],v['birth'],v['unit']]\n", " list2.append(list1)\n", "for k, v in dict1.items():\n", " name = v['name']\n", " birth = v['birth']\n", " for item in list2:\n", " if name in item and birth in item:\n", " dict1[k]['phone'] = item[0]\n", " dict1[k]['unit'] = item[3]\n", " dict2[item[0]]['code'] = k\n", " break\n", "filename = 'data/交警支队名单221010.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "filename = 'data/交警支队手机号码221010.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict2, fl, ensure_ascii=False)\n", "print('ok') \n", " \n" ] }, { "cell_type": "markdown", "id": "234d9b71-f99e-48cb-af9b-151bbf3f1715", "metadata": {}, "source": [ "### 小鹅通人员分组(按照手机号关联)" ] }, { "cell_type": "code", "execution_count": null, "id": "9aaa35a7-13e2-4ece-a9fd-931ad00e89d3", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "\n", "filename = 'data/交警支队分组情况.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", " phone = line[9]\n", " group = line[1]\n", " \n", " if phone in dict1.keys():\n", " \n", " dict1[phone]['group'] = group\n", "\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl,ensure_ascii=False) " ] }, { "cell_type": "markdown", "id": "e3a23383-e918-41c7-818e-6914ebfe7baf", "metadata": {}, "source": [ "### 小鹅通人员信息关联" ] }, { "cell_type": "code", "execution_count": null, "id": "fc1da208-192e-4b06-b42f-72e7d44245ad", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "filename = 'data/交警支队名单221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "for k, v in dict1.items():\n", " if 'phone' in v.keys():\n", " dict2.setdefault(v['phone'], {})\n", " dict2[v['phone']]['name'] = v['name']\n", " dict2[v['phone']]['sex'] = v['sex']\n", " dict2[v['phone']]['unit'] = v['unit']\n", " dict2[v['phone']]['birth'] = v['birth']\n", "#print(dict2) \n", "list1 = dict2.keys()\n", "filename = 'data/小鹅通人员信息221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for k, v in dict1.items():\n", " phone = v['phone']\n", " if phone in list1:\n", " dict2[phone]['nick'] = v['nick']\n", " dict2[phone]['user'] = v['name']\n", " dict2[phone]['id'] = k\n", "filename = 'data/交警支队小鹅通信息221010.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict2, fl, ensure_ascii=False)\n", "print('ok') " ] }, { "cell_type": "markdown", "id": "8136ea7b-d485-452d-b032-0cfa538166a9", "metadata": {}, "source": [ "### 修正人员信息" ] }, { "cell_type": "code", "execution_count": null, "id": "5678472e-b131-4940-9161-240dcd3461bb", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "\n", "wb = openpyxl.load_workbook('data/新增人员表221018.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,1).value is None:\n", " break\n", " else:\n", " phone = sheet.cell(n, 5).value\n", " if phone in dict2.keys():\n", " dict2[phone]['id'] = sheet.cell(n, 1).value\n", " dict2[phone]['nick'] = sheet.cell(n, 3).value\n", " dict2[phone]['user'] = sheet.cell(n, 2).value\n", " print(sheet.cell(n, 1).value,sheet.cell(n, 3).value,sheet.cell(n, 2).value,phone)\n", "\n", "#with open(filename, 'w') as fl:\n", "# json.dump(dict2, fl, ensure_ascii=False)\n", "#print('ok')" ] }, { "cell_type": "markdown", "id": "dc856c16-3ff0-4c24-a5ee-062129698e08", "metadata": {}, "source": [ "## 打卡信息导入" ] }, { "cell_type": "code", "execution_count": null, "id": "c1a5aaef-70be-4fd2-9384-983aeb59f491", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import os\n", "import glob\n", "import csv\n", "import re\n", "\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "for k, v in dict1.items():\n", " if 'id' in v.keys():\n", " dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']] \n", "dict3 = {} \n", "fi_path = 'data/交警支队/打卡/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'百日筑基-(.+)》',fn)[0]\n", " header = next(fl1)\n", " for line in fl1: \n", " id = line[0]\n", " num = line[10]\n", " #print(id,num)\n", " if id in dict2.keys() and dict2[id][4] == group:\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = dict2[id][0]\n", " dict3[id]['phone'] = dict2[id][2]\n", " dict3[id]['unit'] = dict2[id][1]\n", " dict3[id]['nick'] = dict2[id][3]\n", " dict3[id]['dk'] = num\n", "\n", "fi_path = 'data/交警支队/时长/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='',encoding='gb18030') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'《(.+)》',fn)[0]\n", " #header = next(fl1)\n", " i = 0\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " if i> 1:\n", " list1.append(line)\n", " id = line[0]\n", " if id in dict2.keys() and dict2[id][4] == group:\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = dict2[id][0]\n", " dict3[id]['phone'] = dict2[id][2]\n", " dict3[id]['unit'] = dict2[id][1]\n", " dict3[id]['nick'] = dict2[id][3]\n", " dict3[id]['sc'] = line[6] \n", " i +=1\n", "\n", "list1 = []\n", "for k, v in dict3.items():\n", " list2 = []\n", " if 'dk' in v.keys():\n", " dk = v['dk']\n", " else:\n", " dk = 0\n", " if 'sc' in v.keys():\n", " sc = v['sc']\n", " else:\n", " sc = ''\n", " list2 = [k,v['name'],v['phone'],v['unit'],dk,sc]\n", " list1.append(list2)\n", "title = ['昵称','姓名','手机号','部门','打卡次数','累计学习时长']\n", "filename = 'data/交警支队学习情况表221212.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": "e83be6f5-c05a-4ac0-8511-2dabf770466c", "metadata": { "execution": { "iopub.execute_input": "2022-10-18T06:28:39.091613Z", "iopub.status.busy": "2022-10-18T06:28:39.091059Z", "iopub.status.idle": "2022-10-18T06:28:39.098295Z", "shell.execute_reply": "2022-10-18T06:28:39.096326Z", "shell.execute_reply.started": "2022-10-18T06:28:39.091564Z" } }, "source": [ "### 核对新增人员" ] }, { "cell_type": "code", "execution_count": null, "id": "a4886e66-99d1-4f24-9d53-29a239e62bad", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import os\n", "import glob\n", "import csv\n", "import re\n", "\n", "filename = 'data/交警支队小鹅通信息221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "dict2 = {}\n", "for k, v in dict1.items():\n", " if 'id' in v.keys():\n", " dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']] \n", " \n", "dict3 = {} \n", "fi_path = 'data/交警支队/打卡/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'百日筑基-(.+)》',fn)[0]\n", " header = next(fl1)\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " id = line[0]\n", " num = line[10]\n", " #print(id,num)\n", " if id not in dict2.keys():\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = line[4]\n", " dict3[id]['phone'] = line[5]\n", " dict3[id]['nick'] = line[1]\n", " \n", "fi_path = 'data/交警支队/时长/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='',encoding='gb18030') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'《(.+)》',fn)[0]\n", " #header = next(fl1)\n", " i = 0\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " if i> 1:\n", " \n", " id = line[0]\n", " if id not in dict2.keys():\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = line[10]\n", " dict3[id]['phone'] = line[11]\n", " dict3[id]['nick'] = line[1] \n", " i +=1\n", "#print(dict3)\n", "for k, v in dict3.items():\n", " phone = re.sub('[\\r\\n\\f\\t ]{1,}', '',v['phone'])\n", " if phone in dict1.keys():\n", " dict1[phone]['id'] = k\n", " dict1[phone]['nick'] = v['nick'] \n", " dict1[phone]['user'] = v['name']\n", " else:\n", " list1.append([k,v['name'],v['nick'],phone])\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "\n", "title = ['id','姓名','昵称','手机号']\n", "filename = 'data/新增人员表221018.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": "ee4bb827-287f-4b1f-8dbd-d595cb010892", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import os\n", "import glob\n", "import csv\n", "import re\n", "\n", "filename = 'data/交警支队小鹅通信息221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "for k, v in dict1.items():\n", " if 'id' in v.keys():\n", " dict2[v['id']] = [v['name'],v['unit'],k,v['nick'],v['group']] \n", "dict3 = {} \n", "fi_path = 'data/交警支队/打卡/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'百日筑基-(.+)》',fn)[0]\n", " header = next(fl1)\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " id = line[0]\n", " num = line[10]\n", " #print(id,num)\n", " if id not in dict2.keys():\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = line[4]\n", " dict3[id]['phone'] = line[5]\n", " dict3[id]['nick'] = line[1]\n", " \n", "fi_path = 'data/交警支队/时长/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "\n", "list1 = []\n", "for fn in fl:\n", " with open(fn,'r',newline='',encoding='gb18030') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " group = re.findall(r'《(.+)》',fn)[0]\n", " #header = next(fl1)\n", " i = 0\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " if i> 1:\n", " \n", " id = line[0]\n", " if id not in dict2.keys():\n", " dict3.setdefault(id,{})\n", " dict3[id]['name'] = line[10]\n", " dict3[id]['phone'] = line[11]\n", " dict3[id]['nick'] = line[1] \n", " i +=1\n", "i = 1\n", "#print(dict3)\n", "for k, v in dict3.items():\n", " phone = re.sub('[\\r\\n\\f\\t ]{1,}', '',v['phone'])\n", " if phone not in dict1.keys():\n", " #dict1[phone]['id'] = k\n", " #dict1[phone]['nick'] = v['nick'] \n", " #dict1[phone]['user'] = v['name']\n", " print(i,k,v['nick'], v['name'],phone)\n", " i+=1\n" ] }, { "cell_type": "markdown", "id": "775a298e-600d-4644-bd43-1eb75a302a9f", "metadata": {}, "source": [ "### 导出无手机号码人员" ] }, { "cell_type": "code", "execution_count": null, "id": "aa15ff39-1527-4f08-9331-d64bd298c1c2", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "filename = 'data/交警支队名单221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "for k, v in dict1.items():\n", " if 'phone' not in v.keys():\n", " print(v['name'],v['unit'])" ] }, { "cell_type": "markdown", "id": "ef1041a9-2865-4a57-8b4d-1af26f059e22", "metadata": {}, "source": [ "### 人员部门调整" ] }, { "cell_type": "code", "execution_count": null, "id": "7b31ffb5-f5fd-4dbc-b30c-0b583f4c7294", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "wb = openpyxl.load_workbook('data/新部门排序-淄博交警支队人员名单 _56473.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "dict2 = {}\n", "\n", "data1 =list(sheet.values)\n", "del data1[0]\n", "for item in data1:\n", " phone = item[4]\n", " dict2[phone] = [item[1],item[0]]\n", "#print(dict2)\n", "dict3 = {}\n", "filename = 'data/交警支队小鹅通信息.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for k, v in dict1.items():\n", " if k not in dict2.keys():\n", " print(k,dict1[k]['name'])\n", "#with open(filename, 'w') as fl:\n", "# json.dump(person, fl, ensure_ascii=False)\n", "#print('ok')" ] }, { "cell_type": "markdown", "id": "287a2b9a-fc63-44f6-84f7-6228d5e14266", "metadata": {}, "source": [ "## 核对分组人员情况" ] }, { "cell_type": "code", "execution_count": null, "id": "8cf3f2b7-cf8e-47b2-9a8b-7ec5016aeef3", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "\n", "filename = 'data/交警支队手机号码221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", " \n", "filename = 'data/交警支队分组情况.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", " phone = line[9]\n", " group = line[1]\n", " if phone not in dict1.keys():\n", " print(line[2],line[9],line[3])\n" ] }, { "cell_type": "markdown", "id": "74e41826-7247-4a5a-99c7-db067dfd6d93", "metadata": {}, "source": [ "## 核对小鹅通人员" ] }, { "cell_type": "code", "execution_count": null, "id": "765cb3e6-d8ab-4aea-9fb3-9008001b9767", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import csv\n", "\n", "filename = 'data/交警支队手机号码221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/小鹅通人员信息221010.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", " \n", "for k, v in dict2.items():\n", " phone = v['phone']\n", " if phone not in dict1.keys():\n", " print(k,v['nick'],v['name'],phone)\n", " \n" ] }, { "cell_type": "markdown", "id": "de4fabec-7ce5-43c8-9019-0a41bf7528d3", "metadata": {}, "source": [ "### 核对存在多组人员" ] }, { "cell_type": "code", "execution_count": null, "id": "65ef74b4-4667-422c-b610-63b517edd75d", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import os\n", "import glob\n", "import csv\n", "import re\n", "\n", "fi_path = 'data/交警支队/打卡/'\n", "fl = glob.glob(f'{fi_path}*.csv')\n", "\n", "list1 = []\n", "dict1 = {}\n", "for fn in fl:\n", " with open(fn,'r',newline='') as csv_file:\n", " fl1 = csv.reader(csv_file,delimiter=',')\n", " zb = fn.split('-')[3]\n", " #header = next(fl1)\n", " i = 0\n", " for line in fl1:\n", " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " if i> 1:\n", " m_id = line[0]\n", " dict1.setdefault(m_id,[])\n", " dict1[m_id].append(zb)\n", " #list1.append(line)\n", " i +=1\n", "filename = 'data/交警支队小鹅通信息221018.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "dict3 = {}\n", "for k ,v in dict2.items():\n", " if 'id' in v.keys():\n", " dict3[v['id']] = [k,v['name'],v['unit'],v['nick']]\n", "\n", "for k, v in dict1.items():\n", " if k in dict3.keys():\n", " if len(v)>1:\n", " print(dict3[k][1],dict3[k][2],dict3[k][0],v)\n", " \n", " " ] }, { "cell_type": "markdown", "id": "60752c6c-2a55-40ee-997b-bcc286fba054", "metadata": {}, "source": [ "### 修改json内容" ] }, { "cell_type": "code", "execution_count": null, "id": "bcf970ab-b1d6-4da5-80ae-36a8a4bb56be", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "\n", "filename = 'data/交警支队名单221010.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "i = 0\n", "for k, v in dict1.items():\n", " if v['unit'] == '支高新区大队':\n", " dict1[k]['unit'] = '高新区大队'\n", " i +=1\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl,ensure_ascii=False) \n", " \n", "print(f'共有{i}条记录被修改')" ] }, { "cell_type": "markdown", "id": "76c5412f-f2ef-446a-903d-6b033b5bfd8a", "metadata": {}, "source": [ "## 统计测评人员" ] }, { "cell_type": "code", "execution_count": null, "id": "38ae9a3f-b284-4407-ab6a-8e992dfd9759", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import csv\n", "wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "cjry = set()\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:\n", " break\n", " else: \n", " phone = sheet.cell(n, 5).value \n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "list1 = []\n", "filename = 'data/Survey_20230424-tcm5.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", " \n", " if k not in cjry:\n", " list2.append([k,person[k]['name'],person[k]['unit']])\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": "113e45e5-403f-4d5d-9b96-adb7f05780f9", "metadata": {}, "source": [ "### 统计未明确人员" ] }, { "cell_type": "code", "execution_count": null, "id": "d54bd635-c0d8-4527-811f-6d28f9cf68ae", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import csv\n", "wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "cjry = set()\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:gangx\n", " break\n", " else: \n", " phone = sheet.cell(n, 5).value \n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "list1 = []\n", "filename = 'data/Survey_20230424-jj.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", "\n", "list2 = []\n", "for item in cjry: \n", " if str(item) not in person.keys():\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)\n" ] }, { "cell_type": "markdown", "id": "c0f7a72a-3930-4c05-bf96-e65f0f83a634", "metadata": {}, "source": [ "### 统计生成报告人员情况表" ] }, { "cell_type": "code", "execution_count": null, "id": "a9a871ae-ab54-4f49-ada4-438b6a3e10be", "metadata": { "tags": [] }, "outputs": [], "source": [ "import openpyxl\n", "import json\n", "import glob,os,shutil\n", "from pathlib2 import Path\n", "import csv\n", "\n", "wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "depart = []\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:\n", " break\n", " else: \n", " phone = sheet.cell(n, 5).value \n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "list1 = []\n", "dict1 = {}\n", "old = []\n", "fi_path = 'file/132/20230425'\n", "fl=glob.glob(f'{fi_path}/*.pdf')\n", "print(len(fl))\n", "for fn in fl:\n", " phone = Path(fn).stem\n", " if phone in person.keys():\n", " name = person[phone]['name']\n", " unit = person[phone]['unit']\n", " else:\n", " name = ''\n", " unit ='未明确部门'\n", " if unit not in depart:\n", " depart.append(unit)\n", " dict1[phone] = {'name':name,'unit':unit}\n", "print(depart)\n", "m_path = 'file/132/new'\n", "for pn in depart:\n", " if not os.path.exists(m_path + '/' + pn):\n", " os.mkdir(m_path + '/' + pn)\n", "\n", "fl=os.listdir(fi_path)\n", "for fn in fl:\n", " if os.path.isfile(fi_path + '/' + fn):\n", " ofn = int(fn.split('.')[0])\n", " old.append(ofn) \n", "old.sort()\n", "for n in old: \n", " o_name = f'{fi_path}/{n}.pdf'\n", " unit = dict1[str(n)]['unit']\n", " \n", " n_name = f'{m_path}/{unit}/{str(n)}.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": 44, "id": "790407ea-3461-4533-8775-390ea3465da9", "metadata": { "execution": { "iopub.execute_input": "2023-04-25T12:17:16.457023Z", "iopub.status.busy": "2023-04-25T12:17:16.456189Z", "iopub.status.idle": "2023-04-25T12:17:16.698120Z", "shell.execute_reply": "2023-04-25T12:17:16.697394Z", "shell.execute_reply.started": "2023-04-25T12:17:16.456992Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "452\n", "['博山大队', '桓台大队', '未明确部门', '支队', '淄川大队', '文昌湖大队', '支队车管所', '高青大队', '张店大队', '设施大队', '周村大队', '高新区大队', '支队外调人员', '沂源大队', '退休人员', '临淄大队']\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "import glob,os,shutil\n", "from pathlib2 import Path\n", "import csv\n", "\n", "wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "depart = []\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:\n", " break\n", " else: \n", " phone = sheet.cell(n, 5).value \n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "list1 = []\n", "dict1 = {}\n", "old = []\n", "fi_path = 'file/132/20230425'\n", "fl=glob.glob(f'{fi_path}/*.pdf')\n", "print(len(fl))\n", "for fn in fl:\n", " phone = Path(fn).stem\n", " if phone in person.keys():\n", " name = person[phone]['name']\n", " unit = person[phone]['unit']\n", " else:\n", " name = ''\n", " unit ='未明确部门'\n", " if unit not in depart:\n", " depart.append(unit)\n", " dict1[phone] = {'name':name,'unit':unit}\n", "print(depart)\n", "m_path = 'file/132/new'\n", "for pn in depart:\n", " if not os.path.exists(m_path + '/' + pn):\n", " os.mkdir(m_path + '/' + pn)\n", "\n", "fl=os.listdir(fi_path)\n", "for fn in fl:\n", " if os.path.isfile(fi_path + '/' + fn):\n", " ofn = int(fn.split('.')[0])\n", " old.append(ofn) \n", "old.sort()\n", "for n in old: \n", " o_name = f'{fi_path}/{n}.pdf'\n", " unit = dict1[str(n)]['unit'] \n", " n_name = f'{m_path}/{unit}/{str(n)}.pdf'\n", " list1.append([unit,n])\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": "markdown", "id": "b0f8f072-c8d2-4259-8785-4f2a37a06b66", "metadata": {}, "source": [ "### 生成参加评测人员信息" ] }, { "cell_type": "code", "execution_count": 51, "id": "ec6779c9-4cf2-4fb9-b6ce-430eeca07046", "metadata": { "execution": { "iopub.execute_input": "2023-05-05T00:42:59.292182Z", "iopub.status.busy": "2023-05-05T00:42:59.291341Z", "iopub.status.idle": "2023-05-05T00:42:59.515203Z", "shell.execute_reply": "2023-05-05T00:42:59.514466Z", "shell.execute_reply.started": "2023-05-05T00:42:59.292142Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "452\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "import glob,os,shutil\n", "from pathlib2 import Path\n", "import csv\n", "\n", "wb = openpyxl.load_workbook('data/淄博交警支队人员名单(排序花名册).xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "depart = []\n", "for n in range(2, sheet.max_row+1):\n", " if sheet.cell(n,2).value is None:\n", " break\n", " else: \n", " phone = sheet.cell(n, 5).value \n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value \n", " xb = str(sheet.cell(n, 3).value)\n", " if xb == '1':\n", " sex = '男'\n", " elif xb =='2':\n", " sex = '女'\n", " dict1['sex'] = sex\n", " dict1['unit'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "list1 = []\n", "dict1 = {}\n", "old = []\n", "fi_path = 'file/132/20230425'\n", "fl=glob.glob(f'{fi_path}/*.pdf')\n", "print(len(fl))\n", "for fn in fl:\n", " phone = Path(fn).stem\n", " if phone in person.keys():\n", " name = person[phone]['name']\n", " unit = person[phone]['unit']\n", " sex = person[phone]['sex']\n", " else:\n", " name = ''\n", " unit ='未明确部门'\n", " sex = ''\n", " if unit not in depart:\n", " depart.append(unit)\n", " dict1[phone] = {'name':name,'unit':unit,'sex':sex}\n", "filename = 'data/淄博交警参加测评人员.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl,ensure_ascii=False) " ] }, { "cell_type": "markdown", "id": "f9686f85-2d33-4e4d-8d4d-498237c26d2c", "metadata": {}, "source": [ "### 生成心理测评人员明细" ] }, { "cell_type": "code", "execution_count": 52, "id": "b915259c-755b-4d8a-98f0-ef8707624b38", "metadata": { "execution": { "iopub.execute_input": "2023-05-05T00:43:56.396524Z", "iopub.status.busy": "2023-05-05T00:43:56.395990Z", "iopub.status.idle": "2023-05-05T00:43:56.874426Z", "shell.execute_reply": "2023-05-05T00:43:56.873679Z", "shell.execute_reply.started": "2023-05-05T00:43:56.396492Z" }, "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-psy3.csv'\n", "list2 = []\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", " phone = str(line[2])\n", " result = json.loads(line[5]) \n", " \n", " if phone in dict1.keys():\n", " list1 = []\n", " \n", " list1.append(phone)\n", " list1.append(dict1[phone]['name'])\n", " list1.append(dict1[phone]['sex'])\n", " list1.append(dict1[phone]['unit'])\n", " #print(k,v['phone'],type(result))\n", " for k1, v1 in result.items():\n", " list1.append(v1)\n", " list2.append(list1)\n", "filename = 'data/交警心理评估明细表.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": "b19438f4-1fbe-480f-9809-3db7af008812", "metadata": {}, "source": [ "### 生成中医测评人员明细" ] }, { "cell_type": "code", "execution_count": 53, "id": "596b26a5-42cc-400f-8c6f-39bfa0fb9233", "metadata": { "execution": { "iopub.execute_input": "2023-05-05T00:46:28.321827Z", "iopub.status.busy": "2023-05-05T00:46:28.321422Z", "iopub.status.idle": "2023-05-05T00:46:28.612694Z", "shell.execute_reply": "2023-05-05T00:46:28.612003Z", "shell.execute_reply.started": "2023-05-05T00:46:28.321799Z" }, "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-tcm5.csv'\n", "list2 = []\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", " phone = str(line[2])\n", " result = json.loads(line[5]) \n", " \n", " if phone in dict1.keys():\n", " list1 = []\n", " \n", " list1.append(phone)\n", " list1.append(dict1[phone]['name'])\n", " list1.append(dict1[phone]['sex'])\n", " list1.append(dict1[phone]['unit'])\n", " #print(k,v['phone'],type(result))\n", " for k1, v1 in result.items():\n", " list1.append(v1)\n", " list2.append(list1)\n", "filename = 'data/交警中医评估明细表.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": "code", "execution_count": null, "id": "eac36b4d-943b-4d1f-9d64-f1c63daf7b40", "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 }