{ "cells": [ { "cell_type": "markdown", "id": "338fb8da-815a-4536-ae91-4f461ba9401f", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 26, "id": "ba24132c-133f-4508-8fe7-e68d1908b6e9", "metadata": { "execution": { "iopub.execute_input": "2024-09-20T08:47:18.577809Z", "iopub.status.busy": "2024-09-20T08:47:18.577022Z", "iopub.status.idle": "2024-09-20T08:47:18.914709Z", "shell.execute_reply": "2024-09-20T08:47:18.914113Z", "shell.execute_reply.started": "2024-09-20T08:47:18.577734Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "from datetime import date\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, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n, 3).value\n", " dict1['unit'] = sheet.cell(n, 7).value\n", " dict1['gh'] = sheet.cell(n, 5).value\n", " dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0] \n", " dict1['phone'] = str(sheet.cell(n,4).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": "10ddfd3b-697c-4459-8bed-147b22f88239", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": 4, "id": "63ab2d5b-3a0a-4ac7-a3e7-b3a34e621e98", "metadata": { "execution": { "iopub.execute_input": "2024-09-17T01:49:44.352863Z", "iopub.status.busy": "2024-09-17T01:49:44.352020Z", "iopub.status.idle": "2024-09-17T01:49:44.374799Z", "shell.execute_reply": "2024-09-17T01:49:44.374342Z", "shell.execute_reply.started": "2024-09-17T01:49:44.352780Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "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": "b6dd08b0-f58c-4dc1-86a9-e7b2b84478c3", "metadata": {}, "source": [ "## 获取人员测试成绩" ] }, { "cell_type": "code", "execution_count": 27, "id": "5d864909-d10f-461d-8e6e-dc5c43613576", "metadata": { "execution": { "iopub.execute_input": "2024-09-20T08:48:09.078723Z", "iopub.status.busy": "2024-09-20T08:48:09.077996Z", "iopub.status.idle": "2024-09-20T08:48:09.151435Z", "shell.execute_reply": "2024-09-20T08:48:09.150864Z", "shell.execute_reply.started": "2024-09-20T08:48:09.078657Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "934\n", "934\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", "\n", "filename = 'data/places_result_20240920.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", " #re_ta[user]['sub_unit'] = dict1[user]['sub_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", "\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": "a08c6b65-a390-451b-b1a5-fc474db40035", "metadata": {}, "source": [ "## 导出测试人员信息" ] }, { "cell_type": "code", "execution_count": 28, "id": "bc79f0d2-62a2-40c8-bd74-9c7ff17bec8e", "metadata": { "execution": { "iopub.execute_input": "2024-09-20T08:48:32.839532Z", "iopub.status.busy": "2024-09-20T08:48:32.838772Z", "iopub.status.idle": "2024-09-20T08:48:33.052265Z", "shell.execute_reply": "2024-09-20T08:48:33.051700Z", "shell.execute_reply.started": "2024-09-20T08:48:32.839461Z" } }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\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", " 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/镇海体测情况(截至20240920).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": "0c2dfa71-8680-4ec6-938d-d37eeba4d4f9", "metadata": {}, "source": [ "## 统计未体测人员明细表" ] }, { "cell_type": "code", "execution_count": 30, "id": "cf22739a-5cf3-47fd-b87a-158a2e2d5a95", "metadata": { "execution": { "iopub.execute_input": "2024-09-20T08:49:06.241970Z", "iopub.status.busy": "2024-09-20T08:49:06.241223Z", "iopub.status.idle": "2024-09-20T08:49:06.291731Z", "shell.execute_reply": "2024-09-20T08:49:06.291195Z", "shell.execute_reply.started": "2024-09-20T08:49:06.241901Z" } }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/result_镇海.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/镇海1.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "\n", "list1 = []\n", "\n", "i = 1\n", "for k, v in dict2.items(): \n", " if k not in dict1.keys():\n", " list2 = [i,k,v['name'],v['unit']]\n", " i+=1\n", " list1.append(list2)\n", "#print(list1)\n", "filename = f'data/镇海未测试人员名单.xlsx'\n", "title = ['序号','员工编号','姓名','部门']\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": "markdown", "id": "286a65eb-995f-4183-a4e5-6d907ba21151", "metadata": {}, "source": [ "## 清理重复人员" ] }, { "cell_type": "code", "execution_count": 29, "id": "f4dade65-f760-4220-8a65-39843688a60a", "metadata": { "execution": { "iopub.execute_input": "2024-09-20T08:48:41.723955Z", "iopub.status.busy": "2024-09-20T08:48:41.723229Z", "iopub.status.idle": "2024-09-20T08:48:41.926161Z", "shell.execute_reply": "2024-09-20T08:48:41.925529Z", "shell.execute_reply.started": "2024-09-20T08:48:41.723892Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1354\n", "1298\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/镇海.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "print(len(dict1))\n", "dict2 = {}\n", "for k, v in dict1.items():\n", " if 'phone' in v.keys():\n", " dict2.setdefault(k,{})\n", " dict2[k]['name'] = v['name']\n", " dict2[k]['phone'] = v['phone']\n", "\n", "list1 = []\n", "for k, v in dict2.items():\n", " i = 0\n", " for k1, v1 in dict1.items():\n", " if v['name']== v1['name'] and v['phone'] == v1['phone'] and k1 != k:\n", " list1.append(max(int(k),int(k1)))\n", "for item in set(list1):\n", " del dict1[str(item)]\n", "print(len(dict1))\n", "filename = 'data/镇海1.json'\n", "\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl, ensure_ascii=False) \n" ] }, { "cell_type": "code", "execution_count": null, "id": "ef930e32-9413-4fb0-b9e4-ba548d89ec60", "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 }