{ "cells": [ { "cell_type": "markdown", "id": "4b3853d4-d30f-4b1d-99de-fa52777ce65c", "metadata": {}, "source": [ "## 体质指标问卷导入" ] }, { "cell_type": "code", "execution_count": null, "id": "202a0266-f578-4d75-b04c-5ae9957391bf", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/淄博交警体质指标问卷.json'\n", "item = {}\n", "unit = {}\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "for items in dict1['pages']:\n", " for item in items['elements']:\n", " #print(item)\n", " dict2.setdefault(item['name'],{})\n", " name = item['name']\n", " dict2[name]['type'] = item['type']\n", " dict2[name]['title'] = item['title']['zh-cn']\n", " if 'isRequired' in item.keys():\n", " dict2[name]['isRequired'] = item['isRequired']\n", " else:\n", " dict2[name]['isRequired'] = False\n", " if item['type'] == 'text':\n", " dict2[name]['inputType'] = item['inputType']\n", " else:\n", " dict2[name]['choices'] = item['choices']\n", "filename = 'data/淄博交警体质问卷参数.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict2, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "5eed4886-a332-429f-9283-e109d48227fe", "metadata": {}, "source": [ "## 体质指标问卷整理" ] }, { "cell_type": "code", "execution_count": null, "id": "857ca433-556a-4152-af7e-5f81434d11a7", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/淄博交警体质问卷参数.json'\n", "item = {}\n", "unit = {}\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "for k, v in dict1.items():\n", " if 'choices' in v.keys():\n", " dict2 = {}\n", " for item in v['choices']:\n", " dict2[str(item['value'])] = item['text']\n", " dict1[k]['choices'] = dict2\n", "filename = 'data/淄博交警体质问卷参数.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "d7ab7cfd-3448-45a6-abb4-04e7f317b843", "metadata": {}, "source": [ "## 问卷数据分析" ] }, { "cell_type": "code", "execution_count": null, "id": "f5c6a39a-3e3e-4844-8ff8-b9ebb7e8f8af", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "filename = 'data/淄博交警体质问卷参数.json'\n", "item = {}\n", "unit = {}\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/Survey_20230522.json'\n", "\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for items in dict2['Survey']:\n", " #print(items)\n", " phone = items['phone']\n", " print(phone)\n", " data = json.loads(items['data'])\n", " for k, v in data.items():\n", " title = dict1[k]['title']\n", " if dict1[k]['type'] == 'radiogroup':\n", " value = dict1[k]['choices'][str(v)] \n", " if dict1[k]['type'] == 'text':\n", " value = v\n", " if dict1[k]['type'] == 'checkbox':\n", " value = []\n", " for choice in v:\n", " value.append(dict1[k]['choices'][str(choice)]) \n", " print(title,value) " ] }, { "cell_type": "markdown", "id": "366adf62-e2b1-4e14-8164-9511aec571aa", "metadata": {}, "source": [ "## 生成淄博警察人员信息汇总表" ] }, { "cell_type": "code", "execution_count": 56, "id": "0a92a167-0d8d-4c49-a696-fd4dbd04eb64", "metadata": { "execution": { "iopub.execute_input": "2023-05-30T06:48:26.236906Z", "iopub.status.busy": "2023-05-30T06:48:26.236417Z", "iopub.status.idle": "2023-05-30T06:48:26.553550Z", "shell.execute_reply": "2023-05-30T06:48:26.552825Z", "shell.execute_reply.started": "2023-05-30T06:48:26.236874Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13853361818 已经存在!\n", "05332138406 已经存在!\n", "18705333980 已经存在!\n", "13070645243 已经存在!\n", "18705336013 已经存在!\n", "ok\n", "17805337253 已经存在!\n", "13305335697 已经存在!\n", "18705333572 已经存在!\n", "17805337157 已经存在!\n", "17805337611 已经存在!\n", "13964355603 已经存在!\n", "17805337215 已经存在!\n", "17805337257 已经存在!\n", "17615773020 已经存在!\n", "15505337203 已经存在!\n", "13869397003 已经存在!\n", "18053386976 已经存在!\n", "18053386979 已经存在!\n", "15253357267 已经存在!\n", "15206676826 已经存在!\n", "15265333315 已经存在!\n", "13011637601 已经存在!\n", "17805337235 已经存在!\n", "13153362550 已经存在!\n", "17685603319 已经存在!\n", "ok\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", "\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 = str(sheet.cell(n, 5).value)\n", " if phone in person.keys():\n", " print(phone,'已经存在!')\n", " else:\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['单位'] = \"交警支队\"\n", " dict1['部门'] = sheet.cell(n, 1).value\n", " person[phone] = dict1\n", "print('ok')\n", "filename = 'data/高新区.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "for k,v in dict2.items():\n", " if 'phone' in v.keys():\n", " phone = str(v['phone'])\n", " if phone in person.keys():\n", " print(phone,'已经存在!')\n", " else:\n", " person.setdefault(phone, {})\n", " dict1 = {}\n", " dict1['name'] = v['name'] \n", " dict1['sex'] = v['sex']\n", " dict1['单位'] = \"高新区\"\n", " if 'unit' in v.keys():\n", " dict1['部门'] = v['unit']\n", " person[phone] = 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": "c76b5512-699c-4051-88c5-e3f725fa9a0b", "metadata": {}, "source": [ "## 核对参加问卷人员" ] }, { "cell_type": "code", "execution_count": 62, "id": "9e0f66ea-09d6-41ec-8284-9a5e712c6cee", "metadata": { "execution": { "iopub.execute_input": "2023-05-30T06:55:04.917464Z", "iopub.status.busy": "2023-05-30T06:55:04.916603Z", "iopub.status.idle": "2023-05-30T06:55:04.935262Z", "shell.execute_reply": "2023-05-30T06:55:04.934185Z", "shell.execute_reply.started": "2023-05-30T06:55:04.917424Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 13718887655 未有记录\n", "2 15210715398 未有记录\n", "3 18600297579 未有记录\n", "4 付峰 交警支队\n", "5 孙长宁 交警支队\n", "6 张学军 交警支队\n", "7 李平 交警支队\n", "8 谢珺扬 交警支队\n", "9 高维成 交警支队\n", "10 张海天 交警支队\n", "11 董景发 交警支队\n", "12 陈庆永 交警支队\n", "13 魏玉兵 交警支队\n", "14 崔瑞房 交警支队\n", "15 韩俊达 交警支队\n", "16 宋道军 交警支队\n", "17 王若镔 交警支队\n", "18 邵珠峰 交警支队\n", "19 贾备 交警支队\n", "20 于会萍 交警支队\n", "21 王静 交警支队\n", "22 15054176063 未有记录\n", "23 高建红 交警支队\n", "24 巩本波 交警支队\n", "25 邵杰 交警支队\n", "26 宋业金 交警支队\n", "27 安兵 交警支队\n", "28 岳科学 交警支队\n", "29 戴维靖 交警支队\n", "30 闫仲荣 交警支队\n", "31 陈振国 交警支队\n", "32 王拥军 交警支队\n", "33 胡永吉 交警支队\n", "34 赵军 交警支队\n", "35 任振华 交警支队\n", "36 魏鹂娴 交警支队\n", "37 李春红 交警支队\n", "38 赵书辰 交警支队\n", "39 耿玥 交警支队\n", "40 甘军 交警支队\n", "41 姚秀波 交警支队\n", "42 张言辉 交警支队\n", "43 张明 交警支队\n", "44 韦璟 交警支队\n", "45 王学征 交警支队\n", "46 孙庆章 交警支队\n", "47 张天姿 交警支队\n", "48 张明易 交警支队\n", "49 王凌云 交警支队\n", "50 魏亮 交警支队\n" ] } ], "source": [ "import json\n", "import csv\n", "\n", "filename = 'data/淄博警察汇总.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "list1 = []\n", "filename = 'data/Survey_20230530.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", "i = 0\n", "for item in list1:\n", " i+=1\n", " phone = item[2]\n", " if phone in dict1.keys():\n", " print(i,dict1[phone]['name'],dict1[phone]['单位'])\n", " else:\n", " print(i,phone,'未有记录')" ] }, { "cell_type": "code", "execution_count": null, "id": "4203377b-579d-4267-a4a7-e27d2ef4a87c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }