{ "cells": [ { "cell_type": "markdown", "id": "04524c85-988e-4dbf-86eb-939a9db7aa28", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 13, "id": "bbba6efc-73cd-4db6-bae7-014724fee731", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T06:47:52.647999Z", "iopub.status.busy": "2025-06-24T06:47:52.647468Z", "iopub.status.idle": "2025-06-24T06:47:52.837761Z", "shell.execute_reply": "2025-06-24T06:47:52.837173Z", "shell.execute_reply.started": "2025-06-24T06:47:52.647952Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1698 ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/宁夏能化人员.xlsx',data_only=True)\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, 2).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 3).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", " unit = sheet.cell(n, 9).value\n", " \n", " dict1['sub_unit'] = sheet.cell(n, 6).value\n", " if unit == '管理部门':\n", " dict1['unit'] = sheet.cell(n, 6).value\n", " else:\n", " dict1['unit'] = sheet.cell(n, 9).value\n", " \n", " dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \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(len(person),'ok')" ] }, { "cell_type": "code", "execution_count": 36, "id": "ddddbac1-ab71-436a-ab64-2a15600f5b1b", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:47:30.639088Z", "iopub.status.busy": "2025-06-24T07:47:30.638546Z", "iopub.status.idle": "2025-06-24T07:47:30.944089Z", "shell.execute_reply": "2025-06-24T07:47:30.943556Z", "shell.execute_reply.started": "2025-06-24T07:47:30.639038Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1953 ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "\n", "\n", "wb = openpyxl.load_workbook('data/宁夏能化-全部名单.xlsx',data_only=True)\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, 2).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 3).value\n", " dict1['sex'] = sheet.cell(n, 4).value\n", " unit = sheet.cell(n, 8).value\n", " \n", " dict1['sub_unit'] = sheet.cell(n, 6).value\n", " if unit == '管理部门':\n", " dict1['unit'] = sheet.cell(n, 9).value\n", " else:\n", " dict1['unit'] = sheet.cell(n, 8).value\n", " \n", " dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0] \n", " person[code] = dict1\n", "filename = 'data/宁夏能化人员all.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print(len(person),'ok')" ] }, { "cell_type": "markdown", "id": "048a95aa-1691-45f6-b933-6eaf95ae1d30", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": null, "id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "\n", "filename = 'data/宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "for k, v in dict1.items():\n", " dict2 = {}\n", " #if dict1['sex'] =='男':\n", " # sex = 1\n", " \n", " dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}\n", " list1.append(dict2)\n", "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", "\n", "# 将 json 数据写入文件\n", "with open(\"data/data_宁夏能化人员.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 37, "id": "970e171e-1360-448f-a28c-520ccb8f314a", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:47:35.746440Z", "iopub.status.busy": "2025-06-24T07:47:35.746188Z", "iopub.status.idle": "2025-06-24T07:47:35.874766Z", "shell.execute_reply": "2025-06-24T07:47:35.874285Z", "shell.execute_reply.started": "2025-06-24T07:47:35.746417Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1699\n" ] } ], "source": [ "import json\n", "import datetime\n", "import csv\n", "from datetime import date\n", "import my_module as My\n", "\n", "filename = 'data/宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/marks_20250619.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", "print(len(re_ta))" ] }, { "cell_type": "code", "execution_count": null, "id": "24189bf6-d2b2-4855-a6b2-7a6e36cd79f3", "metadata": {}, "outputs": [], "source": [ "import json\n", "import datetime\n", "import csv\n", "from datetime import date\n", "import my_module as My\n", "\n", "filename = 'data/宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/marks_20250619.csv'\n", "re_ta = My.get_result(filename,dict1)\n", "\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))" ] }, { "cell_type": "code", "execution_count": 22, "id": "2082c096-9f36-430c-9823-f09d8b6f9b42", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:24:22.507391Z", "iopub.status.busy": "2025-06-24T07:24:22.506635Z", "iopub.status.idle": "2025-06-24T07:24:22.548344Z", "shell.execute_reply": "2025-06-24T07:24:22.547831Z", "shell.execute_reply.started": "2025-06-24T07:24:22.507322Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['2018652', '2019665', '2019160', '2019512', '3427477', '2019423', '2019494', '2019901']\n" ] } ], "source": [ "filename = 'data/result_宁夏能化人员.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "list1 = []\n", "for k,v in dict2.items():\n", " if k not in dict1.keys():\n", " #print(k,v['name'],v['sex'],v['unit'])\n", " #print(k,v)\n", " list1.append(str(k))\n", "print(list1)" ] }, { "cell_type": "markdown", "id": "6d381859-6d21-45d2-8313-55ebbabf8bd4", "metadata": {}, "source": [ "## 生成测试得分" ] }, { "cell_type": "code", "execution_count": 38, "id": "0905ad6a-f7e4-43ed-ae29-c4850deb946b", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:47:41.560238Z", "iopub.status.busy": "2025-06-24T07:47:41.559637Z", "iopub.status.idle": "2025-06-24T07:47:41.657989Z", "shell.execute_reply": "2025-06-24T07:47:41.657434Z", "shell.execute_reply.started": "2025-06-24T07:47:41.560182Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok!\n" ] } ], "source": [ "import json\n", "import time\n", "import my_module as My\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_宁夏能化人员all.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 'bmi' in v.keys():\n", " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n", " bmi_data = v['bmi']['成绩']\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'] = My.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", " #print(k,v['name'])\n", " dict2[k][item_en]['score'] = My.cal_score(data1)\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n", "\n", "filename = f'data/result_宁夏能化人员all.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2,fl , ensure_ascii=False) \n", "print('ok!') " ] }, { "cell_type": "markdown", "id": "d034a61d-1fbd-417b-99bd-277e43ebb678", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": 42, "id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890", "metadata": { "execution": { "iopub.execute_input": "2025-06-26T01:35:41.139581Z", "iopub.status.busy": "2025-06-26T01:35:41.139145Z", "iopub.status.idle": "2025-06-26T01:35:41.663585Z", "shell.execute_reply": "2025-06-26T01:35:41.663054Z", "shell.execute_reply.started": "2025-06-26T01:35:41.139557Z" }, "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/宁夏能化人员all.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", " 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", " \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": "c4b71b0f-0f0c-4962-a540-611cbab51bfa", "metadata": {}, "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", "list1 = []\n", "for k, v in dict2.items():\n", " if k not in dict1.keys():\n", " list2 = []\n", " unit = v['unit']\n", " if unit=='管理部门':\n", " sub_unit = v['sub_unit']\n", " else:\n", " sub_unit = unit\n", " list2 = [k,v['name'],v['sex'],sub_unit]\n", " list1.append(list2)\n", " \n", "\n", "\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": null, "id": "def3f47a-24ef-4815-b63b-2a16b79b4c15", "metadata": { "tags": [] }, "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", "\n", "\n", "title =['单位','体测人数']\n", "list1 = []\n", "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/宁夏能化部门测试情况表.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": "code", "execution_count": null, "id": "61dde8c3-844a-4016-8952-cb726ab5f61d", "metadata": {}, "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", "\n", "\n", "title =['单位','体测人数']\n", "list1 = []\n", "for k,v in dict2.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/宁夏能化部门人员情况表.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": "970a1cc8-4fdf-478a-9f5b-b82d7d4bf762", "metadata": {}, "source": [ "## 生成体测成绩明细表" ] }, { "cell_type": "code", "execution_count": 44, "id": "d31020be-c9c0-404f-8e0b-f8f507385f48", "metadata": { "execution": { "iopub.execute_input": "2025-06-27T04:14:46.467739Z", "iopub.status.busy": "2025-06-27T04:14:46.466974Z", "iopub.status.idle": "2025-06-27T04:14:47.053693Z", "shell.execute_reply": "2025-06-27T04:14:47.053104Z", "shell.execute_reply.started": "2025-06-27T04:14:46.467668Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n", "bmi = ['height','weight']\n", "title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','得分','握力','得分','坐位体前屈','得分','纵跳','得分','俯卧撑','得分','一分钟仰卧起坐','得分','单脚站立','得分','选择反应时','得分','台阶指数','得分']\n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "list1 = []\n", "for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n", " list2 = []\n", " list2.append(str(k).rjust(5,'0'))\n", " list2.append(dict1[k]['name']) \n", " list2.append(dict1[k]['sex'])\n", " list2.append(dict1[k]['unit'])\n", " i = 0\n", " if 'bmi' in dict1[k].keys():\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[0])\n", " list2.append(dict1[k]['bmi']['成绩'].split(',')[1])\n", " list2.append(dict1[k]['bmi']['score'])\n", " i+=1\n", " else:\n", " list2.append('') \n", " list2.append('') \n", " list2.append('') \n", " \n", " \n", " for item in items:\n", " if item in dict1[k].keys():\n", " list2.append(dict1[k][item]['成绩'])\n", " list2.append(dict1[k][item]['score']) \n", " i+=1\n", " elif item =='name':\n", " list2.append(dict1[k][item])\n", " else:\n", " list2.append('') \n", " list2.append('') \n", " if i>2:\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)\n", "print('ok') " ] }, { "cell_type": "markdown", "id": "8d5f4103-0d1e-4711-b324-ece360f8dcd3", "metadata": {}, "source": [ "## 生成报告" ] }, { "cell_type": "code", "execution_count": null, "id": "23ffd115-72a3-4f90-9e64-ffa6420df8a4", "metadata": {}, "outputs": [], "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", "file_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'] = 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": 39, "id": "9ffec868-3851-42f6-8431-c5c5d3d15424", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:47:57.736323Z", "iopub.status.busy": "2025-06-24T07:47:57.736061Z", "iopub.status.idle": "2025-06-24T07:48:02.653903Z", "shell.execute_reply": "2025-06-24T07:48:02.653030Z", "shell.execute_reply.started": "2025-06-24T07:47:57.736300Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "8\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_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "file_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", " if str(k) in ['2018652', '2019665', '2019160', '2019512', '3427477', '2019423', '2019494', '2019901']:\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": "markdown", "id": "a056e973-b5d2-4130-85bf-1b1f21f53e48", "metadata": {}, "source": [ "## 体测报告按部门分类" ] }, { "cell_type": "code", "execution_count": 40, "id": "59f69be9-ab27-4308-8641-927dbcfda87e", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:48:39.717546Z", "iopub.status.busy": "2025-06-24T07:48:39.716729Z", "iopub.status.idle": "2025-06-24T07:48:40.238267Z", "shell.execute_reply": "2025-06-24T07:48:40.237638Z", "shell.execute_reply.started": "2025-06-24T07:48:39.717462Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1699\n" ] } ], "source": [ "import os,sys,shutil\n", "import json\n", "import glob\n", "from pathlib import Path\n", "\n", "fi_path = '/home/songyi/pdf-typescript-old2/宁夏能化人员'\n", "new_path = 'file/宁夏能化'\n", "old = []\n", "dict2 = {}\n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", "print(len(fls))\n", "for fn in fls:\n", " fi_name =Path(fn).stem.split('-')[0]\n", " code = int(fi_name) \n", " unit_path = Path(new_path,dict1[str(code)]['unit'])\n", " unit_path.mkdir(parents = True, exist_ok = True)\n", " n_name = Path(unit_path,Path(fn).stem+'.pdf')\n", " #if not os.path.exists(n_name):\n", " shutil.copyfile(fn,n_name)\n", " #print(fn)" ] }, { "cell_type": "markdown", "id": "e4d3abe9-707d-4edd-92df-95a5b0fea941", "metadata": {}, "source": [ "## 生成体测报告打印明细表" ] }, { "cell_type": "code", "execution_count": 41, "id": "896955ac-351a-4914-94a6-56e6d1ae9e6e", "metadata": { "execution": { "iopub.execute_input": "2025-06-24T07:48:42.641359Z", "iopub.status.busy": "2025-06-24T07:48:42.641096Z", "iopub.status.idle": "2025-06-24T07:48:42.812702Z", "shell.execute_reply": "2025-06-24T07:48:42.812095Z", "shell.execute_reply.started": "2025-06-24T07:48:42.641334Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import os,sys,shutil\n", "import json\n", "import glob\n", "from pathlib import Path\n", "import openpyxl\n", "\n", "fi_path = '/home/songyi/pdf-typescript-old2/宁夏能化人员'\n", "\n", "filename = 'data/result_宁夏能化人员all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "fls = glob.glob(f'{fi_path}/*.pdf')\n", "list1 = []\n", "title = ['测试编号','姓名','性别','部门']\n", "for fn in fls:\n", " list2 = []\n", " fi_name =Path(fn).stem.split('-')[0] \n", " code = int(fi_name)\n", " sex = dict1[str(code)]['sex']\n", " unit = dict1[str(code)]['unit']\n", " list2 = [fi_name,Path(fn).stem.split('-')[1],sex,unit]\n", " \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) \n", "print('ok')" ] }, { "cell_type": "code", "execution_count": null, "id": "a1907b6f-3ba7-4773-8f6e-6559af18131e", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }