20231018
This commit is contained in:
1 parent
3e97205f17
commit
61fd173804
4 files changed
+744
-121
No files matched your search
+374
-71
@@ -168,29 +168,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": null,
|
||||
"id": "f32b266a-7e46-4703-ab61-7cbbc81b5ab1",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-06-09T03:17:48.044584Z",
|
||||
"iopub.status.busy": "2023-06-09T03:17:48.044175Z",
|
||||
"iopub.status.idle": "2023-06-09T03:17:48.054183Z",
|
||||
"shell.execute_reply": "2023-06-09T03:17:48.053116Z",
|
||||
"shell.execute_reply.started": "2023-06-09T03:17:48.044557Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[41.3, 46.2, 52.3, 58.8, 68.2]\n",
|
||||
"46.2\n",
|
||||
"1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
@@ -232,29 +215,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"id": "b32fbbdd-eb0a-4f0d-8901-e39a727c3ff8",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-06-09T03:07:07.558861Z",
|
||||
"iopub.status.busy": "2023-06-09T03:07:07.557966Z",
|
||||
"iopub.status.idle": "2023-06-09T03:07:07.572751Z",
|
||||
"shell.execute_reply": "2023-06-09T03:07:07.571714Z",
|
||||
"shell.execute_reply.started": "2023-06-09T03:07:07.558820Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"M30~39\n",
|
||||
"177.7,97.0\n",
|
||||
"1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
@@ -290,6 +256,372 @@
|
||||
"print(score)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7fe0ffe8-c3d1-4843-9765-87d4a12b7c39",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 体测报告生成"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9fec0bfc-8a97-446f-95fe-6e9cf8e482d8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 转换报告格式"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3e614f4a-a623-48e2-97f8-b31f62c9a983",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import datetime\n",
|
||||
"import csv\n",
|
||||
"from datetime import date\n",
|
||||
"\n",
|
||||
"filename = '../item.json'\n",
|
||||
"item = {}\n",
|
||||
"unit = {}\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"for k,v in dict1.items():\n",
|
||||
" item[k] = v\n",
|
||||
"item['1']['en'] = 'lung'\n",
|
||||
"item['2']['en'] = 'grip'\n",
|
||||
"item['3']['en'] = 'flexion'\n",
|
||||
"item['4']['en'] = 'jump'\n",
|
||||
"item['5']['en'] = 'pushup'\n",
|
||||
"item['6']['en'] = 'balance'\n",
|
||||
"item['7']['en'] = 'reaction'\n",
|
||||
"item['8']['en'] = 'step'\n",
|
||||
"item['9']['en'] = 'situp'\n",
|
||||
"item['10']['en'] = 'height'\n",
|
||||
"item['11']['en'] = 'weight'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"re_ta = {}\n",
|
||||
"dict1 = {}\n",
|
||||
"list1 = []\n",
|
||||
"filename = 'data/北京党校.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"\n",
|
||||
"filename = 'data/places_result_20231018.csv'\n",
|
||||
"with open(filename,'r',newline='') as csv_file:\n",
|
||||
" fl = csv.reader(csv_file,delimiter=',')\n",
|
||||
" header = next(fl) \n",
|
||||
" for line in fl:\n",
|
||||
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
||||
" list1.append(line)\n",
|
||||
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
||||
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
||||
"for result in list1:\n",
|
||||
" user = str(result[2])\n",
|
||||
" rq = date.fromisoformat(result[6].replace('/','-'))\n",
|
||||
" if user in dict1.keys():\n",
|
||||
" l_xm = []\n",
|
||||
" m_item = str(result[3]) \n",
|
||||
" re_ta.setdefault(user,{}) \n",
|
||||
" re_ta[user]['name'] = dict1[user]['name']\n",
|
||||
" re_ta[user]['sex'] = dict1[user]['sex']\n",
|
||||
" if dict1[user]['sex'] == '男':\n",
|
||||
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
|
||||
" else:\n",
|
||||
" l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
|
||||
" re_ta[user]['unit'] = dict1[user]['unit']\n",
|
||||
" birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n",
|
||||
" #nian = int(birth[0].strip())\n",
|
||||
" #yue = int(birth[1].strip())\n",
|
||||
" #ri = int(birth[2].strip())\n",
|
||||
" #print(k,nian,yue,ri)\n",
|
||||
" item_name = item[m_item]['en'] \n",
|
||||
" if item_name in l_xm: \n",
|
||||
" days = (rq-birth).days \n",
|
||||
" re_ta[user]['age'] = int(days/365)\n",
|
||||
" re_ta[user]['month'] = int(days/365*12)\n",
|
||||
" re_ta[user]['rq'] = result[6]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" re_ta[user].setdefault(item_name,{}) \n",
|
||||
" score = int(result[4])/item[m_item]['divisor'] \n",
|
||||
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
||||
"print(len(re_ta))\n",
|
||||
"filename = 'data/result_北京党校.json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(re_ta, fl, ensure_ascii=False) \n",
|
||||
"print(len(re_ta))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6741916c-deb6-496f-bc8f-5248e107e0e9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 生成完善得分"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "141b30dc-5975-4dcb-9bc3-9b20d26a0917",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"filename = '../item.json'\n",
|
||||
"item = {}\n",
|
||||
"unit = {}\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict3 = json.load(fl) \n",
|
||||
"for k,v in dict3.items():\n",
|
||||
" item[k] = v\n",
|
||||
"item['1']['en'] = 'lung'\n",
|
||||
"item['2']['en'] = 'grip'\n",
|
||||
"item['3']['en'] = 'flexion'\n",
|
||||
"item['4']['en'] = 'jump'\n",
|
||||
"item['5']['en'] = 'pushup'\n",
|
||||
"item['6']['en'] = 'balance'\n",
|
||||
"item['7']['en'] = 'reaction'\n",
|
||||
"item['8']['en'] = 'step'\n",
|
||||
"item['9']['en'] = 'situp'\n",
|
||||
"item['10']['en'] = 'height'\n",
|
||||
"item['11']['en'] = 'weight'\n",
|
||||
"\n",
|
||||
"filename = 'data/体质检测标准 (1).json' \n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def cal_score(data1):\n",
|
||||
" #data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46} \n",
|
||||
" person = dict1['person']\n",
|
||||
" criteria = dict1['criteria']\n",
|
||||
" if data1['age'] >59:\n",
|
||||
" data1['age'] = 59\n",
|
||||
" if data1['age'] <20:\n",
|
||||
" data1['age'] = 20\n",
|
||||
" info = data1['sex']+str(data1['age'])\n",
|
||||
" bz = person[info]\n",
|
||||
" mx = criteria[bz][data1['item']]\n",
|
||||
" result = data1['result'] \n",
|
||||
" if data1['item'] == 'reaction':\n",
|
||||
" for bz1 in mx:\n",
|
||||
" if result > bz1:\n",
|
||||
" #print(bz1)\n",
|
||||
" score = mx.index(bz1,0)\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" score = 5\n",
|
||||
" else:\n",
|
||||
" for bz1 in mx:\n",
|
||||
" if result < bz1:\n",
|
||||
" #print(bz1)\n",
|
||||
" score = mx.index(bz1,0)\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" score = 5\n",
|
||||
" return(score)\n",
|
||||
"filename = 'data/体质检测标准_BMI.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict4 = json.load(fl) \n",
|
||||
" \n",
|
||||
"def cal_bmi(data1):\n",
|
||||
" # data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
|
||||
" person = dict4['person']\n",
|
||||
" criteria = dict4['criteria']\n",
|
||||
" if data1['age'] > 59:\n",
|
||||
" data1['age'] = 59\n",
|
||||
" if data1['age'] <20:\n",
|
||||
" data1['age'] = 20\n",
|
||||
" info = data1['sex']+str(data1['age'])\n",
|
||||
" bz = person[info]\n",
|
||||
" #print(bz)\n",
|
||||
" result = data1['result']\n",
|
||||
" #print(data1['code'],result)\n",
|
||||
" height = int(float(result.split(',')[0]))\n",
|
||||
" weight = float(result.split(',')[1])\n",
|
||||
" if str(height) not in criteria[bz]:\n",
|
||||
" score = 1\n",
|
||||
" else: \n",
|
||||
" mx = criteria[bz][str(height)]\n",
|
||||
" if weight < mx[0]:\n",
|
||||
" score = 1\n",
|
||||
" elif weight < mx[1]:\n",
|
||||
" score = 3\n",
|
||||
" elif weight < mx[2]:\n",
|
||||
" score = 5 \n",
|
||||
" elif weight <= mx[3]:\n",
|
||||
" score = 3 \n",
|
||||
" elif weight > mx[3]:\n",
|
||||
" score = 1\n",
|
||||
" return score\n",
|
||||
" \n",
|
||||
" \n",
|
||||
"\n",
|
||||
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
|
||||
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
|
||||
"filename = 'data/result_北京党校.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict2 = json.load(fl) \n",
|
||||
"for k, v in dict2.items():\n",
|
||||
" #print(k)\n",
|
||||
" if v['sex'] == '男':\n",
|
||||
" sex = 'M'\n",
|
||||
" else:\n",
|
||||
" sex = 'F' \n",
|
||||
" if 'height' in v.keys() and 'weight' in v.keys():\n",
|
||||
" bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
|
||||
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
|
||||
" dict2[k]['bmi'] = {}\n",
|
||||
" dict2[k]['bmi']['成绩'] = bmi_data\n",
|
||||
" dict2[k]['bmi']['score'] = cal_bmi(data1)\n",
|
||||
" for item_en in list_item:\n",
|
||||
" if item_en in v.keys(): \n",
|
||||
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
|
||||
" dict2[k][item_en]['score'] = cal_score(data1)\n",
|
||||
" #print(k,v[item_en]['成绩'],cal_score(data1))\n",
|
||||
"\n",
|
||||
"filename = f'data/result_北京党校.json'\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||||
"print('ok!') "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "cf8f168e-4161-4fbb-bf5f-f9d1cb9bbb6f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 生成报告清单"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "f20224aa-2131-473d-a0ec-0743482ed58e",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-18T04:07:20.752069Z",
|
||||
"iopub.status.busy": "2023-10-18T04:07:20.751766Z",
|
||||
"iopub.status.idle": "2023-10-18T04:07:20.842528Z",
|
||||
"shell.execute_reply": "2023-10-18T04:07:20.841931Z",
|
||||
"shell.execute_reply.started": "2023-10-18T04:07:20.752043Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"filename = 'data/result_天津231017.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"dict2 = {}\n",
|
||||
"list2 = []\n",
|
||||
"i= 1\n",
|
||||
"p= 1\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" list2.append(k)\n",
|
||||
" i+=1\n",
|
||||
" if i>200:\n",
|
||||
" dict2[p] = list2\n",
|
||||
" p+=1\n",
|
||||
" i = 1\n",
|
||||
" list2 = []\n",
|
||||
"dict2[p] = list2\n",
|
||||
"filename = f'报告清单.json'\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict2,fl , ensure_ascii=False) \n",
|
||||
"print('ok!') "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ceef0742-f62a-4a7d-b0d5-be7ae7abb741",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 生成报告"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b123ee6b-85d2-4660-b226-321832a6b796",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"headers = {\n",
|
||||
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
|
||||
" }\n",
|
||||
"filename = 'data/result_天津231017.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
"fiie_path ='./134/'\n",
|
||||
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
|
||||
"i=1\n",
|
||||
"list2 = []\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" list1 = []\n",
|
||||
" mydata = {}\n",
|
||||
" \n",
|
||||
" id = str(k).rjust(8,\"0\")\n",
|
||||
" mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n",
|
||||
" mydata['title'] = '中石化(天津)石油化工\\n有限公司'\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",
|
||||
" for item in list_item:\n",
|
||||
" if item in v.keys():\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: \n",
|
||||
" list1.append(mydata)\n",
|
||||
" list2.append([k,v['name']])\n",
|
||||
" i+=1\n",
|
||||
" x = requests.post('http://192.168.1.148:3003', data = json.dumps(list1), headers=headers)\n",
|
||||
" print(id,v['name'],x.text)\n",
|
||||
" #x.close()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "732161bb-98f2-4861-ab66-7a374678bcd8",
|
||||
@@ -895,16 +1227,9 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"id": "cf345bf0-f11b-459e-9b69-b2843836f6f3",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-08-29T13:51:03.280856Z",
|
||||
"iopub.status.busy": "2023-08-29T13:51:03.280394Z",
|
||||
"iopub.status.idle": "2023-08-29T13:51:03.399330Z",
|
||||
"shell.execute_reply": "2023-08-29T13:51:03.398909Z",
|
||||
"shell.execute_reply.started": "2023-08-29T13:51:03.280807Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -930,16 +1255,9 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"id": "1acaf159-637e-4101-9881-f6bb79400136",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-05-19T09:08:35.287714Z",
|
||||
"iopub.status.busy": "2023-05-19T09:08:35.286693Z",
|
||||
"iopub.status.idle": "2023-05-19T09:08:35.304177Z",
|
||||
"shell.execute_reply": "2023-05-19T09:08:35.303461Z",
|
||||
"shell.execute_reply.started": "2023-05-19T09:08:35.287667Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -957,27 +1275,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"id": "ad3078ac-ae53-4bb4-95bd-387631092bf1",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-05-20T04:06:02.667541Z",
|
||||
"iopub.status.busy": "2023-05-20T04:06:02.667013Z",
|
||||
"iopub.status.idle": "2023-05-20T04:06:02.681377Z",
|
||||
"shell.execute_reply": "2023-05-20T04:06:02.680428Z",
|
||||
"shell.execute_reply.started": "2023-05-20T04:06:02.667502Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'_id': ObjectId('64673c9319e8481e9c0ad1a3'), 'place': '714309', 'code': '4', 'name': '朱维'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pymongo\n",
|
||||
"\n",
|
||||
|
||||
Reference in new issue
Block a user