diff --git a/体测单位/东营杨庙202307.ipynb b/体测单位/东营杨庙202307.ipynb new file mode 100644 index 0000000..3bbed6d --- /dev/null +++ b/体测单位/东营杨庙202307.ipynb @@ -0,0 +1,863 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0deffb8b-6ff0-4a87-b733-08dde1494994", + "metadata": {}, + "source": [ + "## 杨庙人员信息导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4bd7851-d612-4387-a8b2-5173eac8f866", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "\n", + "wb = openpyxl.load_workbook('data/杨庙社区居民信息表20230801(系统导入版).xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "person = {}\n", + "\n", + "for n in range(2, sheet.max_row+1):\n", + " if sheet.cell(n,1).value is not None:\n", + " code = int(sheet.cell(n, 1).value)\n", + " person.setdefault(code, {})\n", + " dict1 = {}\n", + " dict1['name'] = sheet.cell(n, 2).value\n", + " dict1['sex'] = sheet.cell(n, 3).value\n", + " birth = str(sheet.cell(n, 4).value).split()[0]\n", + " dict1['birth'] = birth \n", + " person[code] = dict1\n", + "\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(person, fl, ensure_ascii=False)\n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "fc2c5182-e10c-45eb-841d-d6083ddfde53", + "metadata": {}, + "source": [ + "## 检测问卷编号重复" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8eff79b-3c8c-45e3-8127-6e863008ad4a", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + "wb = openpyxl.load_workbook('data/杨庙问卷统计表(老年组).xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "dict1 = {}\n", + "dict3 = {}\n", + "sheet = wb.active\n", + "data1 =list(sheet.values)\n", + "list_bh = data1[0][1:]\n", + "list1 = []\n", + "for item in list_bh:\n", + " if item not in list1:\n", + " list1.append(item)\n", + " else:\n", + " print(item)\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "26d77f4b-6ba1-45b3-8955-9ae481b9ae9c", + "metadata": {}, + "source": [ + "## 导入手工体测数据" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ccfac27a-b255-4263-9ce0-c606d82f6473", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + "wb = openpyxl.load_workbook('data/杨庙手工数据(数据库).xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "dict1 = {}\n", + "dict3 = {1:10,2:11,3:7,4:2,5:6,6:3,7:1}\n", + "sheet = wb.active\n", + "data1 =list(sheet.values)\n", + "del data1[0]\n", + "list1 = []\n", + "for item in data1:\n", + " code = item[0]\n", + " if str(code) in dict2.keys():\n", + " for i in range(1,8):\n", + " if item[i] is not None:\n", + " list1.append((141,code,dict3[i],item[i],'2023-08-03','2023-08-03 12:00:00'))\n", + "print(list1)\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "e4bbd0db-090b-4252-ae27-d9e589f97992", + "metadata": {}, + "source": [ + "## 导出体测信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e77ef529-0522-4f8d-a4d3-9f62a69f6cc6", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import datetime\n", + "import csv\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for k,v in dict1.items():\n", + " item[k] = v\n", + "item['1']['en'] = 'lung'\n", + "item['2']['en'] = 'grip'\n", + "item['3']['en'] = 'flexion'\n", + "item['6']['en'] = 'balance'\n", + "item['7']['en'] = 'reaction'\n", + "item['10']['en'] = 'height'\n", + "item['11']['en'] = 'weight'\n", + "#print(item)\n", + "re_ta = {}\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "filename = 'data/places_result_20230803.csv'\n", + "with open(filename,'r',newline='') as csv_file:\n", + " fl = csv.reader(csv_file,delimiter=',')\n", + " header = next(fl) \n", + " for line in fl:\n", + " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", + " list1.append(line)\n", + "#print(list1)\n", + "for result in list1:\n", + " user = str(result[2])\n", + " if user in dict1.keys(): \n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " re_ta[user]['name'] = dict1[user]['name']\n", + " re_ta[user]['sex'] = dict1[user]['sex'] \n", + " re_ta[user]['birth'] = dict1[user]['birth']\n", + " item_name = item[str(m_item)]['en']\n", + " re_ta[user].setdefault(item_name,{}) \n", + " performance = int(result[4])/item[m_item]['divisor']\n", + " score = result[5]\n", + " re_ta[user][item_name]['成绩'] = performance\n", + " re_ta[user][item_name]['得分'] = score\n", + "list2 = ['grip','lung','balance','reaction','flexion']\n", + "list3 = []\n", + "for k, v in re_ta.items():\n", + " dict2 = {}\n", + " dict2['id'] = int(k)\n", + " dict2['title'] = '杨庙社区'\n", + " dict2['subtitle'] = ''\n", + " dict2['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " dict2['gender'] = 'male'\n", + " else:\n", + " dict2['gender'] = 'female'\n", + " birth = v['birth'].split()[0].split('-') \n", + " nian = int(birth[0].strip())\n", + " yue = int(birth[1].strip())\n", + " ri = int(birth[2].strip())\n", + " #print(k,nian,yue,ri)\n", + " days = (datetime.date(2023, 7, 31)-datetime.date(nian,yue,ri)).days\n", + " dict2['month'] = int(days/30)\n", + " dict3 = {} \n", + " for xm in list2:\n", + " if xm in v.keys():\n", + " dict3[xm] = {'mark':str(v[xm]['成绩']),'score':int(v[xm]['得分'])}\n", + " if 'height' in v.keys():\n", + " dict3['bmi'] = {'mark':str(v['height']['成绩'])+','+str(v['weight']['成绩']),'score':int(v['weight']['得分'])}\n", + " dict2['fit'] = dict3\n", + " list3.append(dict2)\n", + "print(list3) \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e81e3731-1376-4f9d-87fb-83ba1e498047", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import datetime\n", + "import csv\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for k,v in dict1.items():\n", + " item[k] = v\n", + "item['1']['en'] = 'lung'\n", + "item['2']['en'] = 'grip'\n", + "item['3']['en'] = 'flexion'\n", + "item['6']['en'] = 'balance'\n", + "item['7']['en'] = 'reaction'\n", + "item['10']['en'] = 'height'\n", + "item['11']['en'] = 'weight'\n", + "#print(item)\n", + "re_ta = {}\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "filename = 'data/places_result_20230803.csv'\n", + "with open(filename,'r',newline='') as csv_file:\n", + " fl = csv.reader(csv_file,delimiter=',')\n", + " header = next(fl) \n", + " for line in fl:\n", + " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", + " list1.append(line)\n", + "#print(list1)\n", + "for result in list1:\n", + " user = str(result[2])\n", + " if user in dict1.keys(): \n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " re_ta[user]['name'] = dict1[user]['name']\n", + " re_ta[user]['sex'] = dict1[user]['sex'] \n", + " re_ta[user]['birth'] = dict1[user]['birth']\n", + " item_name = item[str(m_item)]['en']\n", + " re_ta[user].setdefault(item_name,{}) \n", + " performance = int(result[4])/item[m_item]['divisor']\n", + " score = result[5]\n", + " re_ta[user][item_name]['成绩'] = performance\n", + " re_ta[user][item_name]['得分'] = score\n", + "list2 = ['grip','lung','balance','reaction','flexion']\n", + "list3 = []\n", + "result = {}\n", + "for k, v in re_ta.items():\n", + " dict2 = {}\n", + " dict2['id'] = int(k)\n", + " dict2['title'] = '杨庙社区'\n", + " dict2['subtitle'] = ''\n", + " dict2['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " dict2['gender'] = 'male'\n", + " else:\n", + " dict2['gender'] = 'female'\n", + " birth = v['birth'].split()[0].split('-') \n", + " nian = int(birth[0].strip())\n", + " yue = int(birth[1].strip())\n", + " ri = int(birth[2].strip())\n", + " #print(k,nian,yue,ri)\n", + " days = (datetime.date(2023, 7, 31)-datetime.date(nian,yue,ri)).days\n", + " dict2['month'] = int(days/30)\n", + " dict3 = {} \n", + " for xm in list2:\n", + " if xm in v.keys():\n", + " mark = v[xm]['成绩']\n", + " if xm == 'lung':\n", + " mark = int(mark)\n", + " \n", + " dict3[xm] = {'mark':str(mark),'score':int(v[xm]['得分'])}\n", + " if 'height' in v.keys():\n", + " dict3['bmi'] = {'mark':str(v['height']['成绩'])+','+str(v['weight']['成绩']),'score':int(v['weight']['得分'])}\n", + " dict2['fit'] = dict3\n", + " result[k] = dict2\n", + "\n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(result, fl) \n", + "print('ok') " + ] + }, + { + "cell_type": "markdown", + "id": "0c6da346-3406-40ad-a44a-0a47c0d6112a", + "metadata": {}, + "source": [ + "## 规范身高体重" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a814c55f-30af-4260-8885-3a6295a48fd7", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "filename = 'data/result_杨庙2308.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for k, v in dict1.items():\n", + " if 'bmi' in v['fit'].keys():\n", + " old = v['fit']['bmi']['mark']\n", + " height = old.split(',')[0]\n", + " weight = old.split(',')[1]\n", + " w = round(float(weight),1)\n", + " v['fit']['bmi']['mark'] = height+','+str(w)\n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False) \n", + "print('ok') " + ] + }, + { + "cell_type": "markdown", + "id": "1ddd3641-94bf-4994-84da-8d97286cbfeb", + "metadata": {}, + "source": [ + "## 问卷信息导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c56c463-2f13-4f74-bb3a-760b284360bf", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "filename = 'data/杨庙社区人员信息2307.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + "wb = openpyxl.load_workbook('data/杨庙问卷统计表(老年组).xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "dict1 = {}\n", + "dict3 = {}\n", + "sheet = wb.active\n", + "data1 =list(sheet.values)\n", + "list_bh = data1[0][1:]\n", + "#print(list_bh)\n", + "del data1[0]\n", + "for i in range(1,len(list_bh)+1):\n", + " list2 = []\n", + " \n", + " for item in data1:\n", + " list2.append(item[i])\n", + " dict1[list_bh[i-1]] = list2\n", + "filename = 'data/result_杨庙2308.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + "for k,v in dict1.items():\n", + " if str(k) in dict2.keys():\n", + " if v[0] is not None:\n", + " psy_yangmiao_old = v[:30]\n", + " #dict2[str(k)]['psy_yangmiao_old'] = psy_yangmiao_old\n", + " if v[30] is not None:\n", + " tcm = v[30:90]\n", + " #print(tcm,len(tcm))\n", + " if v[90] is not None:\n", + " spine = v[90:]\n", + " xx22 = spine[21]\n", + " xx23 = spine[22]\n", + " spine[21] = xx23\n", + " spine[22] = xx22\n", + " \n", + " dict2[str(k)]['psy_yangmiao_old'] = psy_yangmiao_old\n", + " dict2[str(k)]['tcm'] = tcm\n", + " dict2[str(k)]['spine'] = spine\n", + "filename = 'data/result_杨庙2308.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2, fl, ensure_ascii=False) \n", + "print('ok') " + ] + }, + { + "cell_type": "markdown", + "id": "77995e6a-86e4-49bb-a937-de38e13f1bd4", + "metadata": {}, + "source": [ + "## 单份报告生成" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "edcd9c2d-7254-493d-82e0-55556700330b", + "metadata": { + "execution": { + "iopub.execute_input": "2023-08-16T08:53:29.466349Z", + "iopub.status.busy": "2023-08-16T08:53:29.465563Z", + "iopub.status.idle": "2023-08-16T08:53:30.567398Z", + "shell.execute_reply": "2023-08-16T08:53:30.566465Z", + "shell.execute_reply.started": "2023-08-16T08:53:29.466307Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{\"errmsg\":\"ok\"}\n" + ] + } + ], + "source": [ + "import requests\n", + "import json\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "\n", + "mydata ={\"path\":\"./于先生体测报告.pdf\",\n", + " \"id\":\"00001\",\n", + " \"title\":\"社区测试报告\",\n", + " \"name\":\"于先生\",\n", + " \"gender\":\"male\",\n", + " \"month\":725,\n", + " \"fit\":{\"grip\":{\"mark\":\"40.9\",\"score\":2},\n", + " \"bmi\":{\"mark\":\"181.2,81.3\",\"score\":5},\n", + " \"lung\":{\"mark\":\"4590\",\"score\":5},\n", + " \"balance\":{\"mark\":\"57.2\",\"score\":4},\n", + " \"reaction\":{\"mark\":\"0.466\",\"score\":4},\n", + " \"flexion\":{\"mark\":\"-11.6\",\"score\":0},\n", + " \"jump\":{\"mark\":\"26.3\",\"score\":2},\n", + " \"pushup\":{\"mark\":\"3\",\"score\":1},\n", + " \"step\":{\"mark\":\"43\",\"score\":1}\n", + " },\n", + " \"surveys\":{\"tcm\":[3,3,3,2,2,3,1,3,3,1,1,2,3,4,1,1,2,3,4,1,2,4,2,2,4,5,5,3,1,3,3,2,3,4,3,3,2,3,3,3,3,2,4,3,5,2,3,3,2,1,3,4,3,3,3,3,1,1,2,3],\"psy_yangmiao_old\":[3,3,2,3,3,3,4,4,4,1,4,4,4,4,5,5,5,3,4,3,3,4,4,3,4,4,3,4,3,3],\"spine\":[1,2,1,2,1,2,2,1,2,2,1,2,2,2,1,1,1,1,1,2,2,2,2,2,1,2]}}\n", + "print(type(json.dumps(mydata)))\n", + "x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n", + "print(x.text)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "0b528b37-18f5-4b05-bfad-73be35b120cc", + "metadata": { + "execution": { + "iopub.execute_input": "2023-08-26T01:22:01.984551Z", + "iopub.status.busy": "2023-08-26T01:22:01.983645Z", + "iopub.status.idle": "2023-08-26T01:22:02.822718Z", + "shell.execute_reply": "2023-08-26T01:22:02.821896Z", + "shell.execute_reply.started": "2023-08-26T01:22:01.984511Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "{\"errmsg\":\"ok\"}\n" + ] + } + ], + "source": [ + "import requests\n", + "import json\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "\n", + "mydata ={\"path\":\"./00343-殷焕章.pdf\",\n", + " \"id\":\"00343\",\n", + " \"title\":\"东营羊庙社区\",\n", + " \"name\":\"殷焕章\",\n", + " \"gender\":\"male\",\n", + " \"month\":992,\n", + " \"fit\":{\"grip\":{\"mark\":\"20.6\",\"score\":0},\n", + " \"bmi\":{\"mark\":\"160.4,60.0\",\"score\":5},\n", + " \"lung\":{\"mark\":\"1703\",\"score\":1},\n", + " \"balance\":{\"mark\":\"3.9\",\"score\":2},\n", + " \"reaction\":{\"mark\":\"1.519\",\"score\":0},\n", + " \"flexion\":{\"mark\":\"8.9\",\"score\":4}\n", + " }\n", + " }\n", + "print(type(json.dumps(mydata)))\n", + "x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n", + "print(x.text)" + ] + }, + { + "cell_type": "markdown", + "id": "27068dd5-8312-45c3-bbff-9f21646e895b", + "metadata": {}, + "source": [ + "## 报告生成" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ad7eb19-d49d-4f28-b7f7-4776bf443946", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "fiie_path ='./141/'\n", + "dict2 = {}\n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(5,\"0\")\n", + " mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '东营杨庙社区'\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " mydata['gender'] = v['gender'] \n", + " mydata['month'] = v['month']\n", + " if 'fit' in v.keys():\n", + " dict2 = {}\n", + " for k1, v1 in v['fit'].items():\n", + " dict2[k1] = v1\n", + " mydata['fit'] = dict2\n", + " #data['surveys'] = {}\n", + " for item in ('tcm','psy_yangmiao_old','spine'):\n", + " if item in v.keys():\n", + " mydata.setdefault('surveys',{})\n", + " dict2 = {} \n", + " mydata['surveys'][item] = v[item]\n", + " list1.append(mydata) \n", + " #x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n", + " #print(id,v['name'],x.text)\n", + " #x.close()\n", + " #if k =='218':\n", + " # print(mydata)\n", + "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", + "\n", + "# 将 json 数据写入文件\n", + "with open(\"data1.json\", \"w\",encoding = 'utf-8') as file:\n", + " file.write(json_data) \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a01e1b1-778b-4dc8-99e5-f597f10f30a1", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "import time\n", + "from pathlib import Path\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "file_path ='/home/songyi/pdf-typescript-master/141/'\n", + "dict2 = {}\n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " id = str(k).rjust(5,\"0\")\n", + " fn = file_path+id+'-'+ v['name']+'.pdf'\n", + " \n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(5,\"0\")\n", + " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '东营杨庙社区'\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " mydata['gender'] = v['gender'] \n", + " mydata['month'] = v['month']\n", + " if 'fit' in v.keys():\n", + " dict2 = {}\n", + " for k1, v1 in v['fit'].items():\n", + " dict2[k1] = v1\n", + " mydata['fit'] = dict2\n", + " #data['surveys'] = {}\n", + " for item in ('tcm','psy_yangmiao_old','spine'):\n", + " if item in v.keys():\n", + " mydata.setdefault('surveys',{})\n", + " dict2 = {} \n", + " mydata['surveys'][item] = v[item]\n", + " \n", + " x = requests.post('http://10.11.12.4:3003', data = json.dumps(mydata), headers=headers)\n", + " print(id,v['name'],x.text)\n", + " x.close()\n", + " time.sleep(0.05)\n", + " #if k =='218':\n", + " # print(mydata)" + ] + }, + { + "cell_type": "markdown", + "id": "4e80d173-8cba-46d0-86fd-4c031a649a00", + "metadata": {}, + "source": [ + "## 生成报告人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6f69631c-e2d7-431b-8114-c4bb45e394e7", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "\n", + "\n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " id = str(k).rjust(5,\"0\")\n", + " \n", + " name = v['name']\n", + " list1.append([id,name])\n", + "filename = 'data/杨庙测试2023年8月报告明细表.xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "\n", + "for row in list1:\n", + " sheet.append(row)\n", + "wb.save(filename)" + ] + }, + { + "cell_type": "markdown", + "id": "aa34d7f2-9b6c-42c8-b777-60cc0c48a3a3", + "metadata": {}, + "source": [ + "## 统计报告页数" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed2f8014-57c7-40d1-979f-f2d4818c748b", + "metadata": {}, + "outputs": [], + "source": [ + "import pdfplumber\n", + "import glob\n", + "\n", + "file_path ='/home/songyi/pdf-typescript-master/141/'\n", + "fls=glob.glob('/home/songyi/pdf-typescript-master/141/*.pdf')\n", + "n = 0\n", + "for fl in fls:\n", + " pdf = pdfplumber.open(fl)\n", + " n= n+len(pdf.pages)\n", + " print(fl,len(pdf.pages))\n", + "print(n)" + ] + }, + { + "cell_type": "markdown", + "id": "6a867a50-3a97-47c3-8805-0b39b1137173", + "metadata": {}, + "source": [ + "## 导入202303月体测信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2bafc0b8-e849-4be7-8438-ba9fd2b87870", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import time\n", + "import csv\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for k,v in dict1.items():\n", + " item[k] = v\n", + "re_ta = {}\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/杨庙体测明确人员信息(20230328).json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "\n", + "filename = 'data/places_result_20230812.csv'\n", + "with open(filename,'r',newline='') as csv_file:\n", + " fl = csv.reader(csv_file,delimiter=',')\n", + " header = next(fl) \n", + " for line in fl:\n", + " #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", + " list1.append(line)\n", + "#print(list1)\n", + "for result in list1:\n", + " user = str(result[2])\n", + " if user in dict1.keys():\n", + " \n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " re_ta[user]['name'] = dict1[user]['name']\n", + " re_ta[user]['sex'] = dict1[user]['sex'] \n", + " re_ta[user]['部门'] = dict1[user]['unit']\n", + " item_name = item[m_item]['name']\n", + " re_ta[user].setdefault(item_name,{}) \n", + " score = int(result[4])/item[m_item]['divisor'] \n", + " re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n", + " re_ta[user][item_name]['得分'] = result[5]\n", + "print(len(re_ta))\n", + "filename = 'data/result_杨庙社区2303.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(re_ta, fl) \n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "761bd7a5-ef80-4fb9-b64e-983c8e788e2c", + "metadata": {}, + "source": [ + "## 对应两次测试信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4da3291-ebec-4fc9-aaa0-6ecf836c5ff2", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "dict4 = {\n", + " 'lung':'肺活量',\n", + " 'grip':'握力',\n", + " 'flexion' : '坐位体前屈',\n", + " 'balance' : '单脚站立',\n", + " 'reaction' : '选择反应时'\n", + "}\n", + "\n", + "wb = openpyxl.load_workbook('data/副本杨庙测试2023年8月报告明细表.xlsx')\n", + "sheet = wb.active\n", + "items = ['bmi','lung','grip','flexion','balance','reaction']\n", + "dict1 = {}\n", + "for n in range(2, sheet.max_row+1):\n", + " if sheet.cell(n,1).value is not None:\n", + " code = str(sheet.cell(n, 1).value) \n", + " dict1[code] = str(sheet.cell(n, 3).value) \n", + "filename = 'data/result_杨庙230801.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl) \n", + "filename = 'data/result_杨庙社区2303.json'\n", + "with open(filename,'r') as fl:\n", + " dict3 = json.load(fl) \n", + "list1 = []\n", + "for k, v in dict1.items():\n", + " list2 = []\n", + " list2.append(k)\n", + " list2.append(dict2[k]['name'])\n", + " list2.append(dict2[k]['gender'])\n", + " list2.append(dict3[dict1[k]]['部门'])\n", + " for item in items:\n", + " if item == 'bmi' and item in dict2[k]['fit'].keys():\n", + " list2.append(dict2[k]['fit'][item]['mark'].split(',')[0])\n", + " if '身高' in dict3[dict1[k]].keys():\n", + " list2.append(dict3[dict1[k]]['身高']['成绩'])\n", + " else:\n", + " list2.append('') \n", + " list2.append(dict2[k]['fit'][item]['mark'].split(',')[1])\n", + " if '体重' in dict3[dict1[k]].keys():\n", + " list2.append(dict3[dict1[k]]['体重']['成绩'])\n", + " else:\n", + " list2.append('')\n", + " if item != 'bmi' and item in dict2[k]['fit'].keys():\n", + " list2.append(dict2[k]['fit'][item]['mark'])\n", + " if dict4[item] in dict3[dict1[k]].keys():\n", + " list2.append(dict3[dict1[k]][dict4[item]]['成绩'])\n", + " else:\n", + " list2.append('') \n", + " list1.append(list2)\n", + "print(list1)\n", + "filename = 'data/杨庙测试人员测试对比信息表.xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "\n", + "for row in list1:\n", + " sheet.append(row)\n", + "wb.save(filename) " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/体测单位/体测数据管理.ipynb b/体测单位/体测数据管理.ipynb new file mode 100644 index 0000000..d9ec4d0 --- /dev/null +++ b/体测单位/体测数据管理.ipynb @@ -0,0 +1,193 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "dcfbd41f-ca70-4f15-9153-60e6aaac27e8", + "metadata": {}, + "source": [ + "## 生成手机验证码" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b68302b4-8fc1-4060-a10d-7f059f006f3c", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import os,sys,shutil\n", + "import json\n", + "import math\n", + "import glob\n", + "import random\n", + "from pathlib import Path\n", + "import pymongo\n", + "\n", + "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", + "mydb = myclient[\"baogao\"]\n", + "\n", + "\n", + "wb = openpyxl.load_workbook('data/北京石油分公司报告明细.xlsx')\n", + "place_id = 419309\n", + "place_code = '01'\n", + "dw_name = '北京石油分公司'\n", + "fi_path = 'file/2023-06-15'\n", + "fls = glob.glob(f'{fi_path}/*.pdf')\n", + "\n", + "code_list = []\n", + "for i in range(10): # 0~9\n", + " code_list.append(str(i))\n", + " \n", + "list1 = []\n", + "i = 0\n", + "while i < len(fls):\n", + " code = random.sample(code_list,6) #随机取6位数\n", + " code_num = ''.join(code) \n", + " if code_num not in list1:\n", + " list1.append(place_code+code_num)\n", + " i +=1\n", + "print(len(list1))\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "list2 = []\n", + "i = 0\n", + "dict2 = {}\n", + "for n in range(2, sheet.max_row+1):\n", + " if sheet.cell(n,1).value is not None:\n", + " dict1 = {}\n", + " phone = str(sheet.cell(n, 3).value)\n", + " code = int(sheet.cell(n, 1).value)\n", + " yzm = list1[i]\n", + " i+=1\n", + " dict1 = {'place_id':place_id,'code':yzm,'fn':str(code)+'.pdf'}\n", + " list2.append(dict1)\n", + " dict2[code]={'phone':phone,'code':yzm}\n", + "mycol = mydb[\"pdf\"]\n", + "x = mycol.insert_many(list2)\n", + "filename = 'data/01.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(dict2, fl, ensure_ascii=False)\n", + "print('ok')\n" + ] + }, + { + "cell_type": "markdown", + "id": "b9a157f4-4772-413e-82f4-ecb7d2af8529", + "metadata": {}, + "source": [ + "## 批量发送短信" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3", + "metadata": {}, + "outputs": [], + "source": [ + "from tencentcloud.common import credential\n", + "from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n", + "from tencentcloud.sms.v20210111 import sms_client, models\n", + "from tencentcloud.common.profile.client_profile import ClientProfile\n", + "from tencentcloud.common.profile.http_profile import HttpProfile\n", + "import json\n", + "\n", + "filename = 'data/01.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "for k, v in dict1.items():\n", + " phone = '+86'+v['phone']\n", + " yzm = v['code']\n", + " try: \n", + " secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n", + " secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n", + " cred = credential.Credential(secretId, secretKey) \n", + " httpProfile = HttpProfile()\n", + " httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n", + " httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n", + " httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n", + " clientProfile = ClientProfile()\n", + " clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n", + " clientProfile.language = \"en-US\"\n", + " clientProfile.httpProfile = httpProfile\n", + " client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n", + " req = models.SendSmsRequest()\n", + " req.SmsSdkAppId = \"1400140089\"\n", + " req.SignName = \"坤铭教育\"\n", + " req.TemplateId = \"1875765\" \n", + " req.TemplateParamSet = [\"北京石油分公司体测者\",yzm]\n", + " req.PhoneNumberSet = [phone]\n", + " req.SessionContext = \"\"\n", + " req.ExtendCode = \"\"\n", + " req.SenderId = \"\"\n", + " #resp = client.SendSms(req)\n", + " dict2 = json.loads(resp.to_json_string(indent=2))\n", + "\n", + " print(v['phone'],dict2['SendStatusSet'][0][\"Message\"])\n", + " except TencentCloudSDKException as err:\n", + " print(v['phone'],err)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eefec974-c4b7-43c8-82c2-6ad6e5045aa0", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "filename = 'data/01.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "for k, v in dict1.items():\n", + " phone = '+86'+v['phone']\n", + " yzm = v['code']\n", + " print(k,phone,yzm)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df637ce6-7c35-404a-af43-2a5a66b49ba0", + "metadata": {}, + "outputs": [], + "source": [ + "dict1 = json.loads(resp.to_json_string(indent=2))\n", + "print(dict1['SendStatusSet'][0][\"Message\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ba05bd1a-9f33-4df7-b15e-d110c19a5dea", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/体测单位/悟空仪器.ipynb b/体测单位/悟空仪器.ipynb new file mode 100644 index 0000000..1d47214 --- /dev/null +++ b/体测单位/悟空仪器.ipynb @@ -0,0 +1,503 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "cba4b789-a7f2-496f-ad57-a5656fe31bd1", + "metadata": {}, + "source": [ + "## 导入人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "feb31e69-387f-4856-a881-3044080e6d9a", + "metadata": {}, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "import datetime\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", + " if sheet.cell(n,1).value is not None:\n", + " code = int(sheet.cell(n, 1).value)\n", + " person.setdefault(code, {})\n", + " dict1 = {}\n", + " dict1['name'] = sheet.cell(n, 2).value \n", + " dict1['sex'] = sheet.cell(n, 3).value\n", + " dict1['unit'] = sheet.cell(n, 5).value\n", + " dict1['birth'] = str(sheet.cell(n, 4).value).split()[0]\n", + " birth = dict1['birth'].split()[0].split('-')\n", + " nian = int(birth[0].strip())\n", + " yue = int(birth[1].strip())\n", + " ri = int(birth[2].strip())\n", + " #print(k,nian,yue,ri)\n", + " days = (datetime.date(2023, 8, 22)-datetime.date(nian,yue,ri)).days\n", + " dict1['month'] = int(days/365*12)\n", + " dict1['age'] = int(days/365)\n", + " person[code] = dict1\n", + "filename = 'data/悟空仪器.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(person, fl, ensure_ascii=False,default=str)\n", + "print('ok')" + ] + }, + { + "cell_type": "markdown", + "id": "6b3f33d7-d4fa-438c-8620-e232ba37bdeb", + "metadata": {}, + "source": [ + "## 导入测试信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1e5f045-2c26-414c-9ce0-eb73678ef0ce", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import time\n", + "import csv\n", + "\n", + "filename = '../item.json'\n", + "item = {}\n", + "unit = {}\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "for k,v in dict1.items():\n", + " item[k] = v\n", + "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_20230829.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", + " re_ta[user]['age'] = dict1[user]['age']\n", + " re_ta[user]['month'] = dict1[user]['month']\n", + " item_name = item[m_item]['en']\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": "bdee5e18-c4b0-4943-bed0-b9137b970661", + "metadata": {}, + "source": [ + "## 计算测试得分" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fd29332f-371e-410d-a709-58b9046cded1", + "metadata": {}, + "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", + " 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", + " \n", + " info = data1['sex']+str(data1['age'])\n", + " bz = person[info]\n", + " #print(bz)\n", + " result = data1['result']\n", + " print(result)\n", + " height = int(float(result.split(',')[0]))\n", + " weight = float(result.split(',')[1])\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", + " 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 = {'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 = {'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 = 'data/result_悟空仪器1.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2,fl , ensure_ascii=False) \n", + "print('ok!') \n", + " \n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "507d5fec-a28b-498e-a7b3-10f1ed653e60", + "metadata": {}, + "source": [ + "## 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8af556eb-3397-4ec7-8c88-52c8420a73c6", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "filename = 'data/result_悟空仪器1.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "fiie_path ='./2201/'\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", + "for k, v in dict1.items():\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(5,\"0\")\n", + " mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '悟空仪器'\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " mydata['gender'] = 'male'\n", + " else:\n", + " mydata['gender'] = 'female'\n", + " \n", + " mydata['month'] = v['month']\n", + " mydata['fit'] = {}\n", + " for item in list_item:\n", + " if item in v.keys():\n", + " mydata['fit'][item] = {'mark':v[item]['成绩'].split()[0],'score':v[item]['score']}\n", + " list1.append(mydata) \n", + " #x = requests.post('http://192.168.31.163:3003', data = json.dumps(mydata), headers=headers)\n", + " #print(id,v['name'],x.text)\n", + " #x.close()\n", + " #if k =='218':\n", + " # print(mydata)\n", + "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", + "\n", + "# 将 json 数据写入文件\n", + "with open(\"data/悟空data1.json\", \"w\",encoding = 'utf-8') as file:\n", + " file.write(json_data) \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e089a71e-dbcf-4327-a192-c7be5410662b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json; charset=UTF-8\"\n", + " }\n", + "filename = 'data/result_悟空仪器1.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "fiie_path ='./2201_1/'\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", + "for k, v in dict1.items():\n", + " list1 = []\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(5,\"0\")\n", + " mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '悟空仪器'\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " 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", + " list1.append(mydata) \n", + " x = requests.post('http://192.168.31.163:3003', data = json.dumps(list1), headers=headers)\n", + " print(id,v['name'],x.text)\n", + " x.close()\n", + " #print(mydata)\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "a7c6234f-64da-4db9-b626-309ec5e605bb", + "metadata": {}, + "source": [ + "## 计算项目平均分" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2fc0a9b0-6acf-460f-a827-ea9119ee4edc", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "filename = 'data/悟空data1.json'\n", + "with open(filename,'r') as fl:\n", + " list1 = json.load(fl)\n", + "dict2 = {}\n", + "#print(list1)\n", + "for item in list1:\n", + " for k, v in item['fit'].items():\n", + " dict2.setdefault(k,{'count':0,'score':0})\n", + " dict2[k]['count'] = dict2[k]['count']+1\n", + " dict2[k]['score'] = dict2[k]['score'] + v['score']\n", + "for k, v in dict2.items():\n", + " print(k,v['count'],v['score'],)\n", + " \n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "677371c7-f5aa-457f-9baa-3fa4bda2dcf8", + "metadata": {}, + "source": [ + "## 核对成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51d613bb-c2d1-4e43-a156-f7ebad9948b8", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import csv\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", + "re_ta = {}\n", + "list1 = []\n", + "item_list = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n", + "filename = 'data/places_result_20230826.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", + " \n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " item_name = item[m_item]['en']\n", + " re_ta[user].setdefault(item_name,{}) \n", + " score = int(result[4])/item[m_item]['divisor'] \n", + " re_ta[user][item_name]['成绩'] = result[5]\n", + "\n", + "filename = 'data/悟空data1.json'\n", + "with open(filename,'r') as fl:\n", + " list1 = json.load(fl)\n", + "for data in list1:\n", + " code = str(int(data['id']))\n", + " for k, v in data['fit'].items():\n", + " if code in re_ta.keys():\n", + " if k in item_list:\n", + " print(code,k,v['score'],re_ta[code][k]['成绩'])\n", + " if k == 'bmi':\n", + " print(code,k,v['score'],re_ta[code]['weight']['成绩'])\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "951a7663-e152-4b82-9685-74912b9258d8", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}