1604 lines
51 KiB
Plaintext
1604 lines
51 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "04524c85-988e-4dbf-86eb-939a9db7aa28",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 体测人员导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "bbba6efc-73cd-4db6-bae7-014724fee731",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-15T10:15:07.803553Z",
|
|
"iopub.status.busy": "2024-05-15T10:15:07.803255Z",
|
|
"iopub.status.idle": "2024-05-15T10:15:07.958318Z",
|
|
"shell.execute_reply": "2024-05-15T10:15:07.957863Z",
|
|
"shell.execute_reply.started": "2024-05-15T10:15:07.803529Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"from datetime import date\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, 3).value\n",
|
|
" dict1['sex'] = sheet.cell(n, 4).value\n",
|
|
" dict1['unit'] = sheet.cell(n, 2).value\n",
|
|
" dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \n",
|
|
" dict1['phone'] = str(sheet.cell(n,6).value)\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": 8,
|
|
"id": "482517fc-650c-4b8c-bdf3-b32ec508de99",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T09:32:43.937514Z",
|
|
"iopub.status.busy": "2024-06-12T09:32:43.936781Z",
|
|
"iopub.status.idle": "2024-06-12T09:32:43.965201Z",
|
|
"shell.execute_reply": "2024-06-12T09:32:43.964613Z",
|
|
"shell.execute_reply.started": "2024-06-12T09:32:43.937449Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"from datetime import date\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, 4).value\n",
|
|
" dict1['sex'] = sheet.cell(n, 5).value\n",
|
|
" dict1['unit'] = sheet.cell(n, 2).value\n",
|
|
" dict1['birth'] = str(sheet.cell(n, 8).value).replace('/','-').split(' ')[0] \n",
|
|
" dict1['phone'] = str(sheet.cell(n,10).value)\n",
|
|
" person[code] = dict1\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(person, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "048a95aa-1691-45f6-b933-6eaf95ae1d30",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成读卡系统文件"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-12-06T04:07:25.580543Z",
|
|
"iopub.status.busy": "2023-12-06T04:07:25.580096Z",
|
|
"iopub.status.idle": "2023-12-06T04:07:25.602275Z",
|
|
"shell.execute_reply": "2023-12-06T04:07:25.599401Z",
|
|
"shell.execute_reply.started": "2023-12-06T04:07:25.580484Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/青海.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"list1 = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict2 = {}\n",
|
|
" #if dict1['sex'] =='男':\n",
|
|
" # sex = 1\n",
|
|
" \n",
|
|
" dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}\n",
|
|
" list1.append(dict2)\n",
|
|
"json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n",
|
|
"\n",
|
|
"# 将 json 数据写入文件\n",
|
|
"with open(\"data/data_青海.json\", \"w\",encoding = 'utf-8') as file:\n",
|
|
" file.write(json_data) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取人员测试成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"id": "970e171e-1360-448f-a28c-520ccb8f314a",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-15T13:07:30.547209Z",
|
|
"iopub.status.busy": "2024-05-15T13:07:30.546727Z",
|
|
"iopub.status.idle": "2024-05-15T13:07:30.568057Z",
|
|
"shell.execute_reply": "2024-05-15T13:07:30.566736Z",
|
|
"shell.execute_reply.started": "2024-05-15T13:07:30.547158Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"27\n",
|
|
"27\n"
|
|
]
|
|
}
|
|
],
|
|
"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/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20240311.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]['unit'] = 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",
|
|
"print(len(re_ta))\n",
|
|
"filename = 'data/result_青海20240515.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": "c6703be2-b6d7-4fe3-9c13-ea55b752d933",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 转换报告格式"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"id": "724306c7-6b00-4322-856b-28ec96dfe9d0",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-15T13:07:38.825400Z",
|
|
"iopub.status.busy": "2024-05-15T13:07:38.824940Z",
|
|
"iopub.status.idle": "2024-05-15T13:07:38.851607Z",
|
|
"shell.execute_reply": "2024-05-15T13:07:38.851206Z",
|
|
"shell.execute_reply.started": "2024-05-15T13:07:38.825363Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"27\n",
|
|
"27\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"import csv\n",
|
|
"from datetime import date\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" item[k] = v\n",
|
|
"item['1']['en'] = 'lung'\n",
|
|
"item['2']['en'] = 'grip'\n",
|
|
"item['3']['en'] = 'flexion'\n",
|
|
"item['4']['en'] = 'jump'\n",
|
|
"item['5']['en'] = 'pushup'\n",
|
|
"item['6']['en'] = 'balance'\n",
|
|
"item['7']['en'] = 'reaction'\n",
|
|
"item['8']['en'] = 'step'\n",
|
|
"item['9']['en'] = 'situp'\n",
|
|
"item['10']['en'] = 'height'\n",
|
|
"item['11']['en'] = 'weight'\n",
|
|
"\n",
|
|
"\n",
|
|
"re_ta = {}\n",
|
|
"dict1 = {}\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20240311.csv'\n",
|
|
"with open(filename,'r',newline='') as csv_file:\n",
|
|
" fl = csv.reader(csv_file,delimiter=',')\n",
|
|
" header = next(fl) \n",
|
|
" for line in fl:\n",
|
|
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
|
" list1.append(line)\n",
|
|
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
|
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
|
"for result in list1:\n",
|
|
" user = str(result[2])\n",
|
|
" rq = date.fromisoformat(result[6].replace('/','-'))\n",
|
|
" if user in dict1.keys():\n",
|
|
" l_xm = []\n",
|
|
" m_item = str(result[3]) \n",
|
|
" re_ta.setdefault(user,{}) \n",
|
|
" re_ta[user]['name'] = dict1[user]['name']\n",
|
|
" re_ta[user]['sex'] = dict1[user]['sex']\n",
|
|
" if dict1[user]['sex'] == '男':\n",
|
|
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
|
" else:\n",
|
|
" l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
|
" re_ta[user]['unit'] = dict1[user]['unit']\n",
|
|
" #birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n",
|
|
" birth = date.fromisoformat(dict1[user]['birth'])\n",
|
|
" #nian = int(birth[0].strip())\n",
|
|
" #yue = int(birth[1].strip())\n",
|
|
" #ri = int(birth[2].strip())\n",
|
|
" #print(k,nian,yue,ri)\n",
|
|
" item_name = item[m_item]['en'] \n",
|
|
" if item_name in l_xm: \n",
|
|
" days = (rq-birth).days \n",
|
|
" re_ta[user]['age'] = int(days/365)\n",
|
|
" re_ta[user]['month'] = int(days/365*12)\n",
|
|
" re_ta[user]['rq'] = result[6]\n",
|
|
"\n",
|
|
"\n",
|
|
" re_ta[user].setdefault(item_name,{}) \n",
|
|
" score = int(result[4])/item[m_item]['divisor'] \n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
"print(len(re_ta))\n",
|
|
"filename = 'data/result_青海all.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": "b9b5d490-b303-481c-b1f2-cb1c281aabe6",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成完善得分"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"id": "a9228dc5-e3b1-4a48-8938-747abb59786c",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-15T13:07:46.464810Z",
|
|
"iopub.status.busy": "2024-05-15T13:07:46.464338Z",
|
|
"iopub.status.idle": "2024-05-15T13:07:46.499865Z",
|
|
"shell.execute_reply": "2024-05-15T13:07:46.498876Z",
|
|
"shell.execute_reply.started": "2024-05-15T13:07:46.464771Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict3 = json.load(fl) \n",
|
|
"for k,v in dict3.items():\n",
|
|
" item[k] = v\n",
|
|
"item['1']['en'] = 'lung'\n",
|
|
"item['2']['en'] = 'grip'\n",
|
|
"item['3']['en'] = 'flexion'\n",
|
|
"item['4']['en'] = 'jump'\n",
|
|
"item['5']['en'] = 'pushup'\n",
|
|
"item['6']['en'] = 'balance'\n",
|
|
"item['7']['en'] = 'reaction'\n",
|
|
"item['8']['en'] = 'step'\n",
|
|
"item['9']['en'] = 'situp'\n",
|
|
"item['10']['en'] = 'height'\n",
|
|
"item['11']['en'] = 'weight'\n",
|
|
"\n",
|
|
"filename = 'data/体质检测标准 (1).json' \n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"def cal_score(data1):\n",
|
|
" #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n",
|
|
" person = dict1['person']\n",
|
|
" criteria = dict1['criteria']\n",
|
|
" if data1['age'] >59:\n",
|
|
" data1['age'] = 59\n",
|
|
" if data1['age'] <20:\n",
|
|
" data1['age'] = 20\n",
|
|
" info = data1['sex']+str(data1['age'])\n",
|
|
" bz = person[info]\n",
|
|
" mx = criteria[bz][data1['item']]\n",
|
|
" result = data1['result'] \n",
|
|
" if data1['item'] == 'reaction':\n",
|
|
" for bz1 in mx:\n",
|
|
" if result > bz1:\n",
|
|
" #print(bz1)\n",
|
|
" score = mx.index(bz1,0)\n",
|
|
" break\n",
|
|
" else:\n",
|
|
" score = 5\n",
|
|
" else:\n",
|
|
" for bz1 in mx:\n",
|
|
" if result < bz1:\n",
|
|
" #print(bz1)\n",
|
|
" score = mx.index(bz1,0)\n",
|
|
" break\n",
|
|
" else:\n",
|
|
" score = 5\n",
|
|
" return(score)\n",
|
|
"filename = 'data/体质检测标准_BMI.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict4 = json.load(fl) \n",
|
|
" \n",
|
|
"def cal_bmi(data1):\n",
|
|
" # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
|
|
" person = dict4['person']\n",
|
|
" criteria = dict4['criteria']\n",
|
|
" if data1['age'] > 59:\n",
|
|
" data1['age'] = 59\n",
|
|
" if data1['age'] <20:\n",
|
|
" data1['age'] = 20\n",
|
|
" info = data1['sex']+str(data1['age'])\n",
|
|
" bz = person[info]\n",
|
|
" #print(bz)\n",
|
|
" result = data1['result']\n",
|
|
" #print(data1['code'],result)\n",
|
|
" height = int(float(result.split(',')[0]))\n",
|
|
" weight = float(result.split(',')[1])\n",
|
|
" if str(height) not in criteria[bz]:\n",
|
|
" score = 1\n",
|
|
" else: \n",
|
|
" mx = criteria[bz][str(height)]\n",
|
|
" if weight < mx[0]:\n",
|
|
" score = 1\n",
|
|
" elif weight < mx[1]:\n",
|
|
" score = 3\n",
|
|
" elif weight < mx[2]:\n",
|
|
" score = 5 \n",
|
|
" elif weight <= mx[3]:\n",
|
|
" score = 3 \n",
|
|
" elif weight > mx[3]:\n",
|
|
" score = 1\n",
|
|
" return score\n",
|
|
" \n",
|
|
" \n",
|
|
"\n",
|
|
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
|
|
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
|
|
"filename = 'data/result_青海all.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_青海all.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
|
"print('ok!') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d034a61d-1fbd-417b-99bd-277e43ebb678",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出测试人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-15T10:36:24.371302Z",
|
|
"iopub.status.busy": "2024-05-15T10:36:24.370831Z",
|
|
"iopub.status.idle": "2024-05-15T10:36:24.404481Z",
|
|
"shell.execute_reply": "2024-05-15T10:36:24.402924Z",
|
|
"shell.execute_reply.started": "2024-05-15T10:36:24.371263Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"\n",
|
|
"filename = 'data/result_青海20240515.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
" \n",
|
|
"list1 = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" if k in dict2.keys():\n",
|
|
" list2 = []\n",
|
|
" list2.append(str(k).rjust(5,'0'))\n",
|
|
" list2.append(v['name']) \n",
|
|
" list2.append(dict2[k]['sex'])\n",
|
|
" list2.append(dict2[k]['unit'])\n",
|
|
" for item in items:\n",
|
|
" if item in v.keys():\n",
|
|
" list2.append(v[item]['成绩']) \n",
|
|
" elif item =='name':\n",
|
|
" list2.append(v[item])\n",
|
|
" else:\n",
|
|
" list2.append('') \n",
|
|
" list1.append(list2)\n",
|
|
"filename = 'data/青海20240515.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": "699c6a40-a6ae-4300-9646-708cb85aa5e8",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导入问卷信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "67e63f07-3f20-4e0e-9c07-7bf6024eeb4b",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T09:33:33.449532Z",
|
|
"iopub.status.busy": "2024-06-12T09:33:33.448794Z",
|
|
"iopub.status.idle": "2024-06-12T09:33:33.470858Z",
|
|
"shell.execute_reply": "2024-06-12T09:33:33.470068Z",
|
|
"shell.execute_reply.started": "2024-06-12T09:33:33.449463Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"18993710898\n",
|
|
"18894239366\n",
|
|
"13801023617\n",
|
|
"19009775378\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"import openpyxl\n",
|
|
"import time\n",
|
|
"from datetime import date\n",
|
|
"\n",
|
|
"filename = 'data/result_青海all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict3 = json.load(fl)\n",
|
|
"\n",
|
|
"phone = {}\n",
|
|
"for k,v in dict3.items():\n",
|
|
" if 'phone' in v.keys():\n",
|
|
" phone[v['phone']] = k\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/Survey_20240612.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",
|
|
" list1.append(line)\n",
|
|
"#print(list1)\n",
|
|
"dict2 = {}\n",
|
|
"psy =[]\n",
|
|
"tcm = []\n",
|
|
"spine = []\n",
|
|
"for i in range(0,45):\n",
|
|
" psy.append(0)\n",
|
|
"psy[44] = []\n",
|
|
"for i in range(0,60):\n",
|
|
" tcm.append(0)\n",
|
|
"for i in range(0,26):\n",
|
|
" spine.append(0)\n",
|
|
"\n",
|
|
"for item in list1:\n",
|
|
" if item[2] in phone.keys():\n",
|
|
" psy =[]\n",
|
|
" tcm = []\n",
|
|
" spine = []\n",
|
|
" for i in range(0,45):\n",
|
|
" psy.append(0)\n",
|
|
" psy[44] = []\n",
|
|
" for i in range(0,60):\n",
|
|
" tcm.append(0)\n",
|
|
" for i in range(0,26):\n",
|
|
" spine.append(0)\n",
|
|
" \n",
|
|
" content = json.loads(item[5])\n",
|
|
" if phone[item[2]] not in dict1.keys():\n",
|
|
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
|
" #print(item[2])\n",
|
|
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
|
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
|
" for k, v in content.items():\n",
|
|
" if 'psy' in k:\n",
|
|
" i = int(k[3:])\n",
|
|
" psy[i-1] = int(v)\n",
|
|
" if 'tcm' in k:\n",
|
|
" i = int(k[3:])\n",
|
|
" tcm[i-1] = int(v)\n",
|
|
" if 'spine' in k:\n",
|
|
" i = int(k[5:])\n",
|
|
" spine[i-1] = int(v)\n",
|
|
" if 'psy' in item[5]:\n",
|
|
" #for i in range(5,26):\n",
|
|
" # new_valve = 5-psy[i]\n",
|
|
" # psy[i] = new_valve\n",
|
|
" for i in range(26,40):\n",
|
|
" new_valve = 1+psy[i]\n",
|
|
" psy[i] = new_valve\n",
|
|
" \n",
|
|
" dict1[phone[item[2]]]['psy'] = psy\n",
|
|
" if 'tcm' in item[5]:\n",
|
|
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
|
" if 'spine' in item[5]:\n",
|
|
" dict1[phone[item[2]]]['spine'] = spine\n",
|
|
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
|
" #rq =date.fromisoformat('2023-12-08')\n",
|
|
" days = (rq-birth).days \n",
|
|
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
|
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
|
" else:\n",
|
|
" print(item[2])\n",
|
|
"filename = 'data/result_青海all_2.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "cc211422-c097-4b80-994d-f7cf11594185",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成报告"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "9e96d70b-3f7c-4c55-8c7a-f8373c2d9a7a",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T09:36:27.538771Z",
|
|
"iopub.status.busy": "2024-06-12T09:36:27.538043Z",
|
|
"iopub.status.idle": "2024-06-12T09:36:46.165927Z",
|
|
"shell.execute_reply": "2024-06-12T09:36:46.164846Z",
|
|
"shell.execute_reply.started": "2024-06-12T09:36:27.538707Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"35\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import requests\n",
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"\n",
|
|
"headers = {\n",
|
|
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
|
" }\n",
|
|
"filename = 'data/result_青海all_2.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"list1 = []\n",
|
|
"file_path ='./青海1/'\n",
|
|
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
|
|
"i=0\n",
|
|
"list2 = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" list1 = []\n",
|
|
" mydata = {}\n",
|
|
" \n",
|
|
" id = str(k).rjust(4,\"0\")\n",
|
|
" mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n",
|
|
" mydata['title'] = '青海油田勘探事业部' \n",
|
|
" mydata['subtitle'] = v['unit']\n",
|
|
" mydata['id'] = id\n",
|
|
" mydata['name'] = v['name']\n",
|
|
" if v['sex'] == '男':\n",
|
|
" mydata['gender'] = 'male'\n",
|
|
" else:\n",
|
|
" mydata['gender'] = 'female'\n",
|
|
" \n",
|
|
" mydata['month'] = v['month']\n",
|
|
" mydata['fits'] = {}\n",
|
|
" survey_list = ['tcm','psy','spine']\n",
|
|
" for item in survey_list:\n",
|
|
" if item in v.keys():\n",
|
|
" mydata.setdefault('surveys',{})\n",
|
|
" mydata['surveys'][item] = v[item]\n",
|
|
" \n",
|
|
" \n",
|
|
" #mydata['fits'] = {}\n",
|
|
" for item in list_item:\n",
|
|
" if item in v.keys():\n",
|
|
" mydata.setdefault('fits',{})\n",
|
|
" if item in ['lung','pushup','step','situp']:\n",
|
|
" mark = v[item]['成绩'].split()[0].split('.')[0]\n",
|
|
" else:\n",
|
|
" mark = v[item]['成绩'].split()[0]\n",
|
|
" mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n",
|
|
" #if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n",
|
|
" #if len(mydata['fits']) >2 : \n",
|
|
" list1.append(mydata)\n",
|
|
" list2.append([k,v['name']])\n",
|
|
" i+=1\n",
|
|
" x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n",
|
|
" #print(id,v['name'],x.text)\n",
|
|
" #print(mydata)\n",
|
|
" #x.close()\n",
|
|
"print(i)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c776f605-c7c4-494e-b172-c5dc7f9beef4",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 统计人员情况"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "11727a08-9da8-4eb2-aadf-69dc72031bdc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-20T06:45:31.065931Z",
|
|
"iopub.status.busy": "2024-05-20T06:45:31.065241Z",
|
|
"iopub.status.idle": "2024-05-20T06:45:31.078036Z",
|
|
"shell.execute_reply": "2024-05-20T06:45:31.077063Z",
|
|
"shell.execute_reply.started": "2024-05-20T06:45:31.065872Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"27\n",
|
|
"14\n",
|
|
"11\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"import openpyxl\n",
|
|
"import time\n",
|
|
"from datetime import date\n",
|
|
"wj = []\n",
|
|
"tc = []\n",
|
|
"all = []\n",
|
|
"filename = 'data/result_青海20240515.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"for k, v in dict1.items():\n",
|
|
" tc.append(k)\n",
|
|
"print(len(tc))\n",
|
|
" \n",
|
|
"filename = 'data/result_青海all_2.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" if 'psy' in v.keys():\n",
|
|
" wj.append(k)\n",
|
|
"print(len(wj))\n",
|
|
"for item in wj:\n",
|
|
" if item in tc:\n",
|
|
" all.append(item)\n",
|
|
"print(len(all))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5e97c15a-8f92-4c17-9f2e-cb76a2e0043b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 统计问卷人员情况表"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "f93523ed-a9fb-46f4-8f38-17ebde168303",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-03T05:27:38.006019Z",
|
|
"iopub.status.busy": "2024-06-03T05:27:38.005067Z",
|
|
"iopub.status.idle": "2024-06-03T05:27:38.015980Z",
|
|
"shell.execute_reply": "2024-06-03T05:27:38.014890Z",
|
|
"shell.execute_reply.started": "2024-06-03T05:27:38.005949Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['18993727823', '18909376562', '18993710970', '18997374506', '18997372109', '18093715987', '18997372608', '18993722556', '18993710998', '18993729661', '18993710973', '18993714097', '18909376963', '18993728737']\n",
|
|
"20\n",
|
|
"18\n",
|
|
"42\n",
|
|
"44\n",
|
|
"61\n",
|
|
"62\n",
|
|
"24\n",
|
|
"68\n",
|
|
"9\n",
|
|
"3\n",
|
|
"55\n",
|
|
"33\n",
|
|
"5\n",
|
|
"50\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"import openpyxl\n",
|
|
"import time\n",
|
|
"from datetime import date\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict3 = json.load(fl)\n",
|
|
"\n",
|
|
"phone = {}\n",
|
|
"for k,v in dict3.items():\n",
|
|
" if 'phone' in v.keys():\n",
|
|
" phone[v['phone']] = k\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/Survey_20240603.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",
|
|
" if line[2] in phone.keys() and line[2] not in list1:\n",
|
|
" list1.append(line[2])\n",
|
|
"print(list1) \n",
|
|
"for item in list1:\n",
|
|
" print(phone[item])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c175912f-a1ea-4849-8bfa-3a9e25883850",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 统计报告发送情况表"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "953e6f09-74dd-48cf-810e-ffe78f621c81",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-03T08:53:03.990417Z",
|
|
"iopub.status.busy": "2024-06-03T08:53:03.989701Z",
|
|
"iopub.status.idle": "2024-06-03T08:53:04.015802Z",
|
|
"shell.execute_reply": "2024-06-03T08:53:04.014751Z",
|
|
"shell.execute_reply.started": "2024-06-03T08:53:03.990354Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"filename = 'data/result_青海all_1.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"list1 = []\n",
|
|
"for k,v in dict1.items():\n",
|
|
" list2 = []\n",
|
|
" list2 = [k,v['name'],v['sex'],v['unit'],v['phone']]\n",
|
|
" list1.append(list2)\n",
|
|
"\n",
|
|
"filename = 'data/青海体测报告发送明细.xlsx'\n",
|
|
"wb = openpyxl.Workbook()\n",
|
|
"sheet = wb.active\n",
|
|
"\n",
|
|
"for row in list1:\n",
|
|
" sheet.append(row)\n",
|
|
" \n",
|
|
"wb.save(filename) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5274f18f-c63b-4bfa-9222-d1586c42fac2",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 筛选家属人员"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "3cc922d2-9a1f-4aa6-8011-5541fe2e9715",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:09:49.493466Z",
|
|
"iopub.status.busy": "2024-06-12T10:09:49.492704Z",
|
|
"iopub.status.idle": "2024-06-12T10:09:49.504610Z",
|
|
"shell.execute_reply": "2024-06-12T10:09:49.503561Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:09:49.493398Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"dict3 = {}\n",
|
|
"filename = 'data/青海.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"filename = 'data/青海2024.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
"\n",
|
|
"for k, v in dict1.items():\n",
|
|
" if k not in dict2.keys():\n",
|
|
" dict3[k] = v\n",
|
|
"filename = 'data/青海_家属.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(dict3, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "804f1cf0-c2e6-4c4d-841b-1cc5e25c35f7",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:11:46.968562Z",
|
|
"iopub.status.busy": "2024-06-12T10:11:46.967823Z",
|
|
"iopub.status.idle": "2024-06-12T10:11:46.982324Z",
|
|
"shell.execute_reply": "2024-06-12T10:11:46.981223Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:11:46.968493Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"14\n",
|
|
"14\n"
|
|
]
|
|
}
|
|
],
|
|
"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/青海_家属.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20240311.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]['unit'] = 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",
|
|
"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": "code",
|
|
"execution_count": 15,
|
|
"id": "0faf3ee7-e075-42bd-84ca-aea2b4ee890e",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:13:41.889274Z",
|
|
"iopub.status.busy": "2024-06-12T10:13:41.887953Z",
|
|
"iopub.status.idle": "2024-06-12T10:13:41.903763Z",
|
|
"shell.execute_reply": "2024-06-12T10:13:41.903073Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:13:41.889194Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"14\n",
|
|
"14\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"import csv\n",
|
|
"from datetime import date\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" item[k] = v\n",
|
|
"item['1']['en'] = 'lung'\n",
|
|
"item['2']['en'] = 'grip'\n",
|
|
"item['3']['en'] = 'flexion'\n",
|
|
"item['4']['en'] = 'jump'\n",
|
|
"item['5']['en'] = 'pushup'\n",
|
|
"item['6']['en'] = 'balance'\n",
|
|
"item['7']['en'] = 'reaction'\n",
|
|
"item['8']['en'] = 'step'\n",
|
|
"item['9']['en'] = 'situp'\n",
|
|
"item['10']['en'] = 'height'\n",
|
|
"item['11']['en'] = 'weight'\n",
|
|
"\n",
|
|
"\n",
|
|
"re_ta = {}\n",
|
|
"dict1 = {}\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/青海_家属.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20240311.csv'\n",
|
|
"with open(filename,'r',newline='') as csv_file:\n",
|
|
" fl = csv.reader(csv_file,delimiter=',')\n",
|
|
" header = next(fl) \n",
|
|
" for line in fl:\n",
|
|
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
|
" list1.append(line)\n",
|
|
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
|
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
|
"for result in list1:\n",
|
|
" user = str(result[2])\n",
|
|
" rq = date.fromisoformat(result[6].replace('/','-'))\n",
|
|
" if user in dict1.keys():\n",
|
|
" l_xm = []\n",
|
|
" m_item = str(result[3]) \n",
|
|
" re_ta.setdefault(user,{}) \n",
|
|
" re_ta[user]['name'] = dict1[user]['name']\n",
|
|
" re_ta[user]['sex'] = dict1[user]['sex']\n",
|
|
" if dict1[user]['sex'] == '男':\n",
|
|
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
|
" else:\n",
|
|
" l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
|
" re_ta[user]['unit'] = dict1[user]['unit']\n",
|
|
" #birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n",
|
|
" birth = date.fromisoformat(dict1[user]['birth'])\n",
|
|
" #nian = int(birth[0].strip())\n",
|
|
" #yue = int(birth[1].strip())\n",
|
|
" #ri = int(birth[2].strip())\n",
|
|
" #print(k,nian,yue,ri)\n",
|
|
" item_name = item[m_item]['en'] \n",
|
|
" if item_name in l_xm: \n",
|
|
" days = (rq-birth).days \n",
|
|
" re_ta[user]['age'] = int(days/365)\n",
|
|
" re_ta[user]['month'] = int(days/365*12)\n",
|
|
" re_ta[user]['rq'] = result[6]\n",
|
|
"\n",
|
|
"\n",
|
|
" re_ta[user].setdefault(item_name,{}) \n",
|
|
" score = int(result[4])/item[m_item]['divisor'] \n",
|
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
|
"print(len(re_ta))\n",
|
|
"filename = 'data/result_青海家属.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(re_ta, fl, ensure_ascii=False) \n",
|
|
"print(len(re_ta))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"id": "62863430-1d61-4282-b500-7261c66ec176",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:15:13.832706Z",
|
|
"iopub.status.busy": "2024-06-12T10:15:13.831999Z",
|
|
"iopub.status.idle": "2024-06-12T10:15:13.851428Z",
|
|
"shell.execute_reply": "2024-06-12T10:15:13.850214Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:15:13.832645Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict3 = json.load(fl) \n",
|
|
"for k,v in dict3.items():\n",
|
|
" item[k] = v\n",
|
|
"item['1']['en'] = 'lung'\n",
|
|
"item['2']['en'] = 'grip'\n",
|
|
"item['3']['en'] = 'flexion'\n",
|
|
"item['4']['en'] = 'jump'\n",
|
|
"item['5']['en'] = 'pushup'\n",
|
|
"item['6']['en'] = 'balance'\n",
|
|
"item['7']['en'] = 'reaction'\n",
|
|
"item['8']['en'] = 'step'\n",
|
|
"item['9']['en'] = 'situp'\n",
|
|
"item['10']['en'] = 'height'\n",
|
|
"item['11']['en'] = 'weight'\n",
|
|
"\n",
|
|
"filename = 'data/体质检测标准 (1).json' \n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"def cal_score(data1):\n",
|
|
" #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n",
|
|
" person = dict1['person']\n",
|
|
" criteria = dict1['criteria']\n",
|
|
" if data1['age'] >59:\n",
|
|
" data1['age'] = 59\n",
|
|
" if data1['age'] <20:\n",
|
|
" data1['age'] = 20\n",
|
|
" info = data1['sex']+str(data1['age'])\n",
|
|
" bz = person[info]\n",
|
|
" mx = criteria[bz][data1['item']]\n",
|
|
" result = data1['result'] \n",
|
|
" if data1['item'] == 'reaction':\n",
|
|
" for bz1 in mx:\n",
|
|
" if result > bz1:\n",
|
|
" #print(bz1)\n",
|
|
" score = mx.index(bz1,0)\n",
|
|
" break\n",
|
|
" else:\n",
|
|
" score = 5\n",
|
|
" else:\n",
|
|
" for bz1 in mx:\n",
|
|
" if result < bz1:\n",
|
|
" #print(bz1)\n",
|
|
" score = mx.index(bz1,0)\n",
|
|
" break\n",
|
|
" else:\n",
|
|
" score = 5\n",
|
|
" return(score)\n",
|
|
"filename = 'data/体质检测标准_BMI.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict4 = json.load(fl) \n",
|
|
" \n",
|
|
"def cal_bmi(data1):\n",
|
|
" # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
|
|
" person = dict4['person']\n",
|
|
" criteria = dict4['criteria']\n",
|
|
" if data1['age'] > 59:\n",
|
|
" data1['age'] = 59\n",
|
|
" if data1['age'] <20:\n",
|
|
" data1['age'] = 20\n",
|
|
" info = data1['sex']+str(data1['age'])\n",
|
|
" bz = person[info]\n",
|
|
" #print(bz)\n",
|
|
" result = data1['result']\n",
|
|
" #print(data1['code'],result)\n",
|
|
" height = int(float(result.split(',')[0]))\n",
|
|
" weight = float(result.split(',')[1])\n",
|
|
" if str(height) not in criteria[bz]:\n",
|
|
" score = 1\n",
|
|
" else: \n",
|
|
" mx = criteria[bz][str(height)]\n",
|
|
" if weight < mx[0]:\n",
|
|
" score = 1\n",
|
|
" elif weight < mx[1]:\n",
|
|
" score = 3\n",
|
|
" elif weight < mx[2]:\n",
|
|
" score = 5 \n",
|
|
" elif weight <= mx[3]:\n",
|
|
" score = 3 \n",
|
|
" elif weight > mx[3]:\n",
|
|
" score = 1\n",
|
|
" return score\n",
|
|
" \n",
|
|
" \n",
|
|
"\n",
|
|
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
|
|
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
|
|
"filename = 'data/result_青海家属.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl) \n",
|
|
"for k, v in dict2.items():\n",
|
|
" #print(k)\n",
|
|
" if v['sex'] == '男':\n",
|
|
" sex = 'M'\n",
|
|
" else:\n",
|
|
" sex = 'F' \n",
|
|
" if 'height' in v.keys() and 'weight' in v.keys():\n",
|
|
" bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
|
|
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
|
|
" dict2[k]['bmi'] = {}\n",
|
|
" dict2[k]['bmi']['成绩'] = bmi_data\n",
|
|
" dict2[k]['bmi']['score'] = cal_bmi(data1)\n",
|
|
" for item_en in list_item:\n",
|
|
" if item_en in v.keys(): \n",
|
|
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
|
|
" dict2[k][item_en]['score'] = cal_score(data1)\n",
|
|
" #print(k,v[item_en]['成绩'],cal_score(data1))\n",
|
|
"\n",
|
|
"filename = f'data/result_青海家属.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
|
"print('ok!') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"id": "35c83ea5-e331-4655-aba5-42720e2bc63a",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:16:48.636396Z",
|
|
"iopub.status.busy": "2024-06-12T10:16:48.635668Z",
|
|
"iopub.status.idle": "2024-06-12T10:16:48.657437Z",
|
|
"shell.execute_reply": "2024-06-12T10:16:48.656829Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:16:48.636335Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"18993727823\n",
|
|
"18909376562\n",
|
|
"18993710970\n",
|
|
"18997374506\n",
|
|
"18997372109\n",
|
|
"18093715987\n",
|
|
"18997372608\n",
|
|
"18993722556\n",
|
|
"18894239366\n",
|
|
"18993710998\n",
|
|
"13801023617\n",
|
|
"18993710998\n",
|
|
"18993729661\n",
|
|
"18093715391\n",
|
|
"18993710973\n",
|
|
"18997372109\n",
|
|
"18993714097\n",
|
|
"18909376963\n",
|
|
"18993728737\n",
|
|
"18997372608\n",
|
|
"18909376562\n",
|
|
"18993729661\n",
|
|
"18993712026\n",
|
|
"18993710395\n",
|
|
"18997375563\n",
|
|
"18993712869\n",
|
|
"18993710955\n",
|
|
"19009775378\n",
|
|
"18997375312\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"import openpyxl\n",
|
|
"import time\n",
|
|
"from datetime import date\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",
|
|
" dict3 = json.load(fl)\n",
|
|
"\n",
|
|
"phone = {}\n",
|
|
"for k,v in dict3.items():\n",
|
|
" if 'phone' in v.keys():\n",
|
|
" phone[v['phone']] = k\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/Survey_20240612.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",
|
|
" list1.append(line)\n",
|
|
"#print(list1)\n",
|
|
"dict2 = {}\n",
|
|
"psy =[]\n",
|
|
"tcm = []\n",
|
|
"spine = []\n",
|
|
"for i in range(0,45):\n",
|
|
" psy.append(0)\n",
|
|
"psy[44] = []\n",
|
|
"for i in range(0,60):\n",
|
|
" tcm.append(0)\n",
|
|
"for i in range(0,26):\n",
|
|
" spine.append(0)\n",
|
|
"\n",
|
|
"for item in list1:\n",
|
|
" if item[2] in phone.keys():\n",
|
|
" psy =[]\n",
|
|
" tcm = []\n",
|
|
" spine = []\n",
|
|
" for i in range(0,45):\n",
|
|
" psy.append(0)\n",
|
|
" psy[44] = []\n",
|
|
" for i in range(0,60):\n",
|
|
" tcm.append(0)\n",
|
|
" for i in range(0,26):\n",
|
|
" spine.append(0)\n",
|
|
" \n",
|
|
" content = json.loads(item[5])\n",
|
|
" if phone[item[2]] not in dict1.keys():\n",
|
|
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
|
" #print(item[2])\n",
|
|
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
|
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
|
" for k, v in content.items():\n",
|
|
" if 'psy' in k:\n",
|
|
" i = int(k[3:])\n",
|
|
" psy[i-1] = int(v)\n",
|
|
" if 'tcm' in k:\n",
|
|
" i = int(k[3:])\n",
|
|
" tcm[i-1] = int(v)\n",
|
|
" if 'spine' in k:\n",
|
|
" i = int(k[5:])\n",
|
|
" spine[i-1] = int(v)\n",
|
|
" if 'psy' in item[5]:\n",
|
|
" #for i in range(5,26):\n",
|
|
" # new_valve = 5-psy[i]\n",
|
|
" # psy[i] = new_valve\n",
|
|
" for i in range(26,40):\n",
|
|
" new_valve = 1+psy[i]\n",
|
|
" psy[i] = new_valve\n",
|
|
" \n",
|
|
" dict1[phone[item[2]]]['psy'] = psy\n",
|
|
" if 'tcm' in item[5]:\n",
|
|
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
|
" if 'spine' in item[5]:\n",
|
|
" dict1[phone[item[2]]]['spine'] = spine\n",
|
|
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
|
" #rq =date.fromisoformat('2023-12-08')\n",
|
|
" days = (rq-birth).days \n",
|
|
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
|
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
|
" else:\n",
|
|
" print(item[2])\n",
|
|
"filename = 'data/result_青海家属.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"id": "1f137b9b-b51b-4a7a-baea-b1978e5f00c1",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-12T10:18:43.533220Z",
|
|
"iopub.status.busy": "2024-06-12T10:18:43.532466Z",
|
|
"iopub.status.idle": "2024-06-12T10:18:51.206996Z",
|
|
"shell.execute_reply": "2024-06-12T10:18:51.205814Z",
|
|
"shell.execute_reply.started": "2024-06-12T10:18:43.533131Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"14\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import requests\n",
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"\n",
|
|
"headers = {\n",
|
|
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
|
" }\n",
|
|
"filename = 'data/result_青海家属.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"list1 = []\n",
|
|
"file_path ='./青海家属/'\n",
|
|
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
|
|
"i=0\n",
|
|
"list2 = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" list1 = []\n",
|
|
" mydata = {}\n",
|
|
" \n",
|
|
" id = str(k).rjust(4,\"0\")\n",
|
|
" mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n",
|
|
" mydata['title'] = '青海油田勘探事业部' \n",
|
|
" mydata['subtitle'] = ''\n",
|
|
" mydata['id'] = id\n",
|
|
" mydata['name'] = v['name']\n",
|
|
" if v['sex'] == '男':\n",
|
|
" mydata['gender'] = 'male'\n",
|
|
" else:\n",
|
|
" mydata['gender'] = 'female'\n",
|
|
" \n",
|
|
" mydata['month'] = v['month']\n",
|
|
" mydata['fits'] = {}\n",
|
|
" survey_list = ['tcm','psy','spine']\n",
|
|
" for item in survey_list:\n",
|
|
" if item in v.keys():\n",
|
|
" mydata.setdefault('surveys',{})\n",
|
|
" mydata['surveys'][item] = v[item]\n",
|
|
" \n",
|
|
" \n",
|
|
" #mydata['fits'] = {}\n",
|
|
" for item in list_item:\n",
|
|
" if item in v.keys():\n",
|
|
" mydata.setdefault('fits',{})\n",
|
|
" if item in ['lung','pushup','step','situp']:\n",
|
|
" mark = v[item]['成绩'].split()[0].split('.')[0]\n",
|
|
" else:\n",
|
|
" mark = v[item]['成绩'].split()[0]\n",
|
|
" mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n",
|
|
" #if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n",
|
|
" #if len(mydata['fits']) >2 : \n",
|
|
" list1.append(mydata)\n",
|
|
" list2.append([k,v['name']])\n",
|
|
" i+=1\n",
|
|
" x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n",
|
|
" #print(id,v['name'],x.text)\n",
|
|
" #print(mydata)\n",
|
|
" #x.close()\n",
|
|
"print(i)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "56dfb00b-d907-4d0a-8a12-f39e9db6f6a2",
|
|
"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
|
|
}
|