864 lines
28 KiB
Plaintext
864 lines
28 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0deffb8b-6ff0-4a87-b733-08dde1494994",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 杨庙人员信息导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "c4bd7851-d612-4387-a8b2-5173eac8f866",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙社区居民信息表20230801(系统导入版).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",
|
||
" dict1['sex'] = sheet.cell(n, 3).value\n",
|
||
" birth = str(sheet.cell(n, 4).value).split()[0]\n",
|
||
" dict1['birth'] = birth \n",
|
||
" person[code] = dict1\n",
|
||
"\n",
|
||
"filename = 'data/杨庙社区人员信息2307.json'\n",
|
||
"with open(filename, 'w') as fl:\n",
|
||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "fc2c5182-e10c-45eb-841d-d6083ddfde53",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 检测问卷编号重复"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "b8eff79b-3c8c-45e3-8127-6e863008ad4a",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙社区人员信息2307.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",
|
||
"list1 = []\n",
|
||
"for item in list_bh:\n",
|
||
" if item not in list1:\n",
|
||
" list1.append(item)\n",
|
||
" else:\n",
|
||
" print(item)\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "26d77f4b-6ba1-45b3-8955-9ae481b9ae9c",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入手工体测数据"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ccfac27a-b255-4263-9ce0-c606d82f6473",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙社区人员信息2307.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 = {1:10,2:11,3:7,4:2,5:6,6:3,7:1}\n",
|
||
"sheet = wb.active\n",
|
||
"data1 =list(sheet.values)\n",
|
||
"del data1[0]\n",
|
||
"list1 = []\n",
|
||
"for item in data1:\n",
|
||
" code = item[0]\n",
|
||
" if str(code) in dict2.keys():\n",
|
||
" for i in range(1,8):\n",
|
||
" if item[i] is not None:\n",
|
||
" list1.append((141,code,dict3[i],item[i],'2023-08-03','2023-08-03 12:00:00'))\n",
|
||
"print(list1)\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "e4bbd0db-090b-4252-ae27-d9e589f97992",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导出体测信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e77ef529-0522-4f8d-a4d3-9f62a69f6cc6",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import datetime\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",
|
||
"item['1']['en'] = 'lung'\n",
|
||
"item['2']['en'] = 'grip'\n",
|
||
"item['3']['en'] = 'flexion'\n",
|
||
"item['6']['en'] = 'balance'\n",
|
||
"item['7']['en'] = 'reaction'\n",
|
||
"item['10']['en'] = 'height'\n",
|
||
"item['11']['en'] = 'weight'\n",
|
||
"#print(item)\n",
|
||
"re_ta = {}\n",
|
||
"dict1 = {}\n",
|
||
"list1 = []\n",
|
||
"filename = 'data/杨庙社区人员信息2307.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20230803.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",
|
||
"for result in list1:\n",
|
||
" user = str(result[2])\n",
|
||
" if user in dict1.keys(): \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",
|
||
" re_ta[user]['birth'] = dict1[user]['birth']\n",
|
||
" item_name = item[str(m_item)]['en']\n",
|
||
" re_ta[user].setdefault(item_name,{}) \n",
|
||
" performance = int(result[4])/item[m_item]['divisor']\n",
|
||
" score = result[5]\n",
|
||
" re_ta[user][item_name]['成绩'] = performance\n",
|
||
" re_ta[user][item_name]['得分'] = score\n",
|
||
"list2 = ['grip','lung','balance','reaction','flexion']\n",
|
||
"list3 = []\n",
|
||
"for k, v in re_ta.items():\n",
|
||
" dict2 = {}\n",
|
||
" dict2['id'] = int(k)\n",
|
||
" dict2['title'] = '杨庙社区'\n",
|
||
" dict2['subtitle'] = ''\n",
|
||
" dict2['name'] = v['name']\n",
|
||
" if v['sex'] == '男':\n",
|
||
" dict2['gender'] = 'male'\n",
|
||
" else:\n",
|
||
" dict2['gender'] = 'female'\n",
|
||
" birth = v['birth'].split()[0].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, 7, 31)-datetime.date(nian,yue,ri)).days\n",
|
||
" dict2['month'] = int(days/30)\n",
|
||
" dict3 = {} \n",
|
||
" for xm in list2:\n",
|
||
" if xm in v.keys():\n",
|
||
" dict3[xm] = {'mark':str(v[xm]['成绩']),'score':int(v[xm]['得分'])}\n",
|
||
" if 'height' in v.keys():\n",
|
||
" dict3['bmi'] = {'mark':str(v['height']['成绩'])+','+str(v['weight']['成绩']),'score':int(v['weight']['得分'])}\n",
|
||
" dict2['fit'] = dict3\n",
|
||
" list3.append(dict2)\n",
|
||
"print(list3) \n",
|
||
" \n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "e81e3731-1376-4f9d-87fb-83ba1e498047",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import datetime\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",
|
||
"item['1']['en'] = 'lung'\n",
|
||
"item['2']['en'] = 'grip'\n",
|
||
"item['3']['en'] = 'flexion'\n",
|
||
"item['6']['en'] = 'balance'\n",
|
||
"item['7']['en'] = 'reaction'\n",
|
||
"item['10']['en'] = 'height'\n",
|
||
"item['11']['en'] = 'weight'\n",
|
||
"#print(item)\n",
|
||
"re_ta = {}\n",
|
||
"dict1 = {}\n",
|
||
"list1 = []\n",
|
||
"filename = 'data/杨庙社区人员信息2307.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20230803.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",
|
||
"for result in list1:\n",
|
||
" user = str(result[2])\n",
|
||
" if user in dict1.keys(): \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",
|
||
" re_ta[user]['birth'] = dict1[user]['birth']\n",
|
||
" item_name = item[str(m_item)]['en']\n",
|
||
" re_ta[user].setdefault(item_name,{}) \n",
|
||
" performance = int(result[4])/item[m_item]['divisor']\n",
|
||
" score = result[5]\n",
|
||
" re_ta[user][item_name]['成绩'] = performance\n",
|
||
" re_ta[user][item_name]['得分'] = score\n",
|
||
"list2 = ['grip','lung','balance','reaction','flexion']\n",
|
||
"list3 = []\n",
|
||
"result = {}\n",
|
||
"for k, v in re_ta.items():\n",
|
||
" dict2 = {}\n",
|
||
" dict2['id'] = int(k)\n",
|
||
" dict2['title'] = '杨庙社区'\n",
|
||
" dict2['subtitle'] = ''\n",
|
||
" dict2['name'] = v['name']\n",
|
||
" if v['sex'] == '男':\n",
|
||
" dict2['gender'] = 'male'\n",
|
||
" else:\n",
|
||
" dict2['gender'] = 'female'\n",
|
||
" birth = v['birth'].split()[0].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, 7, 31)-datetime.date(nian,yue,ri)).days\n",
|
||
" dict2['month'] = int(days/30)\n",
|
||
" dict3 = {} \n",
|
||
" for xm in list2:\n",
|
||
" if xm in v.keys():\n",
|
||
" mark = v[xm]['成绩']\n",
|
||
" if xm == 'lung':\n",
|
||
" mark = int(mark)\n",
|
||
" \n",
|
||
" dict3[xm] = {'mark':str(mark),'score':int(v[xm]['得分'])}\n",
|
||
" if 'height' in v.keys():\n",
|
||
" dict3['bmi'] = {'mark':str(v['height']['成绩'])+','+str(v['weight']['成绩']),'score':int(v['weight']['得分'])}\n",
|
||
" dict2['fit'] = dict3\n",
|
||
" result[k] = dict2\n",
|
||
"\n",
|
||
"filename = 'data/result_杨庙230801.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(result, fl) \n",
|
||
"print('ok') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0c6da346-3406-40ad-a44a-0a47c0d6112a",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 规范身高体重"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "a814c55f-30af-4260-8885-3a6295a48fd7",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for k, v in dict1.items():\n",
|
||
" if 'bmi' in v['fit'].keys():\n",
|
||
" old = v['fit']['bmi']['mark']\n",
|
||
" height = old.split(',')[0]\n",
|
||
" weight = old.split(',')[1]\n",
|
||
" w = round(float(weight),1)\n",
|
||
" v['fit']['bmi']['mark'] = height+','+str(w)\n",
|
||
"filename = 'data/result_杨庙230801.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
||
"print('ok') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "1ddd3641-94bf-4994-84da-8d97286cbfeb",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 问卷信息导入"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "1c56c463-2f13-4f74-bb3a-760b284360bf",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl\n",
|
||
"import json\n",
|
||
"\n",
|
||
"filename = 'data/杨庙社区人员信息2307.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_杨庙2308.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_yangmiao_old'] = psy_yangmiao_old\n",
|
||
" dict2[str(k)]['tcm'] = tcm\n",
|
||
" dict2[str(k)]['spine'] = spine\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(dict2, fl, ensure_ascii=False) \n",
|
||
"print('ok') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "77995e6a-86e4-49bb-a937-de38e13f1bd4",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 单份报告生成"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "edcd9c2d-7254-493d-82e0-55556700330b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-08-16T08:53:29.466349Z",
|
||
"iopub.status.busy": "2023-08-16T08:53:29.465563Z",
|
||
"iopub.status.idle": "2023-08-16T08:53:30.567398Z",
|
||
"shell.execute_reply": "2023-08-16T08:53:30.566465Z",
|
||
"shell.execute_reply.started": "2023-08-16T08:53:29.466307Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"<class 'str'>\n",
|
||
"{\"errmsg\":\"ok\"}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import requests\n",
|
||
"import json\n",
|
||
"\n",
|
||
"headers = {\n",
|
||
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
||
" }\n",
|
||
"\n",
|
||
"mydata ={\"path\":\"./于先生体测报告.pdf\",\n",
|
||
" \"id\":\"00001\",\n",
|
||
" \"title\":\"社区测试报告\",\n",
|
||
" \"name\":\"于先生\",\n",
|
||
" \"gender\":\"male\",\n",
|
||
" \"month\":725,\n",
|
||
" \"fit\":{\"grip\":{\"mark\":\"40.9\",\"score\":2},\n",
|
||
" \"bmi\":{\"mark\":\"181.2,81.3\",\"score\":5},\n",
|
||
" \"lung\":{\"mark\":\"4590\",\"score\":5},\n",
|
||
" \"balance\":{\"mark\":\"57.2\",\"score\":4},\n",
|
||
" \"reaction\":{\"mark\":\"0.466\",\"score\":4},\n",
|
||
" \"flexion\":{\"mark\":\"-11.6\",\"score\":0},\n",
|
||
" \"jump\":{\"mark\":\"26.3\",\"score\":2},\n",
|
||
" \"pushup\":{\"mark\":\"3\",\"score\":1},\n",
|
||
" \"step\":{\"mark\":\"43\",\"score\":1}\n",
|
||
" },\n",
|
||
" \"surveys\":{\"tcm\":[3,3,3,2,2,3,1,3,3,1,1,2,3,4,1,1,2,3,4,1,2,4,2,2,4,5,5,3,1,3,3,2,3,4,3,3,2,3,3,3,3,2,4,3,5,2,3,3,2,1,3,4,3,3,3,3,1,1,2,3],\"psy_yangmiao_old\":[3,3,2,3,3,3,4,4,4,1,4,4,4,4,5,5,5,3,4,3,3,4,4,3,4,4,3,4,3,3],\"spine\":[1,2,1,2,1,2,2,1,2,2,1,2,2,2,1,1,1,1,1,2,2,2,2,2,1,2]}}\n",
|
||
"print(type(json.dumps(mydata)))\n",
|
||
"x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n",
|
||
"print(x.text)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "0b528b37-18f5-4b05-bfad-73be35b120cc",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-08-26T01:22:01.984551Z",
|
||
"iopub.status.busy": "2023-08-26T01:22:01.983645Z",
|
||
"iopub.status.idle": "2023-08-26T01:22:02.822718Z",
|
||
"shell.execute_reply": "2023-08-26T01:22:02.821896Z",
|
||
"shell.execute_reply.started": "2023-08-26T01:22:01.984511Z"
|
||
}
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"<class 'str'>\n",
|
||
"{\"errmsg\":\"ok\"}\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import requests\n",
|
||
"import json\n",
|
||
"\n",
|
||
"headers = {\n",
|
||
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
||
" }\n",
|
||
"\n",
|
||
"mydata ={\"path\":\"./00343-殷焕章.pdf\",\n",
|
||
" \"id\":\"00343\",\n",
|
||
" \"title\":\"东营羊庙社区\",\n",
|
||
" \"name\":\"殷焕章\",\n",
|
||
" \"gender\":\"male\",\n",
|
||
" \"month\":992,\n",
|
||
" \"fit\":{\"grip\":{\"mark\":\"20.6\",\"score\":0},\n",
|
||
" \"bmi\":{\"mark\":\"160.4,60.0\",\"score\":5},\n",
|
||
" \"lung\":{\"mark\":\"1703\",\"score\":1},\n",
|
||
" \"balance\":{\"mark\":\"3.9\",\"score\":2},\n",
|
||
" \"reaction\":{\"mark\":\"1.519\",\"score\":0},\n",
|
||
" \"flexion\":{\"mark\":\"8.9\",\"score\":4}\n",
|
||
" }\n",
|
||
" }\n",
|
||
"print(type(json.dumps(mydata)))\n",
|
||
"x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n",
|
||
"print(x.text)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "27068dd5-8312-45c3-bbff-9f21646e895b",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 报告生成"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "7ad7eb19-d49d-4f28-b7f7-4776bf443946",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import requests\n",
|
||
"import json\n",
|
||
"\n",
|
||
"headers = {\n",
|
||
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
||
" }\n",
|
||
"filename = 'data/result_杨庙230801.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"fiie_path ='./141/'\n",
|
||
"dict2 = {}\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" mydata = {}\n",
|
||
" \n",
|
||
" id = str(k).rjust(5,\"0\")\n",
|
||
" mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n",
|
||
" mydata['title'] = '东营杨庙社区'\n",
|
||
" mydata['id'] = id\n",
|
||
" mydata['name'] = v['name']\n",
|
||
" mydata['gender'] = v['gender'] \n",
|
||
" mydata['month'] = v['month']\n",
|
||
" if 'fit' in v.keys():\n",
|
||
" dict2 = {}\n",
|
||
" for k1, v1 in v['fit'].items():\n",
|
||
" dict2[k1] = v1\n",
|
||
" mydata['fit'] = dict2\n",
|
||
" #data['surveys'] = {}\n",
|
||
" for item in ('tcm','psy_yangmiao_old','spine'):\n",
|
||
" if item in v.keys():\n",
|
||
" mydata.setdefault('surveys',{})\n",
|
||
" dict2 = {} \n",
|
||
" mydata['surveys'][item] = v[item]\n",
|
||
" list1.append(mydata) \n",
|
||
" #x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n",
|
||
" #print(id,v['name'],x.text)\n",
|
||
" #x.close()\n",
|
||
" #if k =='218':\n",
|
||
" # print(mydata)\n",
|
||
"json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n",
|
||
"\n",
|
||
"# 将 json 数据写入文件\n",
|
||
"with open(\"data1.json\", \"w\",encoding = 'utf-8') as file:\n",
|
||
" file.write(json_data) \n",
|
||
" \n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "6a01e1b1-778b-4dc8-99e5-f597f10f30a1",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import requests\n",
|
||
"import json\n",
|
||
"import time\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"headers = {\n",
|
||
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
||
" }\n",
|
||
"filename = 'data/result_杨庙230801.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"file_path ='/home/songyi/pdf-typescript-master/141/'\n",
|
||
"dict2 = {}\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" id = str(k).rjust(5,\"0\")\n",
|
||
" fn = file_path+id+'-'+ v['name']+'.pdf'\n",
|
||
" \n",
|
||
" mydata = {}\n",
|
||
" \n",
|
||
" id = str(k).rjust(5,\"0\")\n",
|
||
" mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n",
|
||
" mydata['title'] = '东营杨庙社区'\n",
|
||
" mydata['id'] = id\n",
|
||
" mydata['name'] = v['name']\n",
|
||
" mydata['gender'] = v['gender'] \n",
|
||
" mydata['month'] = v['month']\n",
|
||
" if 'fit' in v.keys():\n",
|
||
" dict2 = {}\n",
|
||
" for k1, v1 in v['fit'].items():\n",
|
||
" dict2[k1] = v1\n",
|
||
" mydata['fit'] = dict2\n",
|
||
" #data['surveys'] = {}\n",
|
||
" for item in ('tcm','psy_yangmiao_old','spine'):\n",
|
||
" if item in v.keys():\n",
|
||
" mydata.setdefault('surveys',{})\n",
|
||
" dict2 = {} \n",
|
||
" mydata['surveys'][item] = v[item]\n",
|
||
" \n",
|
||
" x = requests.post('http://10.11.12.4:3003', data = json.dumps(mydata), headers=headers)\n",
|
||
" print(id,v['name'],x.text)\n",
|
||
" x.close()\n",
|
||
" time.sleep(0.05)\n",
|
||
" #if k =='218':\n",
|
||
" # print(mydata)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "4e80d173-8cba-46d0-86fd-4c031a649a00",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成报告人员信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "6f69631c-e2d7-431b-8114-c4bb45e394e7",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"filename = 'data/result_杨庙230801.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])\n",
|
||
"filename = 'data/杨庙测试2023年8月报告明细表.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": "aa34d7f2-9b6c-42c8-b777-60cc0c48a3a3",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 统计报告页数"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "ed2f8014-57c7-40d1-979f-f2d4818c748b",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import pdfplumber\n",
|
||
"import glob\n",
|
||
"\n",
|
||
"file_path ='/home/songyi/pdf-typescript-master/141/'\n",
|
||
"fls=glob.glob('/home/songyi/pdf-typescript-master/141/*.pdf')\n",
|
||
"n = 0\n",
|
||
"for fl in fls:\n",
|
||
" pdf = pdfplumber.open(fl)\n",
|
||
" n= n+len(pdf.pages)\n",
|
||
" print(fl,len(pdf.pages))\n",
|
||
"print(n)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "6a867a50-3a97-47c3-8805-0b39b1137173",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 导入202303月体测信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "2bafc0b8-e849-4be7-8438-ba9fd2b87870",
|
||
"metadata": {},
|
||
"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",
|
||
"filename = 'data/杨庙体测明确人员信息(20230328).json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"filename = 'data/places_result_20230812.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",
|
||
"for result in list1:\n",
|
||
" user = str(result[2])\n",
|
||
" if user in dict1.keys():\n",
|
||
" \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",
|
||
" re_ta[user]['部门'] = dict1[user]['unit']\n",
|
||
" item_name = item[m_item]['name']\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",
|
||
" re_ta[user][item_name]['得分'] = result[5]\n",
|
||
"print(len(re_ta))\n",
|
||
"filename = 'data/result_杨庙社区2303.json'\n",
|
||
"with open(filename,'w') as fl:\n",
|
||
" json.dump(re_ta, fl) \n",
|
||
"print('ok')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "761bd7a5-ef80-4fb9-b64e-983c8e788e2c",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 对应两次测试信息"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "c4da3291-ebec-4fc9-aaa0-6ecf836c5ff2",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"dict4 = {\n",
|
||
" 'lung':'肺活量',\n",
|
||
" 'grip':'握力',\n",
|
||
" 'flexion' : '坐位体前屈',\n",
|
||
" 'balance' : '单脚站立',\n",
|
||
" 'reaction' : '选择反应时'\n",
|
||
"}\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/副本杨庙测试2023年8月报告明细表.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"items = ['bmi','lung','grip','flexion','balance','reaction']\n",
|
||
"dict1 = {}\n",
|
||
"for n in range(2, sheet.max_row+1):\n",
|
||
" if sheet.cell(n,1).value is not None:\n",
|
||
" code = str(sheet.cell(n, 1).value) \n",
|
||
" dict1[code] = str(sheet.cell(n, 3).value) \n",
|
||
"filename = 'data/result_杨庙230801.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl) \n",
|
||
"filename = 'data/result_杨庙社区2303.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict3 = json.load(fl) \n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" list2 = []\n",
|
||
" list2.append(k)\n",
|
||
" list2.append(dict2[k]['name'])\n",
|
||
" list2.append(dict2[k]['gender'])\n",
|
||
" list2.append(dict3[dict1[k]]['部门'])\n",
|
||
" for item in items:\n",
|
||
" if item == 'bmi' and item in dict2[k]['fit'].keys():\n",
|
||
" list2.append(dict2[k]['fit'][item]['mark'].split(',')[0])\n",
|
||
" if '身高' in dict3[dict1[k]].keys():\n",
|
||
" list2.append(dict3[dict1[k]]['身高']['成绩'])\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append(dict2[k]['fit'][item]['mark'].split(',')[1])\n",
|
||
" if '体重' in dict3[dict1[k]].keys():\n",
|
||
" list2.append(dict3[dict1[k]]['体重']['成绩'])\n",
|
||
" else:\n",
|
||
" list2.append('')\n",
|
||
" if item != 'bmi' and item in dict2[k]['fit'].keys():\n",
|
||
" list2.append(dict2[k]['fit'][item]['mark'])\n",
|
||
" if dict4[item] in dict3[dict1[k]].keys():\n",
|
||
" list2.append(dict3[dict1[k]][dict4[item]]['成绩'])\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list1.append(list2)\n",
|
||
"print(list1)\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) "
|
||
]
|
||
}
|
||
],
|
||
"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
|
||
}
|