Files
jupyter/体测单位/上地派出所.ipynb
2023-05-06 21:32:55 +08:00

370 lines
11 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "effb9eb3-27b3-4cc6-bed5-68f7e5279316",
"metadata": {},
"source": [
"## 导入人员信息"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "069af150-58fd-45ff-bab7-8fe1760abe91",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-15T14:25:29.264807Z",
"iopub.status.busy": "2023-04-15T14:25:29.263987Z",
"iopub.status.idle": "2023-04-15T14:25:29.959415Z",
"shell.execute_reply": "2023-04-15T14:25:29.958603Z",
"shell.execute_reply.started": "2023-04-15T14:25:29.264769Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/student_20140922(上地派出所监测花名册) .xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"\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, 4).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 6).value\n",
" if sheet.cell(n, 7).value ==1:\n",
" sex = '男'\n",
" else:\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" dict1['unit'] = sheet.cell(n, 3).value\n",
"\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": "b5eb1f6a-a960-4d51-8c09-f77794926159",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "d0cb294b-d403-4c4c-9de6-61ec98cf9797",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-05T06:41:07.266525Z",
"iopub.status.busy": "2023-05-05T06:41:07.266100Z",
"iopub.status.idle": "2023-05-05T06:41:07.287905Z",
"shell.execute_reply": "2023-05-05T06:41:07.286990Z",
"shell.execute_reply.started": "2023-05-05T06:41:07.266497Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"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",
"filename = 'data/上地派出所人员名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"re_ta = {}\n",
"dict2 = {}\n",
"list1 = []\n",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/142.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]['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",
" re_ta[user][item_name]['得分'] =result[5]\n",
"filename = 'data/result_上地派出所1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "ac363a21-83aa-42e5-a82b-fd051e4b86a7",
"metadata": {},
"source": [
"## 计算测试成绩平均分"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "4f5a8416-3536-4c52-bfdc-758420e519d3",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-05T07:17:09.764428Z",
"iopub.status.busy": "2023-05-05T07:17:09.763611Z",
"iopub.status.idle": "2023-05-05T07:17:09.782569Z",
"shell.execute_reply": "2023-05-05T07:17:09.781678Z",
"shell.execute_reply.started": "2023-05-05T07:17:09.764387Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位/部门','身高','','体重','','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\n",
"filename = 'data/result_上地派出所1.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"for k, v in dict1.items():\n",
" i = 0\n",
" score = 0\n",
" for k1, v1 in v.items():\n",
" \n",
" if k1 in items:\n",
" score = score + int(v1['得分'])\n",
" i = i + 1\n",
" pjf = score / i\n",
" dict1[k]['总分'] = score\n",
" dict1[k]['平均分'] = round(score / i,2)\n",
"filename = 'data/result_上地派出所.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) \n",
"print('ok')\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"id": "f62cd919-feb9-4db1-aacc-09b3b8ea30c1",
"metadata": {},
"source": [
"## 导出测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "eafc36e7-6a8d-4744-b5ff-9cc0c624c732",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-05T07:19:08.537806Z",
"iopub.status.busy": "2023-05-05T07:19:08.536964Z",
"iopub.status.idle": "2023-05-05T07:19:08.596852Z",
"shell.execute_reply": "2023-05-05T07:19:08.595844Z",
"shell.execute_reply.started": "2023-05-05T07:19:08.537767Z"
},
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位/部门','身高','','体重','','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\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(dict2[k]['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit'])\n",
" for item in items:\n",
" if item in dict1[k].keys():\n",
" list2.append(dict1[k][item]['成绩'])\n",
" list2.append(dict1[k][item]['得分']) \n",
" elif item =='name':\n",
" list2.append(dict1[k][item])\n",
" else:\n",
" list2.append('') \n",
" list2.append('')\n",
" list2.append(dict1[k]['总分'])\n",
" list2.append(dict1[k]['平均分'])\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": "c6ef75ff-0aa5-422d-a21c-98e2ebe89672",
"metadata": {},
"source": [
"## 统计项目平均分"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "228b4f0c-deac-41e7-a995-e6d3ea4a0cdf",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-05T08:40:23.243572Z",
"iopub.status.busy": "2023-05-05T08:40:23.242724Z",
"iopub.status.idle": "2023-05-05T08:40:23.257387Z",
"shell.execute_reply": "2023-05-05T08:40:23.256275Z",
"shell.execute_reply.started": "2023-05-05T08:40:23.243532Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"体重 3.18\n",
"肺活量 3.75\n",
"握力 2.23\n",
"坐位体前屈 2.79\n",
"纵跳 2.72\n",
"俯卧撑 3.24\n",
"一分钟仰卧起坐 3.83\n",
"单脚站立 1.77\n",
"选择反应时 3.73\n",
"台阶指数 2.52\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位/部门','身高','','体重','','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\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",
"\n",
"for item in items:\n",
" i = 0\n",
" score = 0\n",
" for k, v in dict1.items():\n",
" if item in v.keys():\n",
" score = int(v[item]['得分']) + score \n",
" i = i + 1\n",
" \n",
" \n",
" print(item,round(score/i,2)) \n",
" \n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc3c36c2-4697-4709-b755-ec6ade9451bd",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}