20231018
This commit is contained in:
1 parent
3e97205f17
commit
61fd173804
4 files changed
+744
-121
No files matched your search
+1
-1
@@ -372,7 +372,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.6"
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
+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",
|
||||
|
||||
+135
-44
@@ -10,26 +10,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"id": "bbba6efc-73cd-4db6-bae7-014724fee731",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-14T10:59:21.792059Z",
|
||||
"iopub.status.busy": "2023-10-14T10:59:21.791573Z",
|
||||
"iopub.status.idle": "2023-10-14T10:59:21.924403Z",
|
||||
"shell.execute_reply": "2023-10-14T10:59:21.923914Z",
|
||||
"shell.execute_reply.started": "2023-10-14T10:59:21.792012Z"
|
||||
}
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
@@ -65,27 +51,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-14T11:00:39.153235Z",
|
||||
"iopub.status.busy": "2023-10-14T11:00:39.152837Z",
|
||||
"iopub.status.idle": "2023-10-14T11:00:39.160327Z",
|
||||
"shell.execute_reply": "2023-10-14T11:00:39.159338Z",
|
||||
"shell.execute_reply.started": "2023-10-14T11:00:39.153204Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
@@ -110,23 +81,23 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "699c6a40-a6ae-4300-9646-708cb85aa5e8",
|
||||
"id": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 手工数据导入数据库"
|
||||
"## 获取人员测试成绩"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "def3f47a-24ef-4815-b63b-2a16b79b4c15",
|
||||
"execution_count": 7,
|
||||
"id": "970e171e-1360-448f-a28c-520ccb8f314a",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-15T06:15:31.143651Z",
|
||||
"iopub.status.busy": "2023-10-15T06:15:31.143188Z",
|
||||
"iopub.status.idle": "2023-10-15T06:15:31.160440Z",
|
||||
"shell.execute_reply": "2023-10-15T06:15:31.159756Z",
|
||||
"shell.execute_reply.started": "2023-10-15T06:15:31.143614Z"
|
||||
"iopub.execute_input": "2023-10-18T02:17:23.733390Z",
|
||||
"iopub.status.busy": "2023-10-18T02:17:23.733131Z",
|
||||
"iopub.status.idle": "2023-10-18T02:17:23.758353Z",
|
||||
"shell.execute_reply": "2023-10-18T02:17:23.757550Z",
|
||||
"shell.execute_reply.started": "2023-10-18T02:17:23.733366Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -135,10 +106,130 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[(496534, 6, 5, 32, '2023-10-15', '2023-10-15 14:00:00'), (496534, 39, 5, 12, '2023-10-15', '2023-10-15 14:00:00'), (496534, 105, 5, 22, '2023-10-15', '2023-10-15 14:00:00'), (496534, 136, 5, 20, '2023-10-15', '2023-10-15 14:00:00'), (496534, 110, 5, 53, '2023-10-15', '2023-10-15 14:00:00'), (496534, 144, 5, 11, '2023-10-15', '2023-10-15 14:00:00'), (496534, 87, 5, 45, '2023-10-15', '2023-10-15 14:00:00'), (496534, 71, 5, 22, '2023-10-15', '2023-10-15 14:00:00'), (496534, 153, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 158, 5, 23, '2023-10-15', '2023-10-15 14:00:00'), (496534, 150, 5, 28, '2023-10-15', '2023-10-15 14:00:00'), (496534, 140, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 138, 5, 35, '2023-10-15', '2023-10-15 14:00:00'), (496534, 137, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 377, 5, 59, '2023-10-15', '2023-10-15 14:00:00'), (496534, 131, 5, 55, '2023-10-15', '2023-10-15 14:00:00'), (496534, 76, 5, 52, '2023-10-15', '2023-10-15 14:00:00'), (496534, 14, 5, 25, '2023-10-15', '2023-10-15 14:00:00'), (496534, 88, 5, 29, '2023-10-15', '2023-10-15 14:00:00'), (496534, 115, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 78, 5, 57, '2023-10-15', '2023-10-15 14:00:00'), (496534, 103, 5, 67, '2023-10-15', '2023-10-15 14:00:00'), (496534, 148, 5, 10, '2023-10-15', '2023-10-15 14:00:00'), (496534, 54, 5, 57, '2023-10-15', '2023-10-15 14:00:00'), (496534, 35, 5, 21, '2023-10-15', '2023-10-15 14:00:00'), (496534, 42, 5, 39, '2023-10-15', '2023-10-15 14:00:00'), (496534, 45, 5, 50, '2023-10-15', '2023-10-15 14:00:00'), (496534, 95, 5, 36, '2023-10-15', '2023-10-15 14:00:00'), (496534, 122, 5, 51, '2023-10-15', '2023-10-15 14:00:00'), (496534, 74, 5, 27, '2023-10-15', '2023-10-15 14:00:00'), (496534, 63, 5, 62, '2023-10-15', '2023-10-15 14:00:00'), (496534, 100, 5, 20, '2023-10-15', '2023-10-15 14:00:00'), (496534, 162, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 43, 5, 50, '2023-10-15', '2023-10-15 14:00:00'), (496534, 149, 5, 49, '2023-10-15', '2023-10-15 14:00:00'), (496534, 127, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 62, 5, 21, '2023-10-15', '2023-10-15 14:00:00'), (496534, 40, 5, 10, '2023-10-15', '2023-10-15 14:00:00'), (496534, 53, 5, 24, '2023-10-15', '2023-10-15 14:00:00')]\n"
|
||||
"141\n",
|
||||
"141\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_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",
|
||||
"#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": "markdown",
|
||||
"id": "d034a61d-1fbd-417b-99bd-277e43ebb678",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 导出测试人员信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||||
"title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
||||
"\n",
|
||||
"filename = 'data/result_北京党校.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"\n",
|
||||
"filename = 'data/北京党校.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict2 = json.load(fl)\n",
|
||||
" \n",
|
||||
"list1 = []\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" list2 = []\n",
|
||||
" list2.append(str(k).rjust(5,'0'))\n",
|
||||
" list2.append(v['name']) \n",
|
||||
" list2.append(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/北京党校.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": null,
|
||||
"id": "def3f47a-24ef-4815-b63b-2a16b79b4c15",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
|
||||
+234
-5
@@ -3,7 +3,9 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bfa33ac5-8fe9-4845-8b1d-56c509afcb83",
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## 体质检测管理"
|
||||
]
|
||||
@@ -786,7 +788,9 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f623d291-8d66-4246-a34f-a051115596ef",
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## 体检报告数据管理"
|
||||
]
|
||||
@@ -1171,10 +1175,235 @@
|
||||
"print(len(dict1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fbb13d70-6601-4421-8deb-26e717c37a8c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 体质问卷管理"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7e0fe102-69d4-425c-bc1f-9a26cc974d9d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 问卷人员导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "714d4a20-9ca0-4439-880b-f68de8c0e2fb",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-18T04:28:34.758506Z",
|
||||
"iopub.status.busy": "2023-10-18T04:28:34.757933Z",
|
||||
"iopub.status.idle": "2023-10-18T04:28:34.828585Z",
|
||||
"shell.execute_reply": "2023-10-18T04:28:34.827501Z",
|
||||
"shell.execute_reply.started": "2023-10-18T04:28:34.758452Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/职工健康提升项目志愿者报名表(汇总).xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
"\n",
|
||||
"for n in range(3, 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['job'] = sheet.cell(n, 3).value\n",
|
||||
" dict1['age'] = int(sheet.cell(n, 6).value)\n",
|
||||
" dict1['phone'] = str(sheet.cell(n,7).value)\n",
|
||||
" dict1['note'] = sheet.cell(n,8).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": "markdown",
|
||||
"id": "e8774dfb-d9f5-44af-a118-4a106ceac9fc",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导入问卷信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "dcdd18b3-d7b7-49b1-b148-c2ea9a7799ff",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-18T04:52:32.821254Z",
|
||||
"iopub.status.busy": "2023-10-18T04:52:32.820749Z",
|
||||
"iopub.status.idle": "2023-10-18T04:52:32.885978Z",
|
||||
"shell.execute_reply": "2023-10-18T04:52:32.885231Z",
|
||||
"shell.execute_reply.started": "2023-10-18T04:52:32.821208Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"3\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import csv\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"filename = 'data/安庆职工健康提升志愿者.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"\n",
|
||||
"wj = {'psy_0556_sh':'心理问卷','tcm_0556_sh':'中医问卷','spine_0556_sh':'脊柱问卷'}\n",
|
||||
"wj_dm = {'psy_0556_sh':0,'tcm_0556_sh':1,'spine_0556_sh':2}\n",
|
||||
"list1 = []\n",
|
||||
"re_ta = {}\n",
|
||||
"filename = 'data/Survey_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",
|
||||
"#print(list1)\n",
|
||||
"for result in list1:\n",
|
||||
" item = str(result[1])\n",
|
||||
" re_ta.setdefault(item,[])\n",
|
||||
" re_ta[item].append(result[2])\n",
|
||||
"print(len(re_ta))\n",
|
||||
"\n",
|
||||
"tj = {}\n",
|
||||
"for k ,v in dict1.items():\n",
|
||||
" phone = v['phone']\n",
|
||||
" tj.setdefault(k, [0,0,0])\n",
|
||||
" for k1,v1 in re_ta.items():\n",
|
||||
" if phone in v1:\n",
|
||||
" tj[k][wj_dm[k1]] = 1\n",
|
||||
"list1 = []\n",
|
||||
"for k, v in tj.items():\n",
|
||||
" list2 = []\n",
|
||||
" list2.append(k)\n",
|
||||
" list2.append(dict1[k]['name'])\n",
|
||||
" list2.append(dict1[k]['phone'])\n",
|
||||
" for item in v:\n",
|
||||
" list2.append(item)\n",
|
||||
" list1.append(list2)\n",
|
||||
" \n",
|
||||
"filename = 'data/安庆职工健康提升问卷情况表.xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"title = ['编号','员工姓名','手机号码','心理','中医','脊柱']\n",
|
||||
"sheet.append(title)\n",
|
||||
"for row in list1:\n",
|
||||
" sheet.append(row)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"wb.save(filename) \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8bc929e2-38f1-4dbd-820e-65d92b59ab26",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导统计问卷新增手机号码"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"id": "ea4fffc4-3c6e-4f85-819f-52f969e04dd7",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-10-18T05:02:18.718756Z",
|
||||
"iopub.status.busy": "2023-10-18T05:02:18.717923Z",
|
||||
"iopub.status.idle": "2023-10-18T05:02:18.745164Z",
|
||||
"shell.execute_reply": "2023-10-18T05:02:18.743072Z",
|
||||
"shell.execute_reply.started": "2023-10-18T05:02:18.718679Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"13865166211\n",
|
||||
"15905566828\n",
|
||||
"18055691637\n",
|
||||
"13855602427\n",
|
||||
"13966613066\n",
|
||||
"18755696791\n",
|
||||
"18055696268\n",
|
||||
"15856585658\n",
|
||||
"13966607917\n",
|
||||
"13855640093\n",
|
||||
"18155688687\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import csv\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"filename = 'data/安庆职工健康提升志愿者.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"\n",
|
||||
"phone = set()\n",
|
||||
"phone1 = set()\n",
|
||||
"for k,v in dict1.items():\n",
|
||||
" phone.add(v['phone'])\n",
|
||||
"\n",
|
||||
"filename = 'data/Survey_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",
|
||||
"#print(list1)\n",
|
||||
"for result in list1:\n",
|
||||
" if result[2] not in phone:\n",
|
||||
" phone1.add(result[2])\n",
|
||||
"for item in phone1:\n",
|
||||
" print(item)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a7219084-9d0a-4027-9d51-5b6cc2f2ec9b",
|
||||
"id": "37bf232e-7db1-40a8-b8d6-4a182f839848",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
@@ -1182,7 +1411,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -1196,7 +1425,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in new issue
Block a user