This commit is contained in:
512song committed 2023-11-26 09:27:24 +00:00
1 parent 8432a5940e
commit 6bb4c5d7ae
2 files changed
+705 -102

No files matched your search

@@ -0,0 +1,696 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "4c74893b-fca2-45f8-8254-2060886909ec",
"metadata": {},
"source": [
"## 人员信息导入"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "abde40cd-d8e3-434d-ade2-207cf80cab49",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T05:16:54.569572Z",
"iopub.status.busy": "2023-10-27T05:16:54.568768Z",
"iopub.status.idle": "2023-10-27T05:16:54.594762Z",
"shell.execute_reply": "2023-10-27T05:16:54.592567Z",
"shell.execute_reply.started": "2023-10-27T05:16:54.569497Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = 'data/data_世纪花园.json'\n",
"with open(filename,'r') as fl:\n",
" list1 = json.load(fl)\n",
"\n",
"dict1 = {}\n",
"for item in list1:\n",
" id = int(item['id'])\n",
" dict1.setdefault(str(id),{})\n",
" dict1[str(id)]['name'] = item['name']\n",
" dict1[str(id)]['sex'] = item['gender']\n",
" dict1[str(id)]['birth'] = item['birth']\n",
" dict1[str(id)]['phone'] = item['phone']\n",
" if item['unit'] == '':\n",
" dict1[str(id)]['unit'] = '未确定'\n",
" else:\n",
" dict1[str(id)]['unit'] = item['unit']\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": "0dc90cf8-0a51-49ab-8f93-81acfd359e63",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "693820f4-f79d-4e6b-9901-0aae57bc6c92",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T05:21:49.693975Z",
"iopub.status.busy": "2023-10-27T05:21:49.693687Z",
"iopub.status.idle": "2023-10-27T05:21:49.714898Z",
"shell.execute_reply": "2023-10-27T05:21:49.714209Z",
"shell.execute_reply.started": "2023-10-27T05:21:49.693956Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"84\n",
"84\n"
]
}
],
"source": [
"import json\n",
"import datetime\n",
"import csv\n",
"from datetime import date\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",
"item['1']['en'] = 'lung'\n",
"item['2']['en'] = 'grip'\n",
"item['3']['en'] = 'flexion'\n",
"item['4']['en'] = 'jump'\n",
"item['5']['en'] = 'pushup'\n",
"item['6']['en'] = 'balance'\n",
"item['7']['en'] = 'reaction'\n",
"item['8']['en'] = 'step'\n",
"item['9']['en'] = 'situp'\n",
"item['10']['en'] = 'height'\n",
"item['11']['en'] = 'weight'\n",
"\n",
"\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"filename = 'data/世纪花园人员信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20231027.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",
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
"for result in list1:\n",
" user = str(result[2])\n",
" rq = date.fromisoformat(result[6].replace('/','-'))\n",
" if user in dict1.keys():\n",
" l_xm = []\n",
" m_item = str(result[3]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" re_ta[user]['sex'] = dict1[user]['sex']\n",
" if dict1[user]['sex'] == '男':\n",
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
" else:\n",
" l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
" re_ta[user]['unit'] = dict1[user]['unit']\n",
" birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\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",
" item_name = item[m_item]['en'] \n",
" if item_name in l_xm: \n",
" days = (rq-birth).days \n",
" re_ta[user]['age'] = int(days/365)\n",
" re_ta[user]['month'] = int(days/365*12)\n",
" re_ta[user]['rq'] = result[6]\n",
"\n",
"\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[4])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
"print(len(re_ta))\n",
"filename = 'data/result_世纪花园.json'\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl, ensure_ascii=False) \n",
"print(len(re_ta))"
]
},
{
"cell_type": "markdown",
"id": "2d417d9a-ca85-4c9f-8673-11f5f1033d1f",
"metadata": {},
"source": [
"## 计算项目成绩"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "9230c78a-40d1-47ed-9bfc-94525b44f8f9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T06:50:35.251325Z",
"iopub.status.busy": "2023-10-27T06:50:35.250643Z",
"iopub.status.idle": "2023-10-27T06:50:35.319251Z",
"shell.execute_reply": "2023-10-27T06:50:35.317670Z",
"shell.execute_reply.started": "2023-10-27T06:50:35.251263Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict3 = json.load(fl) \n",
"for k,v in dict3.items():\n",
" item[k] = v\n",
"item['1']['en'] = 'lung'\n",
"item['2']['en'] = 'grip'\n",
"item['3']['en'] = 'flexion'\n",
"item['4']['en'] = 'jump'\n",
"item['5']['en'] = 'pushup'\n",
"item['6']['en'] = 'balance'\n",
"item['7']['en'] = 'reaction'\n",
"item['8']['en'] = 'step'\n",
"item['9']['en'] = 'situp'\n",
"item['10']['en'] = 'height'\n",
"item['11']['en'] = 'weight'\n",
"\n",
"filename = 'data/体质检测标准 (1).json' \n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"\n",
"\n",
"def cal_score(data1):\n",
" #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n",
" person = dict1['person']\n",
" criteria = dict1['criteria']\n",
" if data1['age'] >59:\n",
" data1['age'] = 59\n",
" if data1['age'] <20:\n",
" data1['age'] = 20\n",
" info = data1['sex']+str(data1['age'])\n",
" bz = person[info]\n",
" mx = criteria[bz][data1['item']]\n",
" result = data1['result'] \n",
" if data1['item'] == 'reaction':\n",
" for bz1 in mx:\n",
" if result > bz1:\n",
" #print(bz1)\n",
" score = mx.index(bz1,0)\n",
" break\n",
" else:\n",
" score = 5\n",
" else:\n",
" for bz1 in mx:\n",
" if result < bz1:\n",
" #print(bz1)\n",
" score = mx.index(bz1,0)\n",
" break\n",
" else:\n",
" score = 5\n",
" return(score)\n",
"filename = 'data/体质检测标准_BMI.json'\n",
"with open(filename,'r') as fl:\n",
" dict4 = json.load(fl) \n",
" \n",
"def cal_bmi(data1):\n",
" # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
" person = dict4['person']\n",
" criteria = dict4['criteria']\n",
" if data1['age'] > 59:\n",
" data1['age'] = 59\n",
" if data1['age'] <20:\n",
" data1['age'] = 20\n",
" info = data1['sex']+str(data1['age'])\n",
" bz = person[info]\n",
" #print(bz)\n",
" result = data1['result']\n",
" #print(data1['code'],result)\n",
" height = int(float(result.split(',')[0]))\n",
" weight = float(result.split(',')[1])\n",
" if str(height) not in criteria[bz]:\n",
" score = 1\n",
" else: \n",
" mx = criteria[bz][str(height)]\n",
" if weight < mx[0]:\n",
" score = 1\n",
" elif weight < mx[1]:\n",
" score = 3\n",
" elif weight < mx[2]:\n",
" score = 5 \n",
" elif weight <= mx[3]:\n",
" score = 3 \n",
" elif weight > mx[3]:\n",
" score = 1\n",
" return score\n",
" \n",
" \n",
"\n",
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
"filename = 'data/result_世纪花园.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"for k, v in dict2.items():\n",
" #print(k)\n",
" if v['sex'] == '男':\n",
" sex = 'M'\n",
" else:\n",
" sex = 'F' \n",
" if 'height' in v.keys() and 'weight' in v.keys():\n",
" bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
" dict2[k]['bmi'] = {}\n",
" dict2[k]['bmi']['成绩'] = bmi_data\n",
" dict2[k]['bmi']['score'] = cal_bmi(data1)\n",
" for item_en in list_item:\n",
" if item_en in v.keys(): \n",
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
" dict2[k][item_en]['score'] = cal_score(data1)\n",
" #print(k,v[item_en]['成绩'],cal_score(data1))\n",
"\n",
"filename = f'data/result_世纪花园.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4365fd0d-1e79-48a3-b580-3041a1340815",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "e86acc03-06e2-4eaf-8207-e1ba834869d3",
"metadata": {},
"source": [
"## 问卷信息导入"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "c42bb7f4-ae16-4950-8fc9-97e7084e4615",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T06:52:29.033946Z",
"iopub.status.busy": "2023-10-27T06:52:29.033331Z",
"iopub.status.idle": "2023-10-27T06:52:29.132179Z",
"shell.execute_reply": "2023-10-27T06:52:29.130961Z",
"shell.execute_reply.started": "2023-10-27T06:52:29.033886Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"filename = 'data/世纪花园人员信息.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",
"sheet = wb.active\n",
"data1 =list(sheet.values)\n",
"list_bh = data1[0][1:]\n",
"#print(list_bh)\n",
"del data1[0]\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",
"filename = 'data/result_世纪花园.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"for k,v in dict1.items():\n",
" if str(k) in dict2.keys():\n",
" if v[0] is not None:\n",
" psy_yangmiao_old = v[:30]\n",
" #dict2[str(k)]['psy_yangmiao_old'] = psy_yangmiao_old\n",
" if v[30] is not None:\n",
" tcm = v[30:90]\n",
" #print(tcm,len(tcm))\n",
" if v[90] is not None:\n",
" spine = v[90:]\n",
" xx22 = spine[21]\n",
" xx23 = spine[22]\n",
" spine[21] = xx23\n",
" spine[22] = xx22\n",
" \n",
" dict2[str(k)]['psy'] = psy_yangmiao_old\n",
" dict2[str(k)]['tcm'] = tcm\n",
" dict2[str(k)]['spine'] = spine\n",
"filename = 'data/result_世纪花园.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2, fl, ensure_ascii=False) \n",
"print('ok') "
]
},
{
"cell_type": "markdown",
"id": "8ff5f29b-f2cd-4b2f-9716-8ec6bd77db1f",
"metadata": {},
"source": [
"## 生成报告人员信息"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6038af14-e3cf-4e79-9a02-a5d70cb2ed65",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T05:38:50.524545Z",
"iopub.status.busy": "2023-10-27T05:38:50.523900Z",
"iopub.status.idle": "2023-10-27T05:38:50.593781Z",
"shell.execute_reply": "2023-10-27T05:38:50.592319Z",
"shell.execute_reply.started": "2023-10-27T05:38:50.524484Z"
},
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/世纪花园人员信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"\n",
"list1 = []\n",
"for k, v in dict1.items():\n",
" id = str(k).rjust(5,\"0\")\n",
" \n",
" name = v['name']\n",
" list1.append([id,name,v['sex'],v['sex'],v['birth'],v['phone'],v['unit']])\n",
"filename = 'data/世纪花园人员信息.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"\n",
"for row in list1:\n",
" sheet.append(row)\n",
"wb.save(filename)"
]
},
{
"cell_type": "markdown",
"id": "e790c586-9099-4a63-a460-a6d53a1e8f99",
"metadata": {},
"source": [
"### 导入问卷人员信息(有姓名)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "096672ef-c1f1-4b31-a490-efd408b95aec",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T06:17:34.577248Z",
"iopub.status.busy": "2023-10-27T06:17:34.576465Z",
"iopub.status.idle": "2023-10-27T06:17:34.622216Z",
"shell.execute_reply": "2023-10-27T06:17:34.620032Z",
"shell.execute_reply.started": "2023-10-27T06:17:34.577174Z"
},
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import datetime\n",
"import csv\n",
"\n",
"list1 = []\n",
"filename = 'data/Survey_20231027.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",
"#print(list1)\n",
"list3 = []\n",
"for item in list1:\n",
" phone = item[2]\n",
" content = json.loads(item[5])\n",
" name = content['name']\n",
" sex = content['gender']\n",
" birth = content['birth']\n",
" unit = content['unit']\n",
" list2 = [phone,name,sex,birth,unit]\n",
" list3.append(list2)\n",
"filename = 'data/世纪花园人员信息1.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"\n",
"for row in list3:\n",
" sheet.append(row)\n",
"wb.save(filename) \n",
" "
]
},
{
"cell_type": "markdown",
"id": "5ab7d644-c90a-4877-9abf-6d4bd88ef3ef",
"metadata": {},
"source": [
"### 导入问卷人员信息(无姓名)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "8f801647-a326-4bf1-a651-4b52e0296998",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T07:12:12.444411Z",
"iopub.status.busy": "2023-10-27T07:12:12.443958Z",
"iopub.status.idle": "2023-10-27T07:12:12.457264Z",
"shell.execute_reply": "2023-10-27T07:12:12.455781Z",
"shell.execute_reply.started": "2023-10-27T07:12:12.444370Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['18610346996', '15689048244', '17865910365', '15966972231', '15953353009', '10002268211', '13906430187', '18553352007', '15092304241', '13953302959', '15966961587', '13964419753', '13563031324', '13869301368', '15964480260', '17616402467', '18253372927', '15169322152', '18653360448', '15954798900', '15953329509', '13561616627', '13581038337', '13287083771', '18553317009', '13287888080', '13953398130', '13665330312', '18353398071', '15854858198', '13280681081', '13583315663', '18653359308', '18053370113', '18953363875', '15153328391', '13853328246', '13606433819', '13389690177', '18560316978', '18560316897', '18653307232', '18853386200', '13953318999', '15376796462', '18253301688', '13853346368', '18560317186', '13969319707', '13792162471', '15589361996', '15315223331', '13869320577', '13792166751', '15065872512', '13969392534', '13573392557', '13589563291', '13573349783', '13953350485', '18678200603', '13589537205', '13589537205', '13853357150', '13969308397', '13706432240', '18560317061', '13964391029', '18953343833', '18905332691', '13054890607', '13082715936', '15053312268', '15963301381', '15550301285', '13306436916', '15553312972', '13280682857', '13070619391', '18678109571', '15965521907', '13280632498', '13964466366', '18853366997', '13789896882', '15589388169']\n",
"18610346996\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"filename = 'data/世纪花园人员信息.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
" \n",
"list1 = []\n",
"list2 = []\n",
"for k, v in dict1.items():\n",
" list2.append(v['phone'])\n",
"print(list2)\n",
"\n",
"filename = 'data/Survey_20231027.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",
" phone = str(line[2])\n",
" if phone in list2:\n",
" print(phone)\n"
]
},
{
"cell_type": "markdown",
"id": "3e5b5d43-c883-4e41-80b6-dd80bdbfcbfa",
"metadata": {},
"source": [
"## 问卷导出"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "fbe793e4-04cf-4e7d-8fb8-1776ed474ab9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-27T07:25:48.897659Z",
"iopub.status.busy": "2023-10-27T07:25:48.897196Z",
"iopub.status.idle": "2023-10-27T07:25:49.038895Z",
"shell.execute_reply": "2023-10-27T07:25:49.038112Z",
"shell.execute_reply.started": "2023-10-27T07:25:48.897615Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('ptv_0533_sjhy','13070619391','{\"Gender\":\"f\",\"Age\":\"O\",\"q1O\":4,\"q2O\":4,\"q3O\":2,\"q4O\":3,\"q5O\":1,\"q6O\":1,\"q7O\":1,\"q8O\":5,\"q9O\":2,\"q10O\":1,\"q11O\":1,\"q12O\":1,\"q13O\":4,\"q14O\":5,\"q15O\":5,\"q16O\":5,\"q17O\":5,\"q18O\":5,\"q19O\":4,\"q20O\":4,\"q21O\":5,\"q22O\":5,\"q23O\":5,\"q24O\":5,\"q25O\":2,\"q26O\":4,\"q27O\":2,\"q28O\":2,\"q29O\":4,\"q30O\":2,\"q1\":4,\"q3\":1,\"q4\":2,\"q5\":4,\"q6\":4,\"q8\":1,\"q10\":1,\"q13\":4,\"q14\":4,\"q15\":4,\"q16\":5,\"q17\":5,\"q18\":5,\"q19\":5,\"q20\":5,\"q22\":5,\"q23\":1,\"q25\":5,\"q26\":5,\"q27\":1,\"q28\":1,\"q29\":5,\"q30\":5,\"q31\":1,\"q32\":1,\"q33\":2,\"q34\":5,\"q35\":5,\"q36\":1,\"q37\":1,\"q38\":5,\"q39\":5,\"q40\":1,\"q41\":1,\"q42\":5,\"q43\":1,\"q44\":4,\"q45\":1,\"q46\":1,\"q47\":1,\"q48\":5,\"q49\":5,\"q50\":5,\"q51\":1,\"q52\":1,\"q53\":5,\"q54\":5,\"q55\":5,\"q56\":5,\"q57\":5,\"q58\":1,\"q59\":1,\"q60\":5,\"qv1\":1,\"qv2\":1,\"qv3\":1,\"qv4\":2,\"qv5\":1,\"qv6\":1,\"qv7\":2,\"qv8\":1,\"qv9\":2,\"qv10\":1,\"qv11\":1,\"qv12\":1,\"qv13\":2,\"qv14\":2,\"qv15\":1,\"qv16\":1,\"qv17\":1,\"qv18\":1,\"qv19\":1,\"qv20\":2,\"qv21\":1,\"qv22\":2,\"qv23\":2,\"qv24\":1,\"qv25\":1,\"qv26\":2}','2023-10-27 15:00:00'),('ptv_0533_sjhy','13280682857','{\"Gender\":\"f\",\"Age\":\"O\",\"q1O\":2,\"q2O\":2,\"q3O\":2,\"q4O\":1,\"q5O\":4,\"q6O\":4,\"q7O\":4,\"q8O\":4,\"q9O\":4,\"q10O\":1,\"q11O\":3,\"q12O\":5,\"q13O\":4,\"q14O\":4,\"q15O\":4,\"q16O\":5,\"q17O\":4,\"q18O\":4,\"q19O\":4,\"q20O\":3,\"q21O\":5,\"q22O\":5,\"q23O\":5,\"q24O\":5,\"q25O\":3,\"q26O\":4,\"q27O\":4,\"q28O\":4,\"q29O\":3,\"q30O\":4,\"q1\":4,\"q3\":1,\"q4\":3,\"q5\":3,\"q6\":4,\"q8\":2,\"q10\":1,\"q13\":3,\"q14\":1,\"q15\":2,\"q16\":4,\"q17\":3,\"q18\":4,\"q19\":1,\"q20\":1,\"q22\":2,\"q23\":2,\"q25\":1,\"q26\":1,\"q27\":1,\"q28\":3,\"q29\":1,\"q30\":1,\"q31\":3,\"q32\":1,\"q33\":1,\"q34\":1,\"q35\":4,\"q36\":3,\"q37\":1,\"q38\":2,\"q39\":5,\"q40\":1,\"q41\":1,\"q42\":1,\"q43\":1,\"q44\":3,\"q45\":1,\"q46\":1,\"q47\":1,\"q48\":1,\"q49\":2,\"q50\":1,\"q51\":1,\"q52\":1,\"q53\":1,\"q54\":2,\"q55\":1,\"q56\":1,\"q57\":1,\"q58\":1,\"q59\":1,\"q60\":1,\"qv1\":2,\"qv2\":2,\"qv3\":2,\"qv4\":1,\"qv5\":2,\"qv6\":2,\"qv7\":2,\"qv8\":2,\"qv9\":2,\"qv10\":2,\"qv11\":2,\"qv12\":2,\"qv13\":2,\"qv14\":2,\"qv15\":1,\"qv16\":1,\"qv17\":2,\"qv18\":1,\"qv19\":2,\"qv20\":2,\"qv21\":1,\"qv22\":2,\"qv23\":2,\"qv24\":2,\"qv25\":2,\"qv26\":2}','2023-10-27 15:00:00'),('ptv_0533_sjhy','13589537205','{\"Gender\":\"f\",\"Age\":\"O\",\"q1O\":3,\"q2O\":5,\"q3O\":2,\"q4O\":1,\"q5O\":5,\"q6O\":5,\"q7O\":5,\"q8O\":5,\"q9O\":5,\"q10O\":1,\"q11O\":4,\"q12O\":5,\"q13O\":5,\"q14O\":5,\"q15O\":5,\"q16O\":5,\"q17O\":5,\"q18O\":5,\"q19O\":5,\"q20O\":5,\"q21O\":5,\"q22O\":5,\"q23O\":5,\"q24O\":5,\"q25O\":4,\"q26O\":5,\"q27O\":4,\"q28O\":3,\"q29O\":5,\"q30O\":4,\"q1\":4,\"q3\":2,\"q4\":2,\"q5\":1,\"q6\":4,\"q8\":1,\"q10\":1,\"q13\":3,\"q14\":4,\"q15\":1,\"q16\":1,\"q17\":3,\"q18\":2,\"q19\":1,\"q20\":3,\"q22\":5,\"q23\":5,\"q25\":3,\"q26\":1,\"q27\":3,\"q28\":1,\"q29\":1,\"q30\":5,\"q31\":1,\"q32\":3,\"q33\":5,\"q34\":2,\"q35\":2,\"q36\":1,\"q37\":1,\"q38\":5,\"q39\":5,\"q40\":5,\"q41\":1,\"q42\":1,\"q43\":1,\"q44\":3,\"q45\":5,\"q46\":1,\"q47\":3,\"q48\":1,\"q49\":1,\"q50\":1,\"q51\":1,\"q52\":1,\"q53\":1,\"q54\":2,\"q55\":1,\"q56\":1,\"q57\":1,\"q58\":1,\"q59\":1,\"q60\":1,\"qv1\":1,\"qv2\":1,\"qv3\":2,\"qv4\":2,\"qv5\":2,\"qv6\":2,\"qv7\":1,\"qv8\":1,\"qv9\":2,\"qv10\":2,\"qv11\":2,\"qv12\":2,\"qv13\":2,\"qv14\":2,\"qv15\":2,\"qv16\":2,\"qv17\":2,\"qv18\":1,\"qv19\":1,\"qv20\":2,\"qv21\":1,\"qv22\":2,\"qv23\":2,\"qv24\":2,\"qv25\":2,\"qv26\":2}','2023-10-27 15:00:00'),('ptv_0533_sjhy','13573392557','{\"Gender\":\"f\",\"Age\":\"O\",\"q1O\":5,\"q2O\":5,\"q3O\":5,\"q4O\":5,\"q5O\":5,\"q6O\":5,\"q7O\":5,\"q8O\":2,\"q9O\":5,\"q10O\":1,\"q11O\":5,\"q12O\":5,\"q13O\":5,\"q14O\":5,\"q15O\":5,\"q16O\":5,\"q17O\":5,\"q18O\":5,\"q19O\":5,\"q20O\":5,\"q21O\":5,\"q22O\":5,\"q23O\":5,\"q24O\":5,\"q25O\":3,\"q26O\":5,\"q27O\":2,\"q28O\":5,\"q29O\":3,\"q30O\":3,\"q1\":1,\"q3\":3,\"q4\":1,\"q5\":5,\"q6\":4,\"q8\":5,\"q10\":5,\"q13\":3,\"q14\":2,\"q15\":1,\"q16\":1,\"q17\":4,\"q18\":5,\"q19\":5,\"q20\":5,\"q22\":5,\"q23\":3,\"q25\":2,\"q26\":4,\"q27\":5,\"q28\":5,\"q29\":5,\"q30\":4,\"q31\":1,\"q32\":1,\"q33\":1,\"q34\":1,\"q35\":3,\"q36\":1,\"q37\":1,\"q38\":3,\"q39\":4,\"q40\":5,\"q41\":1,\"q42\":1,\"q43\":2,\"q44\":1,\"q45\":3,\"q46\":1,\"q47\":3,\"q48\":3,\"q49\":2,\"q50\":4,\"q51\":1,\"q52\":4,\"q53\":1,\"q54\":3,\"q55\":3,\"q56\":1,\"q57\":5,\"q58\":3,\"q59\":1,\"q60\":5,\"qv1\":1,\"qv2\":1,\"qv3\":2,\"qv4\":2,\"qv5\":1,\"qv6\":2,\"qv7\":2,\"qv8\":2,\"qv9\":1,\"qv10\":2,\"qv11\":1,\"qv12\":1,\"qv13\":1,\"qv14\":2,\"qv15\":1,\"qv16\":1,\"qv17\":2,\"qv18\":2,\"qv19\":2,\"qv20\":1,\"qv21\":1,\"qv22\":2,\"qv23\":2,\"qv24\":2,\"qv25\":2,\"qv26\":2}','2023-10-27 15:00:00'),('ptv_0533_sjhy','15954798900','{\"Gender\":\"f\",\"Age\":\"O\",\"q1O\":3,\"q2O\":2,\"q3O\":2,\"q4O\":2,\"q5O\":5,\"q6O\":5,\"q7O\":5,\"q8O\":4,\"q9Line truncated
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"filename = 'data/世纪花园人员信息.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",
"zy = [2,7,9,11,12,21,24]\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'] =='男':\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)]['phone'] \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-10-27 15:00:00'\n",
" s= s+f'(\\'ptv_0533_sjhy\\',\\'{name}\\',\\'{ss}\\',\\'{sj}\\'),'\n",
" #print(dict2)\n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a634c3b-6954-4eff-bc1c-3f5e229bc458",
"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
}
+9 -102
View File
@@ -1427,16 +1427,9 @@
},
{
"cell_type": "code",
"execution_count": 130,
"execution_count": null,
"id": "d554c400-8f2f-4f60-97ba-ab5ace254d6f",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-22T02:55:08.341413Z",
"iopub.status.busy": "2023-11-22T02:55:08.340762Z",
"iopub.status.idle": "2023-11-22T02:55:08.418936Z",
"shell.execute_reply": "2023-11-22T02:55:08.417041Z",
"shell.execute_reply.started": "2023-11-22T02:55:08.341353Z"
},
"tags": []
},
"outputs": [],
@@ -1493,28 +1486,12 @@
},
{
"cell_type": "code",
"execution_count": 122,
"execution_count": null,
"id": "f21b1c8d-1b2d-45f6-8f35-4a62d5b944f7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-22T02:46:15.092874Z",
"iopub.status.busy": "2023-11-22T02:46:15.092396Z",
"iopub.status.idle": "2023-11-22T02:46:15.175664Z",
"shell.execute_reply": "2023-11-22T02:46:15.174984Z",
"shell.execute_reply.started": "2023-11-22T02:46:15.092847Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"697\n",
"697\n"
]
}
],
"outputs": [],
"source": [
"import json\n",
"import datetime\n",
@@ -1606,27 +1583,12 @@
},
{
"cell_type": "code",
"execution_count": 123,
"execution_count": null,
"id": "9ca97d8f-6320-48f1-9a16-2d34167dac19",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-22T02:46:23.851352Z",
"iopub.status.busy": "2023-11-22T02:46:23.850893Z",
"iopub.status.idle": "2023-11-22T02:46:23.961867Z",
"shell.execute_reply": "2023-11-22T02:46:23.961246Z",
"shell.execute_reply.started": "2023-11-22T02:46:23.851325Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"outputs": [],
"source": [
"import json\n",
"import time\n",
@@ -1762,27 +1724,12 @@
},
{
"cell_type": "code",
"execution_count": 132,
"execution_count": null,
"id": "f0608de5-07ae-458c-999e-60968314f058",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-22T03:00:59.351223Z",
"iopub.status.busy": "2023-11-22T03:00:59.350945Z",
"iopub.status.idle": "2023-11-22T03:00:59.703401Z",
"shell.execute_reply": "2023-11-22T03:00:59.702798Z",
"shell.execute_reply.started": "2023-11-22T03:00:59.351200Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
@@ -1848,52 +1795,12 @@
},
{
"cell_type": "code",
"execution_count": 134,
"execution_count": null,
"id": "2c867c7f-00b4-4a41-a6eb-18d6c39fa4cc",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-22T03:28:56.932672Z",
"iopub.status.busy": "2023-11-22T03:28:56.932375Z",
"iopub.status.idle": "2023-11-22T03:28:56.981535Z",
"shell.execute_reply": "2023-11-22T03:28:56.980516Z",
"shell.execute_reply.started": "2023-11-22T03:28:56.932646Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"18777937356\n",
"13768090960\n",
"18977916950\n",
"18277917797\n",
"18092434264\n",
"13977982222\n",
"13877944139\n",
"13517796512\n",
"13977933993\n",
"15613726645\n",
"13877935443\n",
"13768091811\n",
"13877923030\n",
"18092434264\n",
"18992865291\n",
"15577993102\n",
"18277917797\n",
"13977990782\n",
"18177980276\n",
"15224521321\n",
"18822081130\n",
"13807898246\n",
"18277917797\n",
"13768091811\n",
"13517790009\n",
"15143256015\n"
]
}
],
"outputs": [],
"source": [
"import json\n",
"import csv\n",