This commit is contained in:
512song committed 2023-04-16 10:30:21 +00:00
1 parent 140873c0bb
commit 031a48f4ff
2 files changed
+411

No files matched your search

+303
View File
@@ -0,0 +1,303 @@
{
"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": 4,
"id": "d0cb294b-d403-4c4c-9de6-61ec98cf9797",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-15T14:31:21.405573Z",
"iopub.status.busy": "2023-04-15T14:31:21.404701Z",
"iopub.status.idle": "2023-04-15T14:31:21.431005Z",
"shell.execute_reply": "2023-04-15T14:31:21.429944Z",
"shell.execute_reply.started": "2023-04-15T14:31:21.405535Z"
},
"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[4])\n",
" if user in dict1.keys():\n",
" \n",
" m_item = str(result[0]) \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[1])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" re_ta[user][item_name]['得分'] =result[2]\n",
"filename = 'data/result_上地派出所.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "78e461ac-1074-4bce-a2a5-4cd60f3b7ae2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-15T14:36:06.348606Z",
"iopub.status.busy": "2023-04-15T14:36:06.348205Z",
"iopub.status.idle": "2023-04-15T14:36:06.363398Z",
"shell.execute_reply": "2023-04-15T14:36:06.362284Z",
"shell.execute_reply.started": "2023-04-15T14:36:06.348579Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"44\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[4])\n",
" if user in dict1.keys():\n",
" \n",
" m_item = str(result[0]) \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[1])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" re_ta[user][item_name]['得分'] =result[2]\n",
"print(len(re_ta))"
]
},
{
"cell_type": "markdown",
"id": "f62cd919-feb9-4db1-aacc-09b3b8ea30c1",
"metadata": {},
"source": [
"## 导出测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "eafc36e7-6a8d-4744-b5ff-9cc0c624c732",
"metadata": {
"execution": {
"iopub.execute_input": "2023-04-15T14:33:22.621334Z",
"iopub.status.busy": "2023-04-15T14:33:22.620509Z",
"iopub.status.idle": "2023-04-15T14:33:22.666051Z",
"shell.execute_reply": "2023-04-15T14:33:22.665054Z",
"shell.execute_reply.started": "2023-04-15T14:33:22.621295Z"
},
"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(v['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit']) \n",
" \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",
" 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": "code",
"execution_count": null,
"id": "6f7c8be9-8910-4570-bc09-45f464c77ce9",
"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
}