{ "cells": [ { "cell_type": "markdown", "id": "d4d999fe-4890-4a14-b1e8-52dbd6d42e73", "metadata": {}, "source": [ "## 导入人员信息" ] }, { "cell_type": "code", "execution_count": 19, "id": "3154fc8c-0e91-4cda-ba75-666dc7bbb34d", "metadata": { "execution": { "iopub.execute_input": "2023-05-08T07:53:19.491869Z", "iopub.status.busy": "2023-05-08T07:53:19.491008Z", "iopub.status.idle": "2023-05-08T07:53:19.954513Z", "shell.execute_reply": "2023-05-08T07:53:19.953763Z", "shell.execute_reply.started": "2023-05-08T07:53:19.491826Z" }, "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", "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": "31d36f3c-f046-40a9-bf90-ba139fdcce3a", "metadata": {}, "source": [ "## 新增人员信息" ] }, { "cell_type": "code", "execution_count": 22, "id": "5cea2f5e-37fc-4857-8455-090a634a1c0a", "metadata": { "execution": { "iopub.execute_input": "2023-06-21T07:13:31.520222Z", "iopub.status.busy": "2023-06-21T07:13:31.519385Z", "iopub.status.idle": "2023-06-21T07:13:31.624516Z", "shell.execute_reply": "2023-06-21T07:13:31.623557Z", "shell.execute_reply.started": "2023-06-21T07:13:31.520178Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1508\n", "ok\n", "1704\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", "filename = 'data/长炼医院人员名单.json'\n", "with open(filename,'r') as fl:\n", " person = json.load(fl) \n", "print(len(person))\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')\n", "print(len(person))" ] }, { "cell_type": "markdown", "id": "96d5b4bd-4198-4725-9005-070ac4e4f324", "metadata": {}, "source": [ "## 每日成绩导入" ] }, { "cell_type": "code", "execution_count": 23, "id": "4b52477e-926a-44b5-b8a0-20bff98d101d", "metadata": { "execution": { "iopub.execute_input": "2023-06-26T08:39:29.685827Z", "iopub.status.busy": "2023-06-26T08:39:29.684965Z", "iopub.status.idle": "2023-06-26T08:39:29.730243Z", "shell.execute_reply": "2023-06-26T08:39:29.729345Z", "shell.execute_reply.started": "2023-06-26T08:39:29.685786Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "154\n", "154\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 = '20230626'\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 = f'data/result_长炼医院({rq}).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": "code", "execution_count": 4, "id": "033cc564-4aa9-4e88-b38b-ec62a02b1661", "metadata": { "execution": { "iopub.execute_input": "2023-05-26T08:29:09.963390Z", "iopub.status.busy": "2023-05-26T08:29:09.962538Z", "iopub.status.idle": "2023-05-26T08:29:10.005878Z", "shell.execute_reply": "2023-05-26T08:29:10.004986Z", "shell.execute_reply.started": "2023-05-26T08:29:09.963348Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "67\n", "133 杨诚 已测试!\n", "76 李克胜 已测试!\n", "24 李璇 已测试!\n", "45 乔志刚 已测试!\n", "136 胡茂山 已测试!\n", "182 刘立文 已测试!\n", "163 乐文清 已测试!\n", "160 李莉 已测试!\n", "128 王聪 已测试!\n", "161 王雅琴 已测试!\n", "72 彭姝 已测试!\n", "164 高维 已测试!\n", "134 索怡心 已测试!\n", "67\n", "72\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 = '20230510'\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", "filename = 'data/result_长炼医院.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "for k in re_ta.keys():\n", " if k in dict2.keys():\n", " print(k,dict2[k]['name'],'已测试!')\n", "for k, v in re_ta.items():\n", " if k not in dict2.keys():\n", " dict2[k] = v\n", " else:\n", " for k1,v1 in v.items():\n", " dict2[k][k1] = v1\n", "filename = f'data/result_长炼医院({rq}).json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl, ensure_ascii=False) \n", "print(len(re_ta))\n", "filename = 'data/result_长炼医院.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict2, fl, ensure_ascii=False) \n", "print(len(dict2))" ] }, { "cell_type": "markdown", "id": "f220ffba-d172-4b6f-8238-c3a2d6c87ed4", "metadata": {}, "source": [ "## 每日成绩导出" ] }, { "cell_type": "code", "execution_count": 24, "id": "2ffa583b-be51-40a8-bb55-de6a89d1a54a", "metadata": { "execution": { "iopub.execute_input": "2023-06-26T08:39:59.941503Z", "iopub.status.busy": "2023-06-26T08:39:59.940639Z", "iopub.status.idle": "2023-06-26T08:40:00.032505Z", "shell.execute_reply": "2023-06-26T08:40:00.031819Z", "shell.execute_reply.started": "2023-06-26T08:39:59.941463Z" }, "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "#rq = '20230510'\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "filename = f'data/result_长炼医院({rq}).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/长炼医院体测情况表({rq}).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": "ec011c39-f6b1-40d5-b95e-bc59b7a51058", "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 }