1481 lines
50 KiB
Plaintext
1481 lines
50 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": null,
|
||
"id": "edcd9c2d-7254-493d-82e0-55556700330b",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": null,
|
||
"id": "0b528b37-18f5-4b05-bfad-73be35b120cc",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"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": 47,
|
||
"id": "6f69631c-e2d7-431b-8114-c4bb45e394e7",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-01-18T11:50:16.920972Z",
|
||
"iopub.status.busy": "2024-01-18T11:50:16.920504Z",
|
||
"iopub.status.idle": "2024-01-18T11:50:17.016239Z",
|
||
"shell.execute_reply": "2024-01-18T11:50:17.015740Z",
|
||
"shell.execute_reply.started": "2024-01-18T11:50:16.920935Z"
|
||
}
|
||
},
|
||
"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",
|
||
"filename = 'data/杨庙社区人员信息2307.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict2 = json.load(fl)\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items():\n",
|
||
" id = str(k).rjust(5,\"0\")\n",
|
||
" \n",
|
||
" name = v['name']\n",
|
||
" sex = dict2[k]['sex']\n",
|
||
" birth = dict2[k]['birth']\n",
|
||
" list1.append([id,name,sex,birth])\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": "code",
|
||
"execution_count": null,
|
||
"id": "d46d6331-dc3a-4ed5-b2cd-995e467f8ac0",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "8d2be337-20e9-47e1-a8fa-6a35350b37bb",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
},
|
||
{
|
||
"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) "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "2ae502e4-e8ec-4786-8593-ca8835c0b215",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 分析三月数据"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 26,
|
||
"id": "bc0e659e-b072-4ffc-9a9f-951c61ad22b9",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:12:02.250010Z",
|
||
"iopub.status.busy": "2023-10-10T11:12:02.249552Z",
|
||
"iopub.status.idle": "2023-10-10T11:12:02.315587Z",
|
||
"shell.execute_reply": "2023-10-10T11:12:02.314268Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:12:02.249973Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"体重平均成绩:3.6196分,男性:184人\n",
|
||
"体重平均成绩:3.6765分,女性:204人\n",
|
||
"体重平均成绩:3.6495分,总体:388人\n",
|
||
"肺活量平均成绩:1.8865分,男性:185人\n",
|
||
"肺活量平均成绩:1.7122分,女性:205人\n",
|
||
"肺活量平均成绩:1.7949分,总体:390人\n",
|
||
"握力平均成绩:1.7838分,男性:185人\n",
|
||
"握力平均成绩:1.774分,女性:208人\n",
|
||
"握力平均成绩:1.7786分,总体:393人\n",
|
||
"坐位体前屈平均成绩:2.8764分,男性:178人\n",
|
||
"坐位体前屈平均成绩:2.9424分,女性:191人\n",
|
||
"坐位体前屈平均成绩:2.9106分,总体:369人\n",
|
||
"纵跳平均成绩:0.8421分,男性:57人\n",
|
||
"纵跳平均成绩:0.5513分,女性:78人\n",
|
||
"纵跳平均成绩:0.6741分,总体:135人\n",
|
||
"俯卧撑平均成绩:3.0333分,男性:30人\n",
|
||
"俯卧撑平均成绩:3.0333分,总体:30人\n",
|
||
"一分钟仰卧起坐平均成绩:3.2927分,女性:41人\n",
|
||
"一分钟仰卧起坐平均成绩:3.2927分,总体:41人\n",
|
||
"单脚站立平均成绩:1.6932分,男性:176人\n",
|
||
"单脚站立平均成绩:1.7135分,女性:192人\n",
|
||
"单脚站立平均成绩:1.7038分,总体:368人\n",
|
||
"选择反应时平均成绩:2.4725分,男性:182人\n",
|
||
"选择反应时平均成绩:2.2927分,女性:205人\n",
|
||
"选择反应时平均成绩:2.3773分,总体:387人\n",
|
||
"台阶指数平均成绩:3.475分,男性:40人\n",
|
||
"台阶指数平均成绩:3.6866分,女性:67人\n",
|
||
"台阶指数平均成绩:3.6075分,总体:107人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙体测报告明细表.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 = int(sheet.cell(n, 1).value) \n",
|
||
" list1.append(str(code)) \n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_杨庙社区2303.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"\n",
|
||
"for item in items:\n",
|
||
" m = 0\n",
|
||
" f = 0\n",
|
||
" score = 0\n",
|
||
" t_score = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['sex'] == 1 and item in v.keys() and k in list1:\n",
|
||
" #print(k)\n",
|
||
" \n",
|
||
" if v[item]['得分']!=\"\":\n",
|
||
" m = m +1\n",
|
||
" score = score+int(v[item]['得分'])\n",
|
||
" if m>0:\n",
|
||
" print(f'{item}平均成绩:{round(score/m,4)}分,男性:{m}人')\n",
|
||
" t_score = t_score + score\n",
|
||
" score = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['sex'] == 2 and item in v.keys() and k in list1:\n",
|
||
" \n",
|
||
" if v[item]['得分']!='':\n",
|
||
" f = f +1\n",
|
||
" score = score+int(v[item]['得分'])\n",
|
||
" if f >0:\n",
|
||
" print(f'{item}平均成绩:{round(score/f,4)}分,女性:{f}人')\n",
|
||
" t_score = t_score + score\n",
|
||
" if (f+m)>0:\n",
|
||
" print(f'{item}平均成绩:{round(t_score/(f+m),4)}分,总体:{f+m}人')\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 37,
|
||
"id": "e35ed01c-9a45-4a3c-b391-1655223f0c08",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:23:00.446004Z",
|
||
"iopub.status.busy": "2023-10-10T11:23:00.445535Z",
|
||
"iopub.status.idle": "2023-10-10T11:23:00.495577Z",
|
||
"shell.execute_reply": "2023-10-10T11:23:00.494955Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:23:00.445967Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"男性:187人\n",
|
||
"女性:208人\n",
|
||
"总体:395人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙体测报告明细表.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 = int(sheet.cell(n, 1).value) \n",
|
||
" list1.append(str(code)) \n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_杨庙社区2303.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"\n",
|
||
"\n",
|
||
"m =0\n",
|
||
"f =0\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == 1 and k in list1:\n",
|
||
" m = m +1\n",
|
||
"print(f'男性:{m}人')\n",
|
||
"\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == 2 and k in list1:\n",
|
||
" f = f +1\n",
|
||
"print(f'女性:{f}人')\n",
|
||
"\n",
|
||
"print(f'总体:{f+m}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 28,
|
||
"id": "a3fd59cd-5b02-4b19-b91f-12aad60bcc97",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:15:19.155689Z",
|
||
"iopub.status.busy": "2023-10-10T11:15:19.155226Z",
|
||
"iopub.status.idle": "2023-10-10T11:15:19.226867Z",
|
||
"shell.execute_reply": "2023-10-10T11:15:19.225686Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:15:19.155653Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"76\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙体测报告明细表.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 = int(sheet.cell(n, 1).value) \n",
|
||
" list1.append(str(code)) \n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_杨庙社区2303.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in list1:\n",
|
||
" if item not in dict1.keys():\n",
|
||
" print(item)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "55b49119-2d00-4b65-a5cb-4079c84ce188",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 分析八月数据"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 46,
|
||
"id": "0550886e-f3d7-4366-acdc-98d2aa879f98",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:35:05.533094Z",
|
||
"iopub.status.busy": "2023-10-10T11:35:05.532623Z",
|
||
"iopub.status.idle": "2023-10-10T11:35:05.617045Z",
|
||
"shell.execute_reply": "2023-10-10T11:35:05.616118Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:35:05.533057Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"bmi平均成绩:3.7597分,男性:258人\n",
|
||
"bmi平均成绩:3.7911分,女性:316人\n",
|
||
"bmi平均成绩:3.777分,总体:574人\n",
|
||
"lung平均成绩:1.8803分,男性:259人\n",
|
||
"lung平均成绩:1.652分,女性:319人\n",
|
||
"lung平均成绩:1.7543分,总体:578人\n",
|
||
"grip平均成绩:1.5328分,男性:259人\n",
|
||
"grip平均成绩:1.5063分,女性:318人\n",
|
||
"grip平均成绩:1.5182分,总体:577人\n",
|
||
"flexion平均成绩:2.2923分,男性:260人\n",
|
||
"flexion平均成绩:2.511分,女性:319人\n",
|
||
"flexion平均成绩:2.4128分,总体:579人\n",
|
||
"balance平均成绩:2.082分,男性:244人\n",
|
||
"balance平均成绩:1.9628分,女性:296人\n",
|
||
"balance平均成绩:2.0167分,总体:540人\n",
|
||
"reaction平均成绩:1.9648分,男性:256人\n",
|
||
"reaction平均成绩:1.7453分,女性:318人\n",
|
||
"reaction平均成绩:1.8432分,总体:574人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\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 = int(sheet.cell(n, 1).value) \n",
|
||
" list1.append(str(code)) \n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
" \n",
|
||
"for item in items: \n",
|
||
" m = 0\n",
|
||
" f = 0\n",
|
||
" score = 0\n",
|
||
" t_score = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['gender'] == 'male' and item in v['fit'].keys() and k in list1:\n",
|
||
" #print(k)\n",
|
||
" \n",
|
||
" if v['fit'][item]['score']!=\"\":\n",
|
||
" m = m +1\n",
|
||
" score = score+int(v['fit'][item]['score'])\n",
|
||
" if m>0:\n",
|
||
" print(f'{item}平均成绩:{round(score/m,4)}分,男性:{m}人')\n",
|
||
" t_score = t_score + score\n",
|
||
" score = 0\n",
|
||
" for k,v in dict1.items():\n",
|
||
" if v['gender'] == 'female' and item in v['fit'].keys() and k in list1:\n",
|
||
" \n",
|
||
" if v['fit'][item]['score']!=\"\":\n",
|
||
" f = f +1\n",
|
||
" score = score+int(v['fit'][item]['score'])\n",
|
||
" if f >0:\n",
|
||
" print(f'{item}平均成绩:{round(score/f,4)}分,女性:{f}人')\n",
|
||
" t_score = t_score + score\n",
|
||
" if (f+m)>0:\n",
|
||
" print(f'{item}平均成绩:{round(t_score/(f+m),4)}分,总体:{f+m}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 45,
|
||
"id": "775e5a8b-6384-4d67-bbda-c5655dba05d3",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:34:53.146506Z",
|
||
"iopub.status.busy": "2023-10-10T11:34:53.146035Z",
|
||
"iopub.status.idle": "2023-10-10T11:34:53.228193Z",
|
||
"shell.execute_reply": "2023-10-10T11:34:53.227372Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:34:53.146468Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"579\n",
|
||
"男性:260人\n",
|
||
"女性:319人\n",
|
||
"总体:579人\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"\n",
|
||
"wb = openpyxl.load_workbook('data/杨庙测试2023年8月报告明细表.xlsx')\n",
|
||
"sheet = wb.active\n",
|
||
"items = ['bmi','lung','grip','flexion','balance','reaction']\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",
|
||
" list1.append(str(code)) \n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/杨庙社区人员信息2307.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"print(len(list1))\n",
|
||
"\n",
|
||
"m =0\n",
|
||
"f =0\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == '男' and k in list1:\n",
|
||
" m = m +1\n",
|
||
"print(f'男性:{m}人')\n",
|
||
"\n",
|
||
"for k,v in dict1.items():\n",
|
||
" if v['sex'] == '女' and k in list1:\n",
|
||
" f = f +1\n",
|
||
"print(f'女性:{f}人')\n",
|
||
"\n",
|
||
"print(f'总体:{f+m}人')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 43,
|
||
"id": "33984dce-b540-4f60-a100-6399f43d9df8",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:33:29.904700Z",
|
||
"iopub.status.busy": "2023-10-10T11:33:29.904220Z",
|
||
"iopub.status.idle": "2023-10-10T11:33:29.960744Z",
|
||
"shell.execute_reply": "2023-10-10T11:33:29.960314Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:33:29.904662Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\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 = int(sheet.cell(n, 1).value) \n",
|
||
" list1.append(str(code)) \n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in list1:\n",
|
||
" if item not in dict1.keys():\n",
|
||
" print(item)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 44,
|
||
"id": "a74b5034-9613-49ca-ba65-c82a443b143b",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2023-10-10T11:34:15.953655Z",
|
||
"iopub.status.busy": "2023-10-10T11:34:15.953183Z",
|
||
"iopub.status.idle": "2023-10-10T11:34:16.028478Z",
|
||
"shell.execute_reply": "2023-10-10T11:34:16.028017Z",
|
||
"shell.execute_reply.started": "2023-10-10T11:34:15.953618Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"list1 = []\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 = int(sheet.cell(n, 1).value) \n",
|
||
" if str(code) not in list1:\n",
|
||
" list1.append(str(code))\n",
|
||
" else:\n",
|
||
" print(code)\n",
|
||
"\n",
|
||
"\n",
|
||
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl) \n",
|
||
"for item in list1:\n",
|
||
" if item not in dict1.keys():\n",
|
||
" print(item)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "3be7547a-f705-46cc-94e1-37c83ee04d86",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 生成体测成绩表"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "f671a493-88a7-4594-98d7-bd3d0a091bee",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-04-30T03:36:18.290034Z",
|
||
"iopub.status.busy": "2024-04-30T03:36:18.289557Z",
|
||
"iopub.status.idle": "2024-04-30T03:36:18.352150Z",
|
||
"shell.execute_reply": "2024-04-30T03:36:18.350627Z",
|
||
"shell.execute_reply.started": "2024-04-30T03:36:18.289994Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"ename": "KeyError",
|
||
"evalue": "'sex'",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[0;32mIn[6], line 17\u001b[0m\n\u001b[1;32m 15\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mstr\u001b[39m(k)\u001b[38;5;241m.\u001b[39mrjust(\u001b[38;5;241m5\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m 16\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(dict1[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]) \n\u001b[0;32m---> 17\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[43mdict1\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msex\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m)\n\u001b[1;32m 18\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(dict1[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m部门\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 19\u001b[0m i \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n",
|
||
"\u001b[0;31mKeyError\u001b[0m: 'sex'"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['身高','体重','肺活量','握力','纵跳','坐位体前屈','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||
"bmi = ['height','weight']\n",
|
||
"title = ['编号','姓名','性别','单位/部门','身高','','体重','','肺活量','','握力','','纵跳','','坐位体前屈','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数','']\n",
|
||
"\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n",
|
||
" list2 = []\n",
|
||
" list2.append(str(k).rjust(5,'0'))\n",
|
||
" list2.append(dict1[k]['name']) \n",
|
||
" list2.append(dict1[k]['sex'])\n",
|
||
" list2.append(dict1[k]['部门'])\n",
|
||
" i = 0\n",
|
||
" \n",
|
||
" for item in items:\n",
|
||
" if item in dict1[k].keys():\n",
|
||
" list2.append(dict1[k][item]['成绩'])\n",
|
||
" list2.append(dict1[k][item]['得分']) \n",
|
||
" i+=1\n",
|
||
" elif item =='name':\n",
|
||
" list2.append(dict1[k][item])\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append('')\n",
|
||
" list1.append(list2)\n",
|
||
"filename = 'data/杨庙202303体测明细表.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') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"id": "ffce0b6c-5fcd-40b5-a118-6ae2ce9ec464",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-04-30T03:52:18.063321Z",
|
||
"iopub.status.busy": "2024-04-30T03:52:18.062912Z",
|
||
"iopub.status.idle": "2024-04-30T03:52:18.197236Z",
|
||
"shell.execute_reply": "2024-04-30T03:52:18.196723Z",
|
||
"shell.execute_reply.started": "2024-04-30T03:52:18.063266Z"
|
||
},
|
||
"tags": []
|
||
},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"ok\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import json\n",
|
||
"import openpyxl\n",
|
||
"\n",
|
||
"items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n",
|
||
"bmi = ['height','weight']\n",
|
||
"title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\n",
|
||
"\n",
|
||
"filename = 'data/result_杨庙2308.json'\n",
|
||
"with open(filename,'r') as fl:\n",
|
||
" dict1 = json.load(fl)\n",
|
||
"list1 = []\n",
|
||
"for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n",
|
||
" list2 = []\n",
|
||
" list2.append(str(k).rjust(5,'0'))\n",
|
||
" list2.append(dict1[k]['name']) \n",
|
||
" list2.append(dict1[k]['gender'])\n",
|
||
" list2.append(dict1[k]['title'])\n",
|
||
" i = 0\n",
|
||
" if 'bmi' in v['fit'].keys():\n",
|
||
" m_bmi = v['fit']['bmi']['mark']\n",
|
||
" list2.append(m_bmi.split(',')[0])\n",
|
||
" list2.append(m_bmi.split(',')[1])\n",
|
||
" list2.append(v['fit']['bmi']['score'])\n",
|
||
" i+=1\n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" \n",
|
||
" \n",
|
||
" for item in items:\n",
|
||
" if item in v['fit'].keys():\n",
|
||
" list2.append(v['fit'][item]['mark'])\n",
|
||
" list2.append(v['fit'][item]['score']) \n",
|
||
" i+=1\n",
|
||
" \n",
|
||
" else:\n",
|
||
" list2.append('') \n",
|
||
" list2.append('') \n",
|
||
" \n",
|
||
" list1.append(list2)\n",
|
||
"filename = 'data/杨庙202308体测明细表.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') "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "34876192-a7d3-454d-a929-53e3b6bfbeae",
|
||
"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
|
||
}
|