From c428bebaba1bd3663b94058566b14df5747b61f6 Mon Sep 17 00:00:00 2001 From: 512song Date: Wed, 17 Jan 2024 12:54:42 +0800 Subject: [PATCH] 20240117 --- 体测单位/体测数据管理.ipynb | 23 ++- 体测单位/体质检测数据处理.ipynb | 25 ++- 体测单位/安庆石化.ipynb | 320 +++++++++++++++++++++++--------- 3 files changed, 271 insertions(+), 97 deletions(-) diff --git a/体测单位/体测数据管理.ipynb b/体测单位/体测数据管理.ipynb index 0355a40..2d34c53 100644 --- a/体测单位/体测数据管理.ipynb +++ b/体测单位/体测数据管理.ipynb @@ -273,12 +273,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "id": "25a269c3-758f-4e79-ae6d-a6e6f161d64b", "metadata": { + "execution": { + "iopub.execute_input": "2024-01-04T05:07:18.373605Z", + "iopub.status.busy": "2024-01-04T05:07:18.373107Z", + "iopub.status.idle": "2024-01-04T05:07:18.666664Z", + "shell.execute_reply": "2024-01-04T05:07:18.665504Z", + "shell.execute_reply.started": "2024-01-04T05:07:18.373566Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+8613810428462 send success\n" + ] + } + ], "source": [ "from tencentcloud.common import credential\n", "from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n", @@ -290,8 +305,8 @@ "\n", "\n", "\n", - "phone = '+86'+'13520300915'\n", - "yzm = '036578'\n", + "phone = '+86'+'13810428462'\n", + "yzm = '033716'\n", "try: \n", " secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n", " secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n", diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index dc1ee95..92d856c 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -548,12 +548,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 100, "id": "b123ee6b-85d2-4660-b226-321832a6b796", "metadata": { + "execution": { + "iopub.execute_input": "2024-01-03T15:42:44.653385Z", + "iopub.status.busy": "2024-01-03T15:42:44.652940Z", + "iopub.status.idle": "2024-01-03T15:42:59.566347Z", + "shell.execute_reply": "2024-01-03T15:42:59.565824Z", + "shell.execute_reply.started": "2024-01-03T15:42:44.653349Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "43\n" + ] + } + ], "source": [ "import requests\n", "import json\n", @@ -577,7 +592,7 @@ " \n", " id = str(k).rjust(4,\"0\")\n", " mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n", - " mydata['title'] = '中国农业银行股份有限公司'\n", + " mydata['title'] = '中国石化化工销售'\n", " mydata['subtitle'] = v['unit']\n", " mydata['id'] = id\n", " mydata['name'] = v['name']\n", @@ -604,8 +619,8 @@ " 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", - " \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", diff --git a/体测单位/安庆石化.ipynb b/体测单位/安庆石化.ipynb index 4c97bd7..04936ca 100644 --- a/体测单位/安庆石化.ipynb +++ b/体测单位/安庆石化.ipynb @@ -1170,54 +1170,43 @@ { "cell_type": "markdown", "id": "7e0fe102-69d4-425c-bc1f-9a26cc974d9d", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ "### 问卷人员导入" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "714d4a20-9ca0-4439-880b-f68de8c0e2fb", "metadata": { - "execution": { - "iopub.execute_input": "2023-12-12T04:23:01.972390Z", - "iopub.status.busy": "2023-12-12T04:23:01.971582Z", - "iopub.status.idle": "2023-12-12T04:23:02.066623Z", - "shell.execute_reply": "2023-12-12T04:23:02.064926Z", - "shell.execute_reply.started": "2023-12-12T04:23:01.972317Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok\n" - ] - } - ], + "outputs": [], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", - "wb = openpyxl.load_workbook('data/副本2023年安庆石化职工健康提升项目志愿者花名册.xlsx')\n", + "wb = openpyxl.load_workbook('data/2023年安庆石化职工健康提升项目志愿者花名册(修订).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", + "for n in range(4, sheet.max_row+1):\n", + " code = 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['phone'] = str(sheet.cell(n,5).value)\n", + " dict1['age'] = sheet.cell(n, 6).value\n", + " if sheet.cell(n,5).value is not None:\n", + " dict1['phone'] = str(sheet.cell(n,5).value) \n", " person[code] = dict1\n", - "filename = 'data/安庆职工健康提升志愿者1.json'\n", + "filename = 'data/安庆职工健康提升志愿者.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" @@ -1225,41 +1214,136 @@ }, { "cell_type": "markdown", - "id": "e8774dfb-d9f5-44af-a118-4a106ceac9fc", + "id": "d5babc67-d982-46d0-b6a4-bb8d8ad05895", "metadata": {}, "source": [ - "### 导入问卷信息" + "### 导入问卷内容" ] }, { "cell_type": "code", - "execution_count": 31, - "id": "dcdd18b3-d7b7-49b1-b148-c2ea9a7799ff", + "execution_count": null, + "id": "c5a9111d-2785-4d88-9cbd-0cbc952531b0", "metadata": { - "execution": { - "iopub.execute_input": "2023-12-12T04:23:54.507193Z", - "iopub.status.busy": "2023-12-12T04:23:54.506388Z", - "iopub.status.idle": "2023-12-12T04:23:54.583968Z", - "shell.execute_reply": "2023-12-12T04:23:54.582552Z", - "shell.execute_reply.started": "2023-12-12T04:23:54.507133Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "dict1 = {}\n", + "\n", + "filename = 'data/安庆职工健康提升志愿者.json'\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl)\n", + "\n", + "\n", + "list1 = []\n", + "filename = 'data/Survey_20240117.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", + "\n", + "for item in list1:\n", + " psy = []\n", + " tcm = []\n", + " spine = []\n", + " for i in range(0,45):\n", + " psy.append(0)\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for i in range(0,26):\n", + " spine.append(0)\n", + " phone = item[2]\n", + " for k1, v1 in dict3.items():\n", + " if 'phone' in v1.keys() and phone ==v1['phone']: \n", + " dict1[k1] = dict3[k1]\n", + " dict1[k1]['month'] = dict1[k1]['age'] *12\n", + "#print(dict1)\n", + "for item in list1:\n", + " psy = []\n", + " tcm = []\n", + " spine = []\n", + " for i in range(0,45):\n", + " psy.append(0)\n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " for i in range(0,26):\n", + " spine.append(0)\n", + " phone = item[2]\n", + " for k1, v1 in dict1.items():\n", + " if phone ==v1['phone']: \n", + " content = json.loads(item[5])\n", + " if 'tcm' in item[1] or 'spine' in item[1]:\n", + " del content['gender']\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 item[1]: \n", + " i = int(k[1:])\n", + " psy[i-1] = int(v)\n", + " if 'tcm' in item[1]: \n", + " i = int(k[1:])\n", + " tcm[i-1] = int(v)\n", + " if 'spine' in item[1]:\n", + " i = int(k[1:])\n", + " spine[i-1] = int(v)\n", + " if 'psy' in item[1]:\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", + " psy[44] = []\n", + " dict1[k1]['psy'] = psy\n", + " if 'tcm' in item[1]:\n", + " dict1[k1]['tcm'] = tcm\n", + " if 'spine' in item[1]:\n", + " dict1[k1]['spine'] = spine\n", + " #birth = date.fromisoformat(dict3[k1]['birth'].replace('/','-'))\n", + "\n", + " #days = (rq-birth).days \n", + " #dict1[k1]['age'] = int(days/365)\n", + " \n", + " dict1[k1]['rq'] = item[6].replace('/','-').split(' ')[0]\n", + "print(dict1)\n", + "filename = 'data/result_安庆志愿者.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False) " + ] + }, + { + "cell_type": "markdown", + "id": "e8774dfb-d9f5-44af-a118-4a106ceac9fc", + "metadata": {}, + "source": [ + "### 导出问卷人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dcdd18b3-d7b7-49b1-b148-c2ea9a7799ff", + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ "import json\n", "import csv\n", "import openpyxl\n", "\n", - "filename = 'data/安庆职工健康提升志愿者1.json'\n", + "filename = 'data/安庆职工健康提升志愿者.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", @@ -1267,7 +1351,7 @@ "wj_dm = {'psy_0556_sh':0,'tcm_0556_sh':1,'spine_0556_sh':2}\n", "list1 = []\n", "re_ta = {}\n", - "filename = 'data/Survey_20231211-1702260996888.csv'\n", + "filename = 'data/Survey_20240117.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -1283,11 +1367,12 @@ "\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", + " if 'phone' in v.keys():\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", @@ -1298,7 +1383,7 @@ " list2.append(item)\n", " list1.append(list2)\n", " \n", - "filename = 'data/安庆职工健康提升问卷情况表20231212.xlsx'\n", + "filename = 'data/安庆职工健康提升问卷情况表20240108.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "title = ['编号','员工姓名','手机号码','心理','中医','脊柱']\n", @@ -1319,45 +1404,12 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "ea4fffc4-3c6e-4f85-819f-52f969e04dd7", "metadata": { - "execution": { - "iopub.execute_input": "2023-12-12T04:06:50.977355Z", - "iopub.status.busy": "2023-12-12T04:06:50.976552Z", - "iopub.status.idle": "2023-12-12T04:06:51.007761Z", - "shell.execute_reply": "2023-12-12T04:06:51.005174Z", - "shell.execute_reply.started": "2023-12-12T04:06:50.977281Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "18055696268\n", - "13865166211\n", - "13966607917\n", - "13855640093\n", - "18155688687\n", - "15156230686\n", - "13074076020\n", - "18655663060\n", - "15905566828\n", - "13905562130\n", - "13855602427\n", - "13966613066\n", - "15856585658\n", - "13909669602\n", - "18055691637\n", - "18755696791\n", - "19955611658\n", - "13966637322\n", - "13955603120\n" - ] - } - ], + "outputs": [], "source": [ "import json\n", "import csv\n", @@ -1370,9 +1422,10 @@ "phone = set()\n", "phone1 = set()\n", "for k,v in dict1.items():\n", - " phone.add(v['phone'])\n", + " if 'phone' in v.keys():\n", + " phone.add(v['phone'])\n", "\n", - "filename = 'data/Survey_20231211-1702260996888.csv'\n", + "filename = 'data/Survey_20240108.csv'\n", "with open(filename,'r',newline='') as csv_file:\n", " fl = csv.reader(csv_file,delimiter=',')\n", " header = next(fl) \n", @@ -1421,6 +1474,97 @@ "for item in phone1:\n", " print(item)" ] + }, + { + "cell_type": "markdown", + "id": "40b39da5-67e2-4d98-a7b7-175086dd12c8", + "metadata": {}, + "source": [ + "### 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "49880f85-6cda-44a6-a77f-3abd10672d7a", + "metadata": { + "execution": { + "iopub.execute_input": "2024-01-17T04:40:13.175154Z", + "iopub.status.busy": "2024-01-17T04:40:13.174675Z", + "iopub.status.idle": "2024-01-17T04:40:29.104763Z", + "shell.execute_reply": "2024-01-17T04:40:29.103968Z", + "shell.execute_reply.started": "2024-01-17T04:40:13.175118Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "98\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", + "fiie_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'] = fiie_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", + " \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": "319df381-b4fc-4795-8769-df9cd25bd04a", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {