Files
jupyter/体测单位/喀什.ipynb
T
2025-05-28 15:21:57 +08:00

301 lines
9.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "e09ac558-4859-46c8-ba33-bfff63fd1f8e",
"metadata": {},
"source": [
"## 体测人员导入"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "2f3742c3-0247-4304-a580-530102cad1dc",
"metadata": {
"execution": {
"iopub.execute_input": "2025-04-22T11:50:56.869795Z",
"iopub.status.busy": "2025-04-22T11:50:56.869051Z",
"iopub.status.idle": "2025-04-22T11:50:56.891836Z",
"shell.execute_reply": "2025-04-22T11:50:56.891253Z",
"shell.execute_reply.started": "2025-04-22T11:50:56.869726Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"from datetime import date\n",
"from pathlib import Path\n",
"\n",
"wb = openpyxl.load_workbook('data/喀什体测人员.xlsx')\n",
"sheet = wb.active\n",
"sheets = wb.sheetnames\n",
"\n",
"filename = 'data/喀什人员.json'\n",
"path = Path(filename)\n",
"if path.exists():\n",
" with open(filename,'r') as fl:\n",
" person = json.load(fl) \n",
"else:\n",
" person = {}\n",
" \n",
"for n in range(3, sheet.max_row+1):\n",
" code = int(sheet.cell(n, 1).value)\n",
" if code not in person.keys() and sheet.cell(n,2).value is not None:\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n, 3).value\n",
" dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0] \n",
" dict1['phone'] = str(sheet.cell(n, 5).value)\n",
" person[code] = dict1\n",
"filename = 'data/喀什人员.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "b36f7788-0916-45b6-862b-e52d5f6f18d6",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "8b649b7e-2608-4954-91ce-66f15b7e7806",
"metadata": {
"execution": {
"iopub.execute_input": "2025-04-22T11:51:02.601227Z",
"iopub.status.busy": "2025-04-22T11:51:02.600489Z",
"iopub.status.idle": "2025-04-22T11:51:02.610977Z",
"shell.execute_reply": "2025-04-22T11:51:02.610263Z",
"shell.execute_reply.started": "2025-04-22T11:51:02.601160Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11\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/喀什人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"filename = 'data/marks_20250422.csv'\n",
"re_ta = My.get_result(filename,dict1)\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": "markdown",
"id": "261b7ded-936b-40cc-a14c-2f48fc191795",
"metadata": {},
"source": [
"## 生成测试得分"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "fa481310-fb25-4523-9558-eef6717452ba",
"metadata": {
"execution": {
"iopub.execute_input": "2025-04-22T11:51:04.831016Z",
"iopub.status.busy": "2025-04-22T11:51:04.830415Z",
"iopub.status.idle": "2025-04-22T11:51:04.842945Z",
"shell.execute_reply": "2025-04-22T11:51:04.841682Z",
"shell.execute_reply.started": "2025-04-22T11:51:04.830959Z"
}
},
"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_喀什人员.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_喀什人员.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "58709fec-703d-49b3-8596-313ba58b897b",
"metadata": {},
"source": [
"## 生成报告"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "480fe004-aea6-4477-9fdd-a80818d731ac",
"metadata": {
"execution": {
"iopub.execute_input": "2025-04-22T11:51:06.864802Z",
"iopub.status.busy": "2025-04-22T11:51:06.864080Z",
"iopub.status.idle": "2025-04-22T11:51:13.370634Z",
"shell.execute_reply": "2025-04-22T11:51:13.369406Z",
"shell.execute_reply.started": "2025-04-22T11:51:06.864736Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11\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",
"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(5,\"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",
" 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",
" 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 or 'surveys' in mydata.keys():\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",
" #x.close()\n",
"print(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "947cd639-3373-4431-a262-2fb4a9c131af",
"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
}