1340 lines
46 KiB
Plaintext
1340 lines
46 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "f501bde1-90cb-40c4-9dd4-533c27f81be5",
|
||
"metadata": {
|
||
"tags": [],
|
||
"toc-hr-collapsed": true
|
||
},
|
||
"source": [
|
||
"# 调查报告线下数据管理"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "ced4bf30-e7ea-4c4c-ae46-8720ffc07a76",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 羊庙人员信息导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "9b2b755e-049e-48c5-87d3-dd37dceb59fe",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/羊庙测试人员信息.json'\n",
|
||
"\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"dict2 = {}\n",
|
||
"for k,v in dict1.items():\n",
|
||
" for item in v:\n",
|
||
" bh = item['avatar_id']\n",
|
||
" del item['avatar_id']\n",
|
||
" dict2[bh] = item\n",
|
||
"filename = 'data/羊庙人员名单.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(dict2, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "00e9f538-c0f5-46a0-b768-51480ad3fbaf",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 获取参加体测人员编号"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "d89e0e5e-0782-40a3-bba3-862cc9865d4e",
|
||
"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",
|
||
"#print(\"\\n运动项目信息:\")\n",
|
||
"filename = 'data/140.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",
|
||
"list2 = []\n",
|
||
"for result in list1:\n",
|
||
" user = int(result[2])\n",
|
||
" if user not in list2:\n",
|
||
" list2.append(user)\n",
|
||
"list2.sort()\n",
|
||
"print(len(list2))\n",
|
||
"print(list2)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "2c48f588-135a-4d1a-b01e-96222b70b987",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 根据风险筛选统计卡获取信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e76837e8-cdf4-41e0-9d51-6ae5223de813",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"import time\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙运动风险筛查统计表.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"person = {}\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",
|
||
" if sheet.cell(n, 8).value is not None:\n",
|
||
" name = sheet.cell(n, 8).value\n",
|
||
" else:\n",
|
||
" name ='不详'\n",
|
||
" dict1['name'] = name\n",
|
||
" if sheet.cell(n, 9).value is not None:\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 9).value).split(' ')[0]\n",
|
||
" if sheet.cell(n, 10).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n, 10).value)\n",
|
||
" if sheet.cell(n,11).value is not None:\n",
|
||
" dict1['id_num'] = sheet.cell(n,11).value\n",
|
||
" person[code] = dict1\n",
|
||
"print(len(person))\n",
|
||
"filename = 'data/杨庙运动风险筛查统计表信息.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "6cc6b614-85e2-43fd-bc97-301fc776fe29",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 根据恢复版获取信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "1293cdaa-1fdf-43a5-99ce-a031a76f6688",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"import time\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/羊庙恢复版.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"person = {}\n",
|
||
"for n in range(2, sheet.max_row+1):\n",
|
||
" if sheet.cell(n, 4).value is not None: \n",
|
||
" code = int(sheet.cell(n, 4).value)\n",
|
||
" person.setdefault(code, {})\n",
|
||
" dict1 = {}\n",
|
||
" name = sheet.cell(n, 5).value\n",
|
||
" dict1['name'] = name\n",
|
||
" dict1['bh'] = n - 1\n",
|
||
" dict1['sex'] = sheet.cell(n, 6).value\n",
|
||
" if sheet.cell(n, 9).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n, 9).value)\n",
|
||
" if sheet.cell(n,8).value is not None:\n",
|
||
" dict1['id_num'] = sheet.cell(n,8).value\n",
|
||
" if sheet.cell(n,3).value is not None:\n",
|
||
" dict1['unit'] = sheet.cell(n,3).value\n",
|
||
" person[code] = dict1\n",
|
||
"print(len(person))\n",
|
||
"filename = 'data/杨庙恢复版信息.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "de1ce95b-4590-4eee-bd51-d37beabd6f87",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 风险筛选统计卡可用人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "f21fff31-0da6-4c1a-bf7c-8c4a1d4a3ecf",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"re_ta = {}\n",
|
||
"dict1 = {}\n",
|
||
"list1 = []\n",
|
||
"#print(\"\\n运动项目信息:\")\n",
|
||
"filename = 'data/140.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",
|
||
"list2 = []\n",
|
||
"for result in list1:\n",
|
||
" user = int(result[2])\n",
|
||
" if user not in list2:\n",
|
||
" list2.append(user)\n",
|
||
"list2.sort()\n",
|
||
"set1 = set()\n",
|
||
"filename = 'data/杨庙恢复版信息.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict_base = json.load(fl)\n",
|
||
"for k, v in dict_base.items():\n",
|
||
" set1.add(int(k))\n",
|
||
"filename = 'data/杨庙运动风险筛查统计表信息.json'\n",
|
||
"\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"list_fx = []\n",
|
||
"\n",
|
||
"for k,v in dict1.items():\n",
|
||
" \n",
|
||
" if int(k) in list2 and k not in dict_base.keys() and v['name'] != '不详': \n",
|
||
" set1.add(int(k))\n",
|
||
"#print(len(list_fx))\n",
|
||
"#print(len(set1)) \n",
|
||
"for item in list2:\n",
|
||
" if item not in set1:\n",
|
||
" print(item)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b08187a6-41d9-40ec-bc62-d99969148fe7",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 补充恢复版信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "50a5e0f9-3850-48ac-9f3a-f5a7be51a7fd",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"filename = 'data/杨庙恢复版信息.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict_base = json.load(fl)\n",
|
||
"for k, v in dict_base.items():\n",
|
||
" set1.add(int(k))\n",
|
||
"filename = 'data/杨庙运动风险筛查统计表信息.json'\n",
|
||
"\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"for k,v in dict_base.items():\n",
|
||
" if k in dict1.keys() and 'phone' not in v.keys() and 'phone' in dict1[k].keys():\n",
|
||
" #print(k,v['name'])\n",
|
||
" dict_base[k]['phone'] = dict1[k]['phone']\n",
|
||
"\n",
|
||
"for k, v in dict1.items():\n",
|
||
" if int(k) in list2 and k not in dict_base.keys():\n",
|
||
" dict_base[k] = v\n",
|
||
" \n",
|
||
"print(len(dict_base))\n",
|
||
"#print(dict_base)\n",
|
||
"filename = 'data/羊庙人员名单.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"i = 1\n",
|
||
"for k, v in dict_base.items():\n",
|
||
" if 'bh' not in v.keys():\n",
|
||
" name = v['name']\n",
|
||
" n = 0\n",
|
||
" for k1,v1 in dict2.items():\n",
|
||
" if name == v1['name']:\n",
|
||
" bh = k1\n",
|
||
" n = n+1\n",
|
||
" if n ==1:\n",
|
||
" dict_base[k]['bh'] = bh\n",
|
||
" else:\n",
|
||
" print(i,k,v['name'])\n",
|
||
" i+=1\n",
|
||
"filename = 'data/杨庙补充汇总信息.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(dict_base, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "41c81dfc-ee3a-4934-8f02-077e3f07e5fc",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导出汇总信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "1106fa5d-f0dd-4af4-bc39-7b106786b438",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"filename = 'data/杨庙补充汇总信息.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"list_item = ['name','bh','sex','phone','unit','id_num']\n",
|
||
"list_data = []\n",
|
||
"\n",
|
||
"for k, v in dict1.items():\n",
|
||
" list_mx = []\n",
|
||
" list_mx.append(k)\n",
|
||
" for item in list_item:\n",
|
||
" if item in v.keys():\n",
|
||
" list_mx.append(v[item])\n",
|
||
" else:\n",
|
||
" list_mx.append('')\n",
|
||
" list_data.append(list_mx)\n",
|
||
"#print(list_data) \n",
|
||
"filename = 'data/羊庙汇总情况表.xlsx'\n",
|
||
"wb = openpyxl.Workbook()\n",
|
||
"sheet = wb.active\n",
|
||
"#sheet.append(title)\n",
|
||
"for row in list_data:\n",
|
||
" sheet.append(row)\n",
|
||
" \n",
|
||
"wb.save(filename) \n",
|
||
"print('ok!')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d31fa9b7-26d8-4101-94d1-f41723428aa9",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 成年问卷导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "dc20aabb-3942-49b9-8841-8e8a0823033a",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"wb = openpyxl.load_workbook('data/羊庙问卷统计表(成年组).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"\n",
|
||
"dict1 = {}\n",
|
||
"no_xinli = [108,389,268,270]\n",
|
||
"sheet = wb.active\n",
|
||
"data1 =list(sheet.values)\n",
|
||
"list_bh = data1[0][1:]\n",
|
||
"del data1[0]\n",
|
||
"print(len(list_bh))\n",
|
||
"for i in range(1,len(list_bh)+1):\n",
|
||
" list2 = []\n",
|
||
" \n",
|
||
" for item in data1:\n",
|
||
" list2.append(item[i])\n",
|
||
" dict1[list_bh[i-1]] = list2\n",
|
||
"for k, v in dict1.items():\n",
|
||
" #if 0 in v:\n",
|
||
" # print(k)\n",
|
||
" if str(k) not in dict2.keys():\n",
|
||
" print(k,'不在清理名单中')\n",
|
||
"\n",
|
||
"#print(dict1)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "9a38f22b-6a8c-422f-a706-07382ccaceda",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 成年问卷导出"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "2c84736a-b6cc-43d6-9407-ead6300748a5",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl)\n",
|
||
"wb = openpyxl.load_workbook('data/羊庙问卷统计表(成年组).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"dict1 = {}\n",
|
||
"list_bh = []\n",
|
||
"no_xinli = [108,389,268,270]\n",
|
||
"zy = [2,7,9,11,12,21,24]\n",
|
||
"sheet = wb.active\n",
|
||
"data1 =list(sheet.values)\n",
|
||
"list_bh = data1[0][1:]\n",
|
||
"del data1[0]\n",
|
||
"\n",
|
||
"\n",
|
||
"for i in range(1,len(list_bh)+1):\n",
|
||
" list2 = []\n",
|
||
" \n",
|
||
" for item in data1:\n",
|
||
" list2.append(item[i])\n",
|
||
" dict1[list_bh[i-1]] = list2\n",
|
||
"#print(dict1)\n",
|
||
"s = ''\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if str(k) in dict3.keys(): \n",
|
||
" if dict3[str(k)]['sex'] ==1:\n",
|
||
" sex = \"m\"\n",
|
||
" else:\n",
|
||
" sex = \"f\"\n",
|
||
" dict2 = {}\n",
|
||
" list_mx = []\n",
|
||
" list_mx.append(f'\"Gender\":\"{sex}\"')\n",
|
||
" list_mx.append(f'\"Age\":\"M\"')\n",
|
||
" dict2['surveyId'] = \"merge1\"\n",
|
||
" dict2['name'] = dict3[str(k)]['name'] \n",
|
||
" name = dict3[str(k)]['name'] \n",
|
||
" dict2['code'] = str(k)\n",
|
||
" ss = ''\n",
|
||
" \n",
|
||
" if k not in no_xinli:\n",
|
||
" for i in range(0,47):\n",
|
||
" list_mx.append(f'\"q{i+1}M\":{v[i]}') \n",
|
||
" \n",
|
||
" for i in range(1,61):\n",
|
||
" if i not in zy:\n",
|
||
" list_mx.append(f'\"q{i}\":{v[46+i]}')\n",
|
||
" for i in range(1,27):\n",
|
||
" list_mx.append(f'\"qv{i}\":{v[106+i]}')\n",
|
||
" ss = ','.join(list_mx)\n",
|
||
" ss ='{'+ss+'}'\n",
|
||
" dict2['data'] = ss\n",
|
||
" sj = '2023-03-28 20:02:00'\n",
|
||
" s= s+f'(\"merge1\",\"{name}\",\"{str(k)}\",\\'{ss}\\',\"{sj}\"),'\n",
|
||
" #print(dict2)\n",
|
||
"print(s)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "75dda87e-804e-42ba-b1a4-08c8a8b65050",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 老年问卷导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "09a354e6-a07a-40b8-9b8c-3499fb0b7c28",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"wb = openpyxl.load_workbook('data/羊庙问卷统计表(老年组).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"dict1 = {}\n",
|
||
"dict3 = {}\n",
|
||
"no_xinli = [286]\n",
|
||
"sheet = wb.active\n",
|
||
"data1 =list(sheet.values)\n",
|
||
"list_bh = data1[0][1:]\n",
|
||
"print(list_bh)\n",
|
||
"del data1[0]\n",
|
||
"print(len(list_bh))\n",
|
||
"for i in range(1,len(list_bh)+1):\n",
|
||
" list2 = []\n",
|
||
" \n",
|
||
" for item in data1:\n",
|
||
" list2.append(item[i])\n",
|
||
" dict1[list_bh[i-1]] = list2\n",
|
||
"for k, v in dict1.items():\n",
|
||
" #if 0 in v or ' ' in v:\n",
|
||
" # print(k)\n",
|
||
" if str(k) not in dict2.keys():\n",
|
||
" print(k,'不在清理名单中')\n",
|
||
"#print(dict1)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e2e311b1-7436-49e3-bf52-93c38f088be1",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 老年问卷导出"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "f41e130b-06e5-45ee-bf3d-cc25dfcc653d",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl)\n",
|
||
"wb = openpyxl.load_workbook('data/羊庙问卷统计表(老年组).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"dict1 = {}\n",
|
||
"\n",
|
||
"no_xinli = [286]\n",
|
||
"sheet = wb.active\n",
|
||
"data1 =list(sheet.values)\n",
|
||
"list_bh = data1[0][1:]\n",
|
||
"#print(list_bh)\n",
|
||
"del data1[0]\n",
|
||
"\n",
|
||
"for i in range(1,len(list_bh)+1):\n",
|
||
" list2 = []\n",
|
||
" \n",
|
||
" for item in data1:\n",
|
||
" list2.append(item[i])\n",
|
||
" dict1[list_bh[i-1]] = list2\n",
|
||
"#print(dict1)\n",
|
||
"s = ''\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if str(k) in dict3.keys(): \n",
|
||
" if dict3[str(k)]['sex'] ==1:\n",
|
||
" sex = \"m\"\n",
|
||
" else:\n",
|
||
" sex = \"f\"\n",
|
||
" dict2 = {}\n",
|
||
" list_mx = []\n",
|
||
" list_mx.append(f'\"Gender\":\"{sex}\"')\n",
|
||
" list_mx.append(f'\"Age\":\"O\"')\n",
|
||
" dict2['surveyId'] = \"merge1\"\n",
|
||
" dict2['name'] = dict3[str(k)]['name'] \n",
|
||
" dict2['code'] = str(k) \n",
|
||
" name = dict3[str(k)]['name'] \n",
|
||
" if k not in no_xinli:\n",
|
||
" for i in range(0,30):\n",
|
||
" list_mx.append(f'\"q{i+1}O\":{v[i]}') \n",
|
||
" \n",
|
||
" for i in range(1,61):\n",
|
||
" if i not in zy:\n",
|
||
" list_mx.append(f'\"q{i}\":{v[29+i]}')\n",
|
||
" for i in range(1,27):\n",
|
||
" list_mx.append(f'\"qv{i}\":{v[89+i]}')\n",
|
||
" ss = ','.join(list_mx)\n",
|
||
" ss ='{'+ss+'}'\n",
|
||
" dict2['data'] = ss\n",
|
||
" sj = '2023-03-28 20:02:00'\n",
|
||
" s= s+f'(\"merge1\",\"{name}\",\"{str(k)}\",\\'{ss}\\',\"{sj}\"),'\n",
|
||
" #print(dict2)\n",
|
||
"print(s)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3262d713-92a4-4790-81a3-976ff308ee3d",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计网络问卷信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "08980670-fda9-4660-a619-2f5f5ed8d334",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"filename = 'data/merge1.json'\n",
|
||
"\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"dict3 = {}\n",
|
||
"for k, v in dict1.items():\n",
|
||
" print(len(v))\n",
|
||
" for item in v:\n",
|
||
" phone = item['phone']\n",
|
||
" dict3.setdefault(phone,{})\n",
|
||
" #dict3[phone]['data'] = v['data']\n",
|
||
" for k1,v1 in dict2.items():\n",
|
||
" if 'phone' in v1.keys() and phone == v1['phone']:\n",
|
||
" dict3[phone]['bh'] = k1\n",
|
||
"print(dict3)\n",
|
||
"for k, v in dict2.items():\n",
|
||
" for k1, v1 in dict2.items():\n",
|
||
" \n",
|
||
" if 'bh' not in v.keys():\n",
|
||
" print(k)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e06b0149-c1ff-4fd0-b692-1be391433f40",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 按照测试编号管理"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "54c8e75c-6d3a-4b0d-91a1-c5e9e79a119f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入测试人员信息表(符合条件)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "b51b73fa-97fa-473c-ab8a-d1fd958eb52a",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"import time\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙体测明确人员信息表(20230328).xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"person = {}\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",
|
||
" name = sheet.cell(n, 2).value \n",
|
||
" dict1['name'] = name\n",
|
||
" dict1['sex'] = sheet.cell(n, 3).value\n",
|
||
" dict1['birth'] = str(sheet.cell(n, 4).value).split(' ')[0]\n",
|
||
" if sheet.cell(n, 5).value is not None:\n",
|
||
" dict1['phone'] = str(sheet.cell(n, 5).value)\n",
|
||
" if sheet.cell(n,6).value is not None:\n",
|
||
" dict1['unit'] = sheet.cell(n,6).value \n",
|
||
" person[code] = dict1\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False,default=str)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "cc0c1a86-e15f-43e9-99e9-140aed8475bf",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 体测报告更名按部门分组"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ac3bb674-77e2-4edb-aae7-7b589c8d9b5a",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import math\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"old = []\n",
|
||
"depart = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" m_depart = v['unit']\n",
|
||
" if m_depart not in depart:\n",
|
||
" depart.append(m_depart)\n",
|
||
" \n",
|
||
"fi_path = '/data/pdf/ydyb/140/2023-03-29'\n",
|
||
"\n",
|
||
"\n",
|
||
"# 创建部门办公室 \n",
|
||
"m_path = 'file/140'\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 = dict1[str(n)]['unit']\n",
|
||
" name = dict1[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": "markdown",
|
||
"id": "a1e61c81-d63b-4089-8d79-f05b4a7a35e2",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成体检报告情况表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "b1ff81f5-a8fa-4cea-9158-f80bccbf1494",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"old = []\n",
|
||
"depart = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" m_depart = v['unit']\n",
|
||
" if m_depart not in depart:\n",
|
||
" depart.append(m_depart)\n",
|
||
" \n",
|
||
"fi_path = '/data/pdf/ydyb/140/2023-03-29'\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",
|
||
"list1 = []\n",
|
||
"for n in old:\n",
|
||
" list2 =[]\n",
|
||
" unit = dict1[str(n)]['unit']\n",
|
||
" name = dict1[str(n)]['name']\n",
|
||
" list2 = [str(n).rjust(5,\"0\"),name,unit]\n",
|
||
" list1.append(list2)\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) \n",
|
||
"print('ok!')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "791d2bce-3183-4405-b41a-4da8df6f5567",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成脊柱问卷信息表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "78109eb9-9c40-4289-b358-a68e64bb3361",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import pymysql\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']\n",
|
||
"title = ['编号','姓名','性别']\n",
|
||
"for item in xm:\n",
|
||
" title.append(item)\n",
|
||
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
||
"cursor = db.cursor()\n",
|
||
"sql = 'SELECT a.phone ,a.name,a.code,a.data FROM Survey as a WHERE a.surveyId =\"merge1\"'\n",
|
||
"cursor.execute(sql)\n",
|
||
"results = cursor.fetchall()\n",
|
||
"list2 =[]\n",
|
||
"for result in results: \n",
|
||
" c=json.loads(result[3])\n",
|
||
" if result[2] is None:\n",
|
||
" phone = result[0]\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if 'phone' in v.keys() and phone ==v['phone']:\n",
|
||
" list1 = []\n",
|
||
" code = k\n",
|
||
" name = v['name']\n",
|
||
" list1.append(code)\n",
|
||
" list1.append(name)\n",
|
||
" list1.append(v['sex'])\n",
|
||
" for item in xm:\n",
|
||
" if item in c.keys():\n",
|
||
" list1.append(c[item])\n",
|
||
" else:\n",
|
||
" list1.append('')\n",
|
||
" list2.append(list1)\n",
|
||
" else:\n",
|
||
" list1 = []\n",
|
||
" code = result[2]\n",
|
||
" name = result[1]\n",
|
||
" list1.append(code)\n",
|
||
" list1.append(name)\n",
|
||
" list1.append(v['sex'])\n",
|
||
" for item in xm:\n",
|
||
" if item in c.keys():\n",
|
||
" list1.append(c[item])\n",
|
||
" else:\n",
|
||
" list1.append('') \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) \n",
|
||
"print('ok!') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "8a641c17-f628-4f5f-94bb-de95e0c40286",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import pymysql\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']\n",
|
||
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
||
"cursor = db.cursor()\n",
|
||
"sql = 'SELECT a.phone ,a.name,a.code,a.data FROM Survey as a WHERE a.surveyId =\"merge1\"'\n",
|
||
"cursor.execute(sql)\n",
|
||
"results = cursor.fetchall()\n",
|
||
"for result in results:\n",
|
||
" c=json.loads(result[3])\n",
|
||
" print(c, type(c))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "beb22a32-ae9b-4602-bf1a-30b8e243ea1f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 查询中年组心理测评人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ce028da4-2cb1-4ee2-b7f3-6f3cfcda1851",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import pymysql\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']\n",
|
||
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
||
"cursor = db.cursor()\n",
|
||
"sql = 'SELECT a.phone ,a.name,a.code,a.data FROM Survey as a WHERE a.surveyId =\"merge1\"'\n",
|
||
"cursor.execute(sql)\n",
|
||
"results = cursor.fetchall()\n",
|
||
"list2 =[]\n",
|
||
"for result in results:\n",
|
||
" c=json.loads(result[3])\n",
|
||
" if 'q1M' in c.keys():\n",
|
||
" if result[2] is None:\n",
|
||
" phone = result[0]\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if 'phone' in v.keys() and phone ==v['phone']:\n",
|
||
" list1 = []\n",
|
||
" code = k\n",
|
||
" name = v['name']\n",
|
||
" list1.append(code)\n",
|
||
" list1.append(name)\n",
|
||
" list1.append(v['sex'])\n",
|
||
" list1.append(v['birth'])\n",
|
||
" list1.append(v['unit'])\n",
|
||
" list2.append(list1)\n",
|
||
" else:\n",
|
||
" list1 = []\n",
|
||
" code = result[2]\n",
|
||
" name = result[1]\n",
|
||
" list1.append(code)\n",
|
||
" list1.append(name)\n",
|
||
" list1.append(dict1[code]['sex'])\n",
|
||
" list1.append(dict1[code]['birth'])\n",
|
||
" list1.append(dict1[code]['unit'])\n",
|
||
" \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) \n",
|
||
"print('ok!') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "be6e17d8-7687-422c-994d-35afd014aee6",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 成年人心理问卷体测报告更名按部门分组"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e24a046e-77cd-4df2-af89-733d718ce543",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import math\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"old = []\n",
|
||
"depart = []\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙心理问卷成年组人员明细表.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"\n",
|
||
"list_bh = []\n",
|
||
"\n",
|
||
"for n in range(1,sheet.max_row+1):\n",
|
||
" list_bh.append(int(sheet.cell(n, 1).value)) \n",
|
||
" m_depart = sheet.cell(n, 5).value\n",
|
||
" if m_depart not in depart:\n",
|
||
" depart.append(m_depart)\n",
|
||
" \n",
|
||
"fi_path = '/data/pdf/ydyb/140/2023-04-01'\n",
|
||
"\n",
|
||
"\n",
|
||
"# 创建部门办公室 \n",
|
||
"m_path = 'file/140wenjuan'\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",
|
||
" if ofn in list_bh:\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",
|
||
" name = dict1[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": "markdown",
|
||
"id": "387b5c35-886a-41dc-b787-f67154efa758",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 杨庙社区处方分组"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b8dafd4a-2bd4-4626-b8a8-45ae9cbe7177",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 人员分组"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "bc731911-3390-4c5e-bccf-fc7c367e1172",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 高血压人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 60,
|
||
"id": "5d24953d-4ded-4e1c-911c-a0baab222399",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-04-01T09:44:43.894749Z",
|
||
"iopub.status.busy": "2023-04-01T09:44:43.893902Z",
|
||
"iopub.status.idle": "2023-04-01T09:44:44.014089Z",
|
||
"shell.execute_reply": "2023-04-01T09:44:44.013281Z",
|
||
"shell.execute_reply.started": "2023-04-01T09:44:43.894709Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"['437', '422', '417', '416', '415', '403', '399', '397', '393', '392', '389', '387', '382', '377', '376', '371', '365', '364', '362', '361', '357', '355', '353', '351', '349', '346', '345', '344', '340', '335', '333', '332', '330', '329', '328', '326', '323', '322', '317', '315', '314', '309', '306', '305', '294', '293', '291', '282', '281', '279', '278', '277', '276', '274', '273', '272', '271', '270', '265', '264', '262', '261', '259', '258', '256', '239', '236', '223', '221', '219', '214', '213', '212', '209', '208', '191', '188', '187', '186', '183', '179', '174', '172', '168', '167', '166', '164', '162', '160', '157', '156', '140', '139', '138', '137', '136', '135', '127', '124', '123', '122', '121', '116', '115', '111', '110', '106', '103', '100', '98', '97', '96', '95', '94', '89', '76', '74', '73', '58', '53', '52', '46', '42', '41', '40', '39', '35', '34', '30', '28', '26', '25', '23', '16', '13', '12', '11', '8', '6', '5']\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import os,sys,shutil\n",
|
||
"import json\n",
|
||
"import math\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙运动风险筛查统计表.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"# sheets = wb.sheetnames\n",
|
||
"\n",
|
||
"list_gxy = []\n",
|
||
"\n",
|
||
"for n in range(2,sheet.max_row+1):\n",
|
||
" code = sheet.cell(n, 1).value\n",
|
||
" if sheet.cell(n, 3).value is not None:\n",
|
||
" code = sheet.cell(n, 1).value\n",
|
||
" gxy = sheet.cell(n, 3).value\n",
|
||
" if str(code) in dict1.keys() and int(gxy) ==1:\n",
|
||
" list_gxy.append(str(code))\n",
|
||
"print(list_gxy)\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a1f4ee17-4a47-4b46-a139-92e25c363a82",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-04-01T09:22:21.145580Z",
|
||
"iopub.status.busy": "2023-04-01T09:22:21.145166Z",
|
||
"iopub.status.idle": "2023-04-01T09:22:21.150015Z",
|
||
"shell.execute_reply": "2023-04-01T09:22:21.148725Z",
|
||
"shell.execute_reply.started": "2023-04-01T09:22:21.145552Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"source": [
|
||
"### 失眠人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 55,
|
||
"id": "efa10ba4-0a27-41e6-beb7-27de8f3109a1",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-04-01T09:40:25.949400Z",
|
||
"iopub.status.busy": "2023-04-01T09:40:25.948559Z",
|
||
"iopub.status.idle": "2023-04-01T09:40:26.009374Z",
|
||
"shell.execute_reply": "2023-04-01T09:40:26.008325Z",
|
||
"shell.execute_reply.started": "2023-04-01T09:40:25.949359Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"['134', '147', '177', '181', '185', '193', '200', '201', '208', '213', '251', '263', '292', '320', '347', '358', '374', '383', '410', '435', '434', '437', '433', '155', '113', '108', '97', '92', '245', '71', '70', '69', '65', '64', '60', '58', '54', '32', '180', '217', '411', '414', '370', '381', '389', '270', '278', '192', '190', '196', '17', '13', '12', '11', '5', '4', '436', '121', '122', '124', '133', '137', '138', '141', '142', '143', '150', '157', '158', '160', '167', '115', '114', '111', '103', '96', '94', '93', '89', '87', '85', '83', '79', '77', '233', '234', '236', '74', '73', '59', '55', '53', '52', '49', '48', '47', '43', '42', '35', '34', '26', '23', '172', '171', '175', '186', '289', '290', '294', '310', '309', '316', '199', '202', '207', '209', '210', '211', '219', '222', '223', '229', '415', '6002', '346', '349', '357', '362', '363', '365', '369', '371', '373', '379', '376', '372', '378', '393', '400', '314', '324', '323', '328', '330', '332', '334', '343', '259', '267', '271', '273', '277', '276', '282', '345']\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import pymysql\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"\n",
|
||
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
||
"cursor = db.cursor()\n",
|
||
"sql = 'SELECT a.phone ,a.name,a.code,a.data FROM Survey as a WHERE a.surveyId =\"merge1\"'\n",
|
||
"cursor.execute(sql)\n",
|
||
"results = cursor.fetchall()\n",
|
||
"list_sm =[]\n",
|
||
"for result in results:\n",
|
||
" c=json.loads(result[3])\n",
|
||
" if 'qv7' in c.keys() and c['qv7'] ==1:\n",
|
||
" if result[2] is None:\n",
|
||
" phone = result[0]\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if 'phone' in v.keys() and phone ==v['phone']:\n",
|
||
" list_sm.append(k) \n",
|
||
" else:\n",
|
||
" list_sm.append(result[2])\n",
|
||
"print(list_sm)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0830d7d4-958d-4166-a439-9a6bfca2cf18",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 脊柱调理人员"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 69,
|
||
"id": "e5bd9e8c-00f5-48b7-8cc7-810316e0423b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-04-01T11:11:09.553748Z",
|
||
"iopub.status.busy": "2023-04-01T11:11:09.553341Z",
|
||
"iopub.status.idle": "2023-04-01T11:11:09.598656Z",
|
||
"shell.execute_reply": "2023-04-01T11:11:09.597753Z",
|
||
"shell.execute_reply.started": "2023-04-01T11:11:09.553720Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"['107', '127', '134', '147', '146', '161', '177', '181', '185', '193', '200', '201', '208', '213', '251', '263', '292', '295', '313', '319', '320', '98765', '342', '360', '358', '359', '374', '6000', '6003', '423', '435', '434', '155', '156', '113', '108', '104', '245', '253', '71', '70', '69', '66', '65', '64', '63', '61', '58', '54', '46', '45', '32', '174', '180', '404', '411', '414', '427', '361', '381', '268', '266', '270', '417', '303', '192', '190', '194', '195', '196', '17', '16', '13', '12', '11', '9', '8', '7', '6', '5', '4', '436', '121', '122', '124', '123', '130', '126', '133', '136', '135', '137', '139', '140', '142', '143', '144', '151', '150', '157', '158', '159', '160', '166', '118', '117', '116', '115', '111', '110', '109', '103', '101', '98', '96', '95', '94', '89', '88', '87', '86', '83', '82', '80', '79', '77', '231', '237', '233', '234', '239', '236', '243', '244', '242', '256', '257', '258', '164', '163', '74', '75', '67', '59', '57', '56', '53', '52', '49', '48', '47', '43', '41', '40', '37', '36', '35', '34', '33', '31', '30', '26', '25', '24', '23', '172', '171', '175', '179', '183', '186', '187', '188', '289', '290', '293', '294', '296', '305', '308', '310', '309', '316', '203', '199', '202', '207', '214', '211', '219', '221', '222', '223', '229', '401', '399', '403', '406', '415', '6002', '430', '346', '349', '348', '353', '357', '355', '351', '362', '364', '365', '369', '368', '371', '373', '377', '379', '376', '372', '378', '382', '386', '393', '392', '396', '400', '314', '318', '323', '322', '326', '325', '328', '331', '330', '332', '334', '335', '337', '333', '344', '259', '262', '264', '260', '265', '267', '272', '271', '273', '275', '277', '276', '281', '283', '282', '286', '345']\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import pymysql\n",
|
||
"\n",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"#print(dict1)\n",
|
||
"\n",
|
||
"db = pymysql.connect(host = \"localhost\",user = \"songyi\",password = \"yylzs\",database = \"ydyb\" )\n",
|
||
"cursor = db.cursor()\n",
|
||
"sql = 'SELECT a.phone ,a.name,a.code,a.data FROM Survey as a WHERE a.surveyId =\"merge1\"'\n",
|
||
"cursor.execute(sql)\n",
|
||
"results = cursor.fetchall()\n",
|
||
"list_jz =[]\n",
|
||
"for result in results:\n",
|
||
" c=json.loads(result[3])\n",
|
||
" if ('qv1' in c.keys() and c['qv1'] ==1) or ('qv18' in c.keys() and c['qv18'] ==1):\n",
|
||
" if result[2] is None:\n",
|
||
" phone = result[0]\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if 'phone' in v.keys() and phone ==v['phone']:\n",
|
||
" list_jz.append(k) \n",
|
||
" else:\n",
|
||
" list_jz.append(result[2])\n",
|
||
"print(list_jz)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 70,
|
||
"id": "4c02f3b9-6677-4114-9fd9-f9d8bccaefe0",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-04-01T11:11:18.106136Z",
|
||
"iopub.status.busy": "2023-04-01T11:11:18.105295Z",
|
||
"iopub.status.idle": "2023-04-01T11:11:18.196768Z",
|
||
"shell.execute_reply": "2023-04-01T11:11:18.195822Z",
|
||
"shell.execute_reply.started": "2023-04-01T11:11:18.106095Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'高血压': ['437', '422', '417', '416', '415', '403', '399', '397', '393', '392', '389', '387', '382', '377', '376', '371', '365', '364', '362', '361', '357', '355', '353', '351', '349', '346', '345', '344', '340', '335', '333', '332', '330', '329', '328', '326', '323', '322', '317', '315', '314', '309', '306', '305', '294', '293', '291', '282', '281', '279', '278', '277', '276', '274', '273', '272', '271', '270', '265', '264', '262', '261', '259', '258', '256', '239', '236', '223', '221', '219', '214', '213', '212', '209', '208', '191', '188', '187', '186', '183', '179', '174', '172', '168', '167', '166', '164', '162', '160', '157', '156', '140', '139', '138', '137', '136', '135', '127', '124', '123', '122', '121', '116', '115', '111', '110', '106', '103', '100', '98', '97', '96', '95', '94', '89', '76', '74', '73', '58', '53', '52', '46', '42', '41', '40', '39', '35', '34', '30', '28', '26', '25', '23', '16', '13', '12', '11', '8', '6', '5'], '失眠': ['134', '147', '177', '181', '185', '193', '200', '201', '251', '263', '292', '320', '347', '358', '374', '383', '410', '435', '434', '433', '155', '113', '108', '92', '245', '71', '70', '69', '65', '64', '60', '54', '32', '180', '217', '411', '414', '370', '381', '192', '190', '196', '17', '4', '436', '133', '141', '142', '143', '150', '158', '114', '93', '87', '85', '83', '79', '77', '233', '234', '59', '55', '49', '48', '47', '43', '171', '175', '289', '290', '310', '316', '199', '202', '207', '210', '211', '222', '229', '6002', '363', '369', '373', '379', '372', '378', '400', '324', '334', '343', '267'], '脊柱调理': ['107', '146', '161', '295', '313', '319', '98765', '342', '360', '359', '6000', '6003', '423', '104', '253', '66', '63', '61', '45', '404', '427', '268', '266', '303', '194', '195', '9', '7', '130', '126', '144', '151', '159', '118', '117', '109', '101', '88', '86', '82', '80', '231', '237', '243', '244', '242', '257', '163', '75', '67', '57', '56', '37', '36', '33', '31', '24', '296', '308', '203', '401', '406', '430', '348', '368', '386', '396', '318', '325', '331', '337', '260', '275', '283', '286'], '整体调理': ['2', '3', '10', '15', '18', '22', '27', '29', '38', '44', '51', '62', '68', '72', '78', '81', '84', '90', '91', '99', '105', '112', '119', '120', '128', '129', '132', '145', '148', '149', '152', '153', '154', '165', '169', '170', '173', '176', '178', '184', '189', '197', '198', '204', '205', '206', '215', '216', '218', '220', '224', '225', '227', '228', '235', '238', '240', '241', '248', '249', '250', '255', '269', '284', '285', '287', '297', '301', '302', '307', '321', '327', '336', '352', '354', '356', '375', '391', '394', '395', '402', '405', '407', '408', '412', '418', '419', '420', '421', '424', '429', '431', '432', '6001', '98776']}\n",
|
||
"ok!\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"dict2 = {}\n",
|
||
"dict2.setdefault('高血压',[])\n",
|
||
"dict2['高血压'] = list_gxy\n",
|
||
"dict2.setdefault('失眠',[])\n",
|
||
"for item in list_sm:\n",
|
||
" if item not in list_gxy:\n",
|
||
" dict2['失眠'].append(item)\n",
|
||
"\n",
|
||
"dict2.setdefault('脊柱调理',[])\n",
|
||
"for item in list_jz:\n",
|
||
" if item not in list_gxy and item not in list_sm:\n",
|
||
" dict2['脊柱调理'].append(item)\n",
|
||
"\n",
|
||
"list_other = []\n",
|
||
"for item in dict1.keys():\n",
|
||
" if item not in list_gxy and item not in list_sm and item not in list_jz:\n",
|
||
" list_other.append(item)\n",
|
||
"dict2['整体调理'] = list_other\n",
|
||
"print(dict2)\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict2.items():\n",
|
||
" for item in v:\n",
|
||
" list2 = [k,item,dict1[item]['name'],dict1[item]['sex'],dict1[item]['birth'],dict1[item]['unit']]\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!') \n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "0077bd98-5a26-4543-a262-c66f419b6db3",
|
||
"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
|
||
}
|