973 lines
29 KiB
Plaintext
973 lines
29 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4c74893b-fca2-45f8-8254-2060886909ec",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 人员信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e5472692-ffc3-442f-9b84-170619215148",
|
|
"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",
|
|
" code = int(sheet.cell(n, 1).value)\n",
|
|
" person.setdefault(code, {})\n",
|
|
" dict1 = {}\n",
|
|
" dict1['name'] = sheet.cell(n, 2).value \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['门牌号e'] = sheet.cell(n,6).value\n",
|
|
" \n",
|
|
" person[code] = 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": "0dc90cf8-0a51-49ab-8f93-81acfd359e63",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取人员测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "693820f4-f79d-4e6b-9901-0aae57bc6c92",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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_20231103.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",
|
|
" \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[8]\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": "8b6cffa9-bd17-431e-a0b1-5004d4cf4726",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "15b3ca3b-ec36-4d1d-bbaf-040fed6e2687",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"#title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"\n",
|
|
"filename = 'data/result_积家.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"filename = 'data/积家人员信息.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
" \n",
|
|
"list1 = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" list2 = []\n",
|
|
" list2.append(str(k).rjust(5,'0'))\n",
|
|
" list2.append(v['name']) \n",
|
|
" list2.append(v['rq']) \n",
|
|
" list2.append(v['sex'])\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)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2d417d9a-ca85-4c9f-8673-11f5f1033d1f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算项目成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9230c78a-40d1-47ed-9bfc-94525b44f8f9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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": null,
|
|
"id": "c42bb7f4-ae16-4950-8fc9-97e7084e4615",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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",
|
|
"\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",
|
|
"print(dict1)\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'] = psy_yangmiao_old\n",
|
|
" #dict2[str(k)]['psy_yangmiao_old'] = psy_yangmiao_old\n",
|
|
" if v[30] is not None:\n",
|
|
" tcm = v[30:90]\n",
|
|
" dict2[str(k)]['tcm'] = tcm\n",
|
|
" #print(tcm,len(tcm))\n",
|
|
" if v[90] is not None:\n",
|
|
" spine = v[90:116]\n",
|
|
" xx22 = spine[21]\n",
|
|
" xx23 = spine[22]\n",
|
|
" spine[21] = xx23\n",
|
|
" spine[22] = xx22\n",
|
|
" dict2[str(k)]['spine'] = spine\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_积家1.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": "c4ba35f4-1591-4f8e-8c19-8ff9bf918748",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "8ff5f29b-f2cd-4b2f-9716-8ec6bd77db1f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成报告人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6038af14-e3cf-4e79-9a02-a5d70cb2ed65",
|
|
"metadata": {
|
|
"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": null,
|
|
"id": "096672ef-c1f1-4b31-a490-efd408b95aec",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/Survey_20240801.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": "code",
|
|
"execution_count": 17,
|
|
"id": "a51a346c-8a3a-425c-be76-940f11c2e1ab",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-08-11T11:10:50.265674Z",
|
|
"iopub.status.busy": "2024-08-11T11:10:50.265079Z",
|
|
"iopub.status.idle": "2024-08-11T11:10:50.339113Z",
|
|
"shell.execute_reply": "2024-08-11T11:10:50.338550Z",
|
|
"shell.execute_reply.started": "2024-08-11T11:10:50.265618Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"38\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/Survey_20240801.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",
|
|
"dict1 = {}\n",
|
|
"bh = 1\n",
|
|
"for item in list1:\n",
|
|
" phone = item[2]\n",
|
|
" content = json.loads(item[5])\n",
|
|
" name = content['name']\n",
|
|
" sex = content['Gender']\n",
|
|
" age = content['Age']\n",
|
|
" del content['name']\n",
|
|
" del content['Gender']\n",
|
|
" del content['Age']\n",
|
|
" for k, v in content.items():\n",
|
|
" if 'O' in k:\n",
|
|
" psy =[]\n",
|
|
" for i in range(1,31):\n",
|
|
" m_key = 'q'+str(i)+'O'\n",
|
|
" psy.append(content[m_key])\n",
|
|
" elif 'M' in k:\n",
|
|
" psy =[]\n",
|
|
" for i in range(1,48):\n",
|
|
" m_key = 'q'+str(i)+'M'\n",
|
|
" psy.append(content[m_key])\n",
|
|
" elif 'qv' in k:\n",
|
|
" spine =[]\n",
|
|
" for i in range(1,27):\n",
|
|
" m_key = 'qv'+str(i)\n",
|
|
" if m_key in content.keys():\n",
|
|
" spine.append(content[m_key])\n",
|
|
" else:\n",
|
|
" spine.append(0)\n",
|
|
" \n",
|
|
" else:\n",
|
|
" tcm = []\n",
|
|
" for i in range(1,61):\n",
|
|
" m_key = 'q'+str(i)\n",
|
|
" if m_key in content.keys():\n",
|
|
" tcm.append(content[m_key])\n",
|
|
" else:\n",
|
|
" tcm.append(0)\n",
|
|
" dict1.setdefault(bh,{})\n",
|
|
" #print(spine)\n",
|
|
" dict1[bh]['name'] = name\n",
|
|
" dict1[bh]['sex'] = sex\n",
|
|
" dict1[bh]['age'] = age\n",
|
|
" dict1[bh]['phone'] = phone\n",
|
|
" dict1[bh]['psy'] = psy\n",
|
|
" dict1[bh]['tcm'] = tcm\n",
|
|
" dict1[bh]['spine'] = spine\n",
|
|
" bh += 1 \n",
|
|
" #list3.append(list2)\n",
|
|
"filename = 'data/积家基础数据240811.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ca5240cb-4ae1-4c40-ad7a-40b620dcf072",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 清理无手机号码人员"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"id": "8a339d2f-0869-45c8-93e6-79bd6ed0e86f",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-08-11T11:22:06.868752Z",
|
|
"iopub.status.busy": "2024-08-11T11:22:06.868034Z",
|
|
"iopub.status.idle": "2024-08-11T11:22:06.881380Z",
|
|
"shell.execute_reply": "2024-08-11T11:22:06.880194Z",
|
|
"shell.execute_reply.started": "2024-08-11T11:22:06.868690Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"3\n",
|
|
"5\n",
|
|
"6\n",
|
|
"8\n",
|
|
"10\n",
|
|
"11\n",
|
|
"13\n",
|
|
"14\n",
|
|
"15\n",
|
|
"19\n",
|
|
"20\n",
|
|
"21\n",
|
|
"22\n",
|
|
"23\n",
|
|
"24\n",
|
|
"25\n",
|
|
"26\n",
|
|
"27\n",
|
|
"30\n",
|
|
"38\n",
|
|
"38\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"filename = 'data/积家基础数据240811.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" if v['phone'] =='18801062497':\n",
|
|
" del v['phone']\n",
|
|
" print(k)\n",
|
|
"filename = 'data/积家基础数据2408.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5ab7d644-c90a-4877-9abf-6d4bd88ef3ef",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入问卷人员信息(无姓名)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8f801647-a326-4bf1-a651-4b52e0296998",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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": null,
|
|
"id": "fbe793e4-04cf-4e7d-8fb8-1776ed474ab9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"import chardet\n",
|
|
"\n",
|
|
"filename = 'data/积家人员信息.json'\n",
|
|
"with open(filename,'r',encoding='utf8') 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)]['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-11-10 12:00:00'\n",
|
|
" \n",
|
|
" \n",
|
|
" s= s+f'(\\'ptv_0533_jj\\',\\'{name}\\',\\'{int(k)}\\',\\'{ss}\\',\\'{sj}\\'),'\n",
|
|
" #print(dict2)\n",
|
|
"print(s)\n",
|
|
"print (chardet.detect(str.encode(s)))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "58417d26-1d6c-4583-ac35-3469fa6b85fd",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 读取读卡系统人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "08e9afb8-a68b-4199-9020-67bc7cd1bd0a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b38517cd-268c-4e80-a4f1-002bf45d81f0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/积家data(1).json'\n",
|
|
"with open(filename,'r',encoding='utf8') as fl:\n",
|
|
" list1 = json.load(fl)\n",
|
|
"i = 1\n",
|
|
"for item in list1:\n",
|
|
" if item['phone'] !='':\n",
|
|
" print(item['name'],item['phone'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4e201e43-3cb1-4511-bf1b-721fc18275db",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 核对报告人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"id": "f370a41c-4f61-4311-8aa9-95946dca42c7",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-11-26T11:36:23.485942Z",
|
|
"iopub.status.busy": "2023-11-26T11:36:23.485461Z",
|
|
"iopub.status.idle": "2023-11-26T11:36:23.534771Z",
|
|
"shell.execute_reply": "2023-11-26T11:36:23.533403Z",
|
|
"shell.execute_reply.started": "2023-11-26T11:36:23.485898Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import math\n",
|
|
"import glob\n",
|
|
"import random\n",
|
|
"from pathlib import Path\n",
|
|
"\n",
|
|
"filename = 'data/积家data(1).json'\n",
|
|
"with open(filename,'r',encoding='utf8') as fl:\n",
|
|
" list1 = json.load(fl)\n",
|
|
"dict2 = {}\n",
|
|
"for item in list1:\n",
|
|
" code = str(int(item['id']))\n",
|
|
" dict2.setdefault(code,{})\n",
|
|
" dict2[code]= {'name':item['name'],'sex':item['gender'],'birth':item['birth'],'phone':item['phone']}\n",
|
|
"#print(dict2)\n",
|
|
"\n",
|
|
"place_id = 698465\n",
|
|
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
|
|
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
|
|
"i = 1\n",
|
|
"list2 = []\n",
|
|
"for fn in fls:\n",
|
|
" list3 = []\n",
|
|
" fi_name =Path(fn).stem.split('-')[0]\n",
|
|
" code = str(int(fi_name))\n",
|
|
" if code in dict2.keys():\n",
|
|
" list3 = [code,dict2[code]['name'],dict2[code]['sex'],dict2[code]['phone']]\n",
|
|
" list2.append(list3)\n",
|
|
"filename = 'data/积家村报告明细.xlsx'\n",
|
|
"wb = openpyxl.Workbook()\n",
|
|
"sheet = wb.active\n",
|
|
"\n",
|
|
"for row in list2:\n",
|
|
" sheet.append(row)\n",
|
|
"wb.save(filename) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e92098ad-d57b-461b-9ec5-e26d0801ff8d",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成报告信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"id": "f12f5070-005f-42fb-869c-f0b4b18de4ec",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-11-26T11:49:51.275785Z",
|
|
"iopub.status.busy": "2023-11-26T11:49:51.275273Z",
|
|
"iopub.status.idle": "2023-11-26T11:49:51.316526Z",
|
|
"shell.execute_reply": "2023-11-26T11:49:51.315347Z",
|
|
"shell.execute_reply.started": "2023-11-26T11:49:51.275718Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"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",
|
|
" code = int(sheet.cell(n, 1).value)\n",
|
|
" person.setdefault(code, {})\n",
|
|
" dict1 = {}\n",
|
|
" dict1['name'] = sheet.cell(n, 2).value \n",
|
|
" dict1['sex'] = sheet.cell(n, 3).value \n",
|
|
" if sheet.cell(n,4).value is not None:\n",
|
|
" dict1['phone'] = sheet.cell(n,4).value\n",
|
|
" \n",
|
|
" person[code] = 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": "code",
|
|
"execution_count": null,
|
|
"id": "e80a1efa-9b54-416d-a7e2-fc4ced0adada",
|
|
"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.12.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|