From cf5e906c57fdb348784179005247cd1b3ca0ebe8 Mon Sep 17 00:00:00 2001 From: 512song Date: Thu, 14 Sep 2023 07:29:10 +0000 Subject: [PATCH] 20230914 --- 体测单位/长炼医院.ipynb | 202 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 1 deletion(-) diff --git a/体测单位/长炼医院.ipynb b/体测单位/长炼医院.ipynb index 10a61ad..8d2d222 100644 --- a/体测单位/长炼医院.ipynb +++ b/体测单位/长炼医院.ipynb @@ -1,5 +1,13 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "55644860-57e6-466b-b6e9-e6fdd807498d", + "metadata": {}, + "source": [ + "# 员工体测" + ] + }, { "cell_type": "markdown", "id": "d4d999fe-4890-4a14-b1e8-52dbd6d42e73", @@ -835,10 +843,202 @@ "print('ok') " ] }, + { + "cell_type": "markdown", + "id": "b07923fd-94da-4b86-8902-523d3ebc3d1b", + "metadata": { + "tags": [] + }, + "source": [ + "# 学生体测" + ] + }, + { + "cell_type": "markdown", + "id": "6ba73ead-6715-46a6-b4a9-3a00b733b151", + "metadata": {}, + "source": [ + "## 导入学生信息" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c828b665-d178-42e4-a885-505045169102", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "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", + " 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 int(sheet.cell(n, 7).value) ==1:\n", + " sex = '男'\n", + " else:\n", + " sex = '女'\n", + " dict1['sex'] = sex\n", + " birth = str(sheet.cell(n, 8).value).split()[0]\n", + " dict1['birth'] = birth\n", + " dict1['unit'] = sheet.cell(n, 3).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": "9d64629c-f5ee-4c2b-a9a8-964259d06d36", + "metadata": {}, + "source": [ + "## 每日成绩导入" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3f1b2284-c39e-4dc2-bc0c-983fb8e3417f", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "508\n", + "508\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", + "re_ta = {}\n", + "dict1 = {}\n", + "list1 = []\n", + "filename = 'data/长岭学生名单.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "rq = '20230914'\n", + "filename = f'data/places_result_{rq}.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", + " 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", + "print(len(re_ta))\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))\n" + ] + }, + { + "cell_type": "markdown", + "id": "33c3ecc6-4dee-4eb9-954e-00f3fbbc179d", + "metadata": {}, + "source": [ + "## 每日成绩导入" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "9d5d379c-5b53-4716-b4ab-fa794c912853", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import json\n", + "import openpyxl\n", + "\n", + "#rq = '20230510'\n", + "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", + "filename = f'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", + " 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 = f'data/长岭学生体测情况表.xlsx'\n", + "wb = openpyxl.Workbook()\n", + "sheet = wb.active\n", + "sheet.append(title)\n", + "for row in list1:\n", + " sheet.append(row)\n", + "wb.save(filename)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "b412ca21-e494-42ba-ac08-0e61cd755d3e", + "id": "1b35c133-928f-40d9-8523-8a16677a55d8", "metadata": {}, "outputs": [], "source": []