318 lines
9.7 KiB
Plaintext
318 lines
9.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "70c15816-2ad5-4486-be33-378963d70934",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 人员信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "07f7e97e-670e-4301-b83d-1304514f15d5",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\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,1).value is not None:\n",
|
|
" code = int(sheet.cell(n, 1).value)\n",
|
|
" person.setdefault(code, {})\n",
|
|
" dict1 = {}\n",
|
|
" dict1['name'] = sheet.cell(n, 2).value\n",
|
|
" if sheet.cell(n, 3).value ==1:\n",
|
|
" sex = '男'\n",
|
|
" else:\n",
|
|
" sex = '女'\n",
|
|
" dict1['sex'] = sex\n",
|
|
" birth = str(sheet.cell(n, 4).value).split()[0]\n",
|
|
" dict1['birth'] = birth\n",
|
|
" dict1['unit'] = sheet.cell(n, 6).value\n",
|
|
" if sheet.cell(n,5).value is not None:\n",
|
|
" dict1['phone'] = str(sheet.cell(n, 5).value) \n",
|
|
" person[code] = dict1\n",
|
|
"\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": "962f6edd-c8d1-42a2-aaff-58f92ccf8d56",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 问卷人员信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "80d51661-e306-477a-84e8-8b9daf9cdb21",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"import datetime\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,7).value is not None and sheet.cell(n,4).value is not None:\n",
|
|
" bh = int(sheet.cell(n, 7).value)\n",
|
|
" person.setdefault(bh, {})\n",
|
|
" dict1 = {}\n",
|
|
" dict1['name'] = sheet.cell(n, 2).value\n",
|
|
" dict1['code'] = sheet.cell(n, 1).value\n",
|
|
" if sheet.cell(n, 3).value ==1:\n",
|
|
" sex = '男'\n",
|
|
" else:\n",
|
|
" sex = '女'\n",
|
|
" dict1['sex'] = sex\n",
|
|
" birth = str(sheet.cell(n, 4).value).split()[0]\n",
|
|
" \n",
|
|
" if len(birth) == 2:\n",
|
|
" dict1['age'] = int(birth)\n",
|
|
" else:\n",
|
|
" birth.replace('/','-')\n",
|
|
" \n",
|
|
" birth = birth.split('-') \n",
|
|
" nian = int(birth[0].strip())\n",
|
|
" yue = int(birth[1].strip())\n",
|
|
" ri = int(birth[2].strip())\n",
|
|
" #print(k,nian,yue,ri)\n",
|
|
" days = (datetime.date(2023, 5, 31)-datetime.date(nian,yue,ri)).days\n",
|
|
" dict1['age'] = round(days/365)\n",
|
|
" if sheet.cell(n,5).value is not None:\n",
|
|
" dict1['phone'] = str(sheet.cell(n, 5).value) \n",
|
|
" person[bh] = dict1\n",
|
|
"\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": "25ffcc7a-5709-4377-b821-bce5097cbd78",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导入脊柱问卷信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "85599cf2-3673-4d3b-ae77-f5ef77217f71",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"wb = openpyxl.load_workbook('data/西藏手工记录.xlsx')\n",
|
|
"sheet = wb['Sheet1']\n",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"data1 =list(sheet.values)\n",
|
|
"list_bh = data1[0][1:]\n",
|
|
"del data1[0]\n",
|
|
"for i in range(1,len(list_bh)+1):\n",
|
|
" list2 = []\n",
|
|
" dict1.setdefault(int(list_bh[i-1]),{})\n",
|
|
" for item in data1:\n",
|
|
" list2.append(item[i])\n",
|
|
" dict1[int(list_bh[i-1])]['wenjuan'] = list2\n",
|
|
"print(dict1)\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": "56538b71-aedc-4880-b655-a814778bda07",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导入体测信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "fa2fe417-cd1d-47c1-bcf6-2e711d49af20",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"wb = openpyxl.load_workbook('data/西藏手工记录.xlsx')\n",
|
|
"sheet = wb['Sheet2']\n",
|
|
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"data1 =list(sheet.values)\n",
|
|
"\n",
|
|
"for item in data1:\n",
|
|
" bh = str(item[0])\n",
|
|
" dict1.setdefault(bh,{})\n",
|
|
" xm = item[1]\n",
|
|
" result = item[2]\n",
|
|
" dict1[bh][xm] = result\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": "0a66d37f-6436-4e3c-abe1-d5fd4796e683",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出手工信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "59b31b70-2af4-40ba-af8c-e72354508c19",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/西藏手工问卷人员名单.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
"filename = 'data/西藏脊柱问卷原始信息.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"for k, v in dict1.items():\n",
|
|
" s = ''\n",
|
|
" if k in dict2.keys():\n",
|
|
" if dict2[str(k)]['sex'] =='男':\n",
|
|
" sex = \"m\"\n",
|
|
" else:\n",
|
|
" sex = \"f\"\n",
|
|
" dict3 = {}\n",
|
|
" list_mx = []\n",
|
|
" name = dict2[str(k)]['name'] \n",
|
|
" list_mx.append(f'\"name\":\"{name}\"')\n",
|
|
" list_mx.append(f'\"Gender\":\"{sex}\"')\n",
|
|
" age = dict2[str(k)]['age']\n",
|
|
" list_mx.append(f'\"Age\":{age}')\n",
|
|
" dict3['surveyId'] = \"zsyxz1\"\n",
|
|
" dict3['name'] = dict2[str(k)]['name'] \n",
|
|
" code = dict2[str(k)]['code']\n",
|
|
" for item in v.keys():\n",
|
|
" if item == 'wenjuan':\n",
|
|
" for i in range(0,21):\n",
|
|
" if v[item][i] ==1:\n",
|
|
" result = 'ture'\n",
|
|
" else:\n",
|
|
" result ='false' \n",
|
|
" item_name = 'q'+str(i+1)\n",
|
|
" list_mx.append(f'\"{item_name}\":{result}')\n",
|
|
" for i in range(23,25):\n",
|
|
" if v[item][i] ==1:\n",
|
|
" result = 'ture'\n",
|
|
" else:\n",
|
|
" result ='false' \n",
|
|
" item_name = 'q'+str(i)\n",
|
|
" list_mx.append(f'\"{item_name}\":{result}')\n",
|
|
" if sex == 'f':\n",
|
|
" item_name = 'q25a'\n",
|
|
" if v[item][21] ==1:\n",
|
|
" result = 'ture'\n",
|
|
" else:\n",
|
|
" result ='false'\n",
|
|
" list_mx.append(f'\"{item_name}\":{result}')\n",
|
|
" else:\n",
|
|
" item_name = 'q22'\n",
|
|
" if v[item][22] ==1:\n",
|
|
" result = 'ture'\n",
|
|
" else:\n",
|
|
" result ='false'\n",
|
|
" list_mx.append(f'\"{item_name}\":{result}')\n",
|
|
" item_name = 'q25b'\n",
|
|
" if v[item][25] ==1:\n",
|
|
" result = 'ture'\n",
|
|
" else:\n",
|
|
" result ='false'\n",
|
|
" list_mx.append(f'\"{item_name}\":{result}')\n",
|
|
" else: \n",
|
|
" item_name = item \n",
|
|
" list_mx.append(f'\"{item_name}\":{v[item]}')\n",
|
|
" ss = ','.join(list_mx)\n",
|
|
" ss ='{'+ss+'}'\n",
|
|
" dict3['data'] = ss\n",
|
|
" sj = '2023-06-01 20:00:00'\n",
|
|
" s= s+f'(\"zsyxz1\",\"{name}\",\"{code}\",\\'{ss}\\',\"{sj}\"),'\n",
|
|
" print(s)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ab602820-2ec4-4e9d-a40e-3e6cf6004374",
|
|
"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
|
|
}
|