diff --git a/体测单位/my_module.py b/体测单位/my_module.py index da9dfb1..fd55f3c 100644 --- a/体测单位/my_module.py +++ b/体测单位/my_module.py @@ -152,7 +152,7 @@ def get_result(filename,dict1): l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step'] else: l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp'] - #re_ta[user]['unit'] = dict1[user]['unit'] + re_ta[user]['unit'] = dict1[user]['unit'] birth = date.fromisoformat(dict1[user]['birth'].replace('/','-')) item_name = result[3] if item_name in l_xm: diff --git a/体测单位/东营石油工程设计院.ipynb b/体测单位/东营石油工程设计院.ipynb index 15dcb76..68a07f8 100644 --- a/体测单位/东营石油工程设计院.ipynb +++ b/体测单位/东营石油工程设计院.ipynb @@ -1407,15 +1407,15 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 1, "id": "d07d132b-dd74-458d-af0c-6a6ae005ad3a", "metadata": { "execution": { - "iopub.execute_input": "2025-06-09T05:54:53.309142Z", - "iopub.status.busy": "2025-06-09T05:54:53.308597Z", - "iopub.status.idle": "2025-06-09T05:54:53.339265Z", - "shell.execute_reply": "2025-06-09T05:54:53.338794Z", - "shell.execute_reply.started": "2025-06-09T05:54:53.309094Z" + "iopub.execute_input": "2025-06-09T08:13:09.484342Z", + "iopub.status.busy": "2025-06-09T08:13:09.483682Z", + "iopub.status.idle": "2025-06-09T08:13:09.516356Z", + "shell.execute_reply": "2025-06-09T08:13:09.515813Z", + "shell.execute_reply.started": "2025-06-09T08:13:09.484283Z" } }, "outputs": [ @@ -1440,6 +1440,7 @@ "filename = 'data/marks_20250609.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\n", + "\n", "filename = 'data/result_东营石油工程设计院2025.json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", @@ -1456,15 +1457,15 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "id": "971d592d-9ff5-4758-af68-2f60a986c2a2", "metadata": { "execution": { - "iopub.execute_input": "2025-06-09T05:55:52.911728Z", - "iopub.status.busy": "2025-06-09T05:55:52.910950Z", - "iopub.status.idle": "2025-06-09T05:55:52.934192Z", - "shell.execute_reply": "2025-06-09T05:55:52.933606Z", - "shell.execute_reply.started": "2025-06-09T05:55:52.911653Z" + "iopub.execute_input": "2025-06-09T08:13:24.385566Z", + "iopub.status.busy": "2025-06-09T08:13:24.384878Z", + "iopub.status.idle": "2025-06-09T08:13:24.414310Z", + "shell.execute_reply": "2025-06-09T08:13:24.413783Z", + "shell.execute_reply.started": "2025-06-09T08:13:24.385501Z" } }, "outputs": [ @@ -1583,10 +1584,102 @@ "wb.save(filename)" ] }, + { + "cell_type": "markdown", + "id": "1f2c3e94-e14b-4c68-b5c7-a71b95fc2f86", + "metadata": {}, + "source": [ + "## 生成报告" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "cf15813a-02de-4dc9-95fe-912d9a5d9025", + "metadata": { + "execution": { + "iopub.execute_input": "2025-06-09T08:14:41.869403Z", + "iopub.status.busy": "2025-06-09T08:14:41.868754Z", + "iopub.status.idle": "2025-06-09T08:16:55.156384Z", + "shell.execute_reply": "2025-06-09T08:16:55.155379Z", + "shell.execute_reply.started": "2025-06-09T08:14:41.869343Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "245\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_东营石油工程设计院2025.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "list1 = []\n", + "file_path ='./东营石油设计院2025/'\n", + "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n", + "i=0\n", + "list2 = []\n", + "for k, v in dict1.items():\n", + " list1 = []\n", + " mydata = {}\n", + " \n", + " id = str(k).rjust(4,\"0\")\n", + " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '东营石油设计院'\n", + " mydata['subtitle'] = v['unit']\n", + " mydata['id'] = id\n", + " mydata['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " mydata['gender'] = 'male'\n", + " else:\n", + " mydata['gender'] = 'female'\n", + " \n", + " mydata['month'] = v['month']\n", + " mydata['fits'] = {}\n", + " survey_list = ['tcm','psy57','spine']\n", + " for item in survey_list:\n", + " if item in v.keys():\n", + " mydata.setdefault('surveys',{})\n", + " mydata['surveys'][item] = v[item]\n", + " \n", + " \n", + " #mydata['fits'] = {}\n", + " for item in list_item:\n", + " if item in v.keys():\n", + " mydata.setdefault('fits',{})\n", + " if item in ['lung','pushup','step','situp']:\n", + " mark = v[item]['成绩'].split()[0].split('.')[0]\n", + " else:\n", + " mark = v[item]['成绩'].split()[0]\n", + " mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n", + " #if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n", + " if len(mydata['fits']) >2 : \n", + " list1.append(mydata)\n", + " list2.append([k,v['name']])\n", + " i+=1\n", + " x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n", + " #print(id,v['name'],x.text)\n", + " #print(mydata)\n", + " #x.close()\n", + "print(i)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "d6e1066a-7779-407f-8b8d-109ada157acc", + "id": "a7eb6a67-a31d-43cf-a44b-8c36c4686de4", "metadata": {}, "outputs": [], "source": [] diff --git a/体测单位/体质检测数据处理.ipynb b/体测单位/体质检测数据处理.ipynb index 25e77d6..bb1f2ba 100644 --- a/体测单位/体质检测数据处理.ipynb +++ b/体测单位/体质检测数据处理.ipynb @@ -835,12 +835,12 @@ "import glob\n", "from pathlib import Path\n", "\n", - "fi_path = '/home/songyi/pdf-typescript-old2/青海2025'\n", - "new_path = 'file/青海2025'\n", + "fi_path = '/home/songyi/pdf-typescript-old2/东营石油设计院2025'\n", + "new_path = 'file/东营石油设计院2025'\n", "old = []\n", "dict2 = {}\n", "\n", - "filename = 'data/result_青海2025-1.json'\n", + "filename = 'data/result_东营石油工程设计院2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", @@ -866,12 +866,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "02319955-7fb6-4791-ae45-55b03bdadd54", "metadata": { + "execution": { + "iopub.execute_input": "2025-06-09T08:21:54.417984Z", + "iopub.status.busy": "2025-06-09T08:21:54.417267Z", + "iopub.status.idle": "2025-06-09T08:21:54.455725Z", + "shell.execute_reply": "2025-06-09T08:21:54.455117Z", + "shell.execute_reply.started": "2025-06-09T08:21:54.417917Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], "source": [ "import os,sys,shutil\n", "import json\n", @@ -879,9 +894,9 @@ "from pathlib import Path\n", "import openpyxl\n", "\n", - "fi_path = '/home/songyi/pdf-typescript-old2/青海2025'\n", + "fi_path = '/home/songyi/pdf-typescript-old2/东营石油设计院2025'\n", "\n", - "filename = 'data/result_青海2025-1.json'\n", + "filename = 'data/result_东营石油工程设计院2025.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", @@ -897,7 +912,7 @@ " \n", " list1.append(list2)\n", "\n", - "filename = 'data/青海油田勘探事业部2025年体测报告明细表.xlsx'\n", + "filename = 'data/东营石油工程设计院2025年体测报告明细表.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", diff --git a/体测单位/宁夏能化.ipynb b/体测单位/宁夏能化.ipynb index 6caf399..6504d4c 100644 --- a/体测单位/宁夏能化.ipynb +++ b/体测单位/宁夏能化.ipynb @@ -10,27 +10,12 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "bbba6efc-73cd-4db6-bae7-014724fee731", "metadata": { - "execution": { - "iopub.execute_input": "2025-05-28T06:35:11.550938Z", - "iopub.status.busy": "2025-05-28T06:35:11.550116Z", - "iopub.status.idle": "2025-05-28T06:35:11.969766Z", - "shell.execute_reply": "2025-05-28T06:35:11.969225Z", - "shell.execute_reply.started": "2025-05-28T06:35:11.550860Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok\n" - ] - } - ], + "outputs": [], "source": [ "import openpyxl\n", "import json\n", @@ -47,7 +32,8 @@ " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 3).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", - " dict1['unit'] = sheet.cell(n, 6).value\n", + " dict1['unit'] = sheet.cell(n, 9).value\n", + " dict1['sub_unit'] = sheet.cell(n, 6).value\n", " dict1['birth'] = sheet.cell(n,5).value\n", " person[code] = dict1\n", "filename = 'data/宁夏能化人员.json'\n", @@ -66,27 +52,12 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f", "metadata": { - "execution": { - "iopub.execute_input": "2025-05-28T06:36:24.201183Z", - "iopub.status.busy": "2025-05-28T06:36:24.200236Z", - "iopub.status.idle": "2025-05-28T06:36:24.222064Z", - "shell.execute_reply": "2025-05-28T06:36:24.221561Z", - "shell.execute_reply.started": "2025-05-28T06:36:24.201103Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok\n" - ] - } - ], + "outputs": [], "source": [ "import json\n", "\n", @@ -119,70 +90,27 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "970e171e-1360-448f-a28c-520ccb8f314a", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-26T12:31:39.094899Z", - "iopub.status.busy": "2023-11-26T12:31:39.094370Z", - "iopub.status.idle": "2023-11-26T12:31:39.114981Z", - "shell.execute_reply": "2023-11-26T12:31:39.114071Z", - "shell.execute_reply.started": "2023-11-26T12:31:39.094860Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "16\n", - "16\n" - ] - } - ], + "outputs": [], "source": [ "import json\n", - "import time\n", + "import datetime\n", "import csv\n", + "from datetime import date\n", + "import my_module as My\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", + "filename = 'data/宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", + "filename = 'data/marks_20250611.csv'\n", + "re_ta = My.get_result(filename,dict1)\n", "\n", - "filename = 'data/places_result_20231126.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_北京党校20231126.json'\n", "\n", + "filename = 'data/result_宁夏能化人员.json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", "print(len(re_ta))" @@ -208,14 +136,14 @@ "import json\n", "import openpyxl\n", "\n", - "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", - "filename = 'data/result_北京党校.json'\n", + "filename = 'data/result_宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", - "filename = 'data/北京党校.json'\n", + "filename = 'data/宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", " \n", @@ -226,15 +154,25 @@ " list2.append(v['name']) \n", " list2.append(dict2[k]['sex'])\n", " list2.append(dict2[k]['unit'])\n", + " list2.append(dict2[k]['sub_unit'])\n", + " if 'bmi' in v.keys():\n", + " height = v['bmi']['成绩'].split(',')[0]\n", + " weight = v['bmi']['成绩'].split(',')[1]\n", + " list2.append(height)\n", + " list2.append(weight)\n", + " else:\n", + " list2.append('')\n", + " list2.append('')\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", + " list2.append('')\n", + " \n", " list1.append(list2)\n", - "filename = 'data/北京党校.xlsx'\n", + "filename = 'data/宁夏能化测试情况明细表(截至20250611).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "sheet.append(title)\n", @@ -249,37 +187,130 @@ "id": "699c6a40-a6ae-4300-9646-708cb85aa5e8", "metadata": {}, "source": [ - "## 手工数据导入数据库" + "## 统计各部门测试人员情况" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, + "id": "c4b71b0f-0f0c-4962-a540-611cbab51bfa", + "metadata": { + "execution": { + "iopub.execute_input": "2025-06-11T10:33:23.785169Z", + "iopub.status.busy": "2025-06-11T10:33:23.784411Z", + "iopub.status.idle": "2025-06-11T10:33:23.824528Z", + "shell.execute_reply": "2025-06-11T10:33:23.823918Z", + "shell.execute_reply.started": "2025-06-11T10:33:23.785101Z" + } + }, + "outputs": [], + "source": [ + "import json\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", + "dict3 = {}\n", + "for k, v in dict2.items():\n", + " unit = v['unit']\n", + " if unit=='管理部门':\n", + " sub_unit = v['sub_unit']\n", + " else:\n", + " sub_unit = unit\n", + " dict3.setdefault(unit,{}) \n", + " dict3[unit].setdefault(sub_unit,{})\n", + " dict3[unit][sub_unit].setdefault('人数',0)\n", + " dict3[unit][sub_unit]['人数'] = dict3[unit][sub_unit]['人数'] + 1\n", + " #dict3[unit]['人数'] = dict3[unit]['人数'] + 1\n", + "\n", + "title =['单位','体测人数']\n", + "list1 = []\n", + "\n", + "for k, v in dict3.items():\n", + " list2 = []\n", + " for k1,v1 in v.items():\n", + " list2 = [k,k1,v1['人数']]\n", + " list1.append(list2)\n", + "\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": "3796748f-2079-46b6-a3a1-b22441880843", + "metadata": {}, + "source": [ + "## 统计各部门已测试情况" + ] + }, + { + "cell_type": "code", + "execution_count": 25, "id": "def3f47a-24ef-4815-b63b-2a16b79b4c15", "metadata": { + "execution": { + "iopub.execute_input": "2025-06-11T10:49:09.048584Z", + "iopub.status.busy": "2025-06-11T10:49:09.047316Z", + "iopub.status.idle": "2025-06-11T10:49:09.067937Z", + "shell.execute_reply": "2025-06-11T10:49:09.067219Z", + "shell.execute_reply.started": "2025-06-11T10:49:09.048505Z" + }, "tags": [] }, "outputs": [], "source": [ - "import openpyxl\n", "import json\n", "\n", - "filename = 'data/北京党校.json'\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", - "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", + "\n", + "dict3 = {}\n", + "\n", + "\n", + "title =['单位','体测人数']\n", "list1 = []\n", - "for item in data1:\n", - " code = int(item[0])\n", - " list1.append((496534,code,item[2],item[1],'2023-10-15','2023-10-15 14:00:00'))\n", - "print(list1)" + "for k,v in dict1.items():\n", + " unit = v['unit']\n", + " if unit=='管理部门':\n", + " sub_unit = dict2[k]['sub_unit']\n", + " else:\n", + " sub_unit = unit\n", + " dict3.setdefault(unit,{}) \n", + " dict3[unit].setdefault(sub_unit,{})\n", + " dict3[unit][sub_unit].setdefault('人数',0)\n", + " dict3[unit][sub_unit]['人数'] = dict3[unit][sub_unit]['人数'] + 1\n", + "\n", + "for k, v in dict3.items():\n", + " list2 = []\n", + " for k1,v1 in v.items():\n", + " list2 = [k,k1,v1['人数']]\n", + " list1.append(list2)\n", + "\n", + "filename = 'data/宁夏能化部门测试情况表(截至20260611).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)" ] }, {