Files
jupyter/体测单位/宁夏能化.ipynb
T
2025-06-11 18:58:21 +08:00

347 lines
9.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "04524c85-988e-4dbf-86eb-939a9db7aa28",
"metadata": {},
"source": [
"## 体测人员导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bbba6efc-73cd-4db6-bae7-014724fee731",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\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",
" 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",
" 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",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('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": null,
"id": "970e171e-1360-448f-a28c-520ccb8f314a",
"metadata": {
"tags": []
},
"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_20250611.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": "markdown",
"id": "d034a61d-1fbd-417b-99bd-277e43ebb678",
"metadata": {},
"source": [
"## 导出测试人员信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890",
"metadata": {
"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_宁夏能化人员.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 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/宁夏能化测试情况明细表(截至20250611).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": 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 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/宁夏能化部门测试情况表(截至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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "67e63f07-3f20-4e0e-9c07-7bf6024eeb4b",
"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
}