From 79717f30e87b7459aed2fbe4d5d9855b9eb2c36e Mon Sep 17 00:00:00 2001 From: 512song Date: Wed, 28 May 2025 09:59:33 +0800 Subject: [PATCH] 20250528 --- 体测单位/党建出版社.ipynb | 362 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 体测单位/党建出版社.ipynb diff --git a/体测单位/党建出版社.ipynb b/体测单位/党建出版社.ipynb new file mode 100644 index 0000000..70baec2 --- /dev/null +++ b/体测单位/党建出版社.ipynb @@ -0,0 +1,362 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "04524c85-988e-4dbf-86eb-939a9db7aa28", + "metadata": {}, + "source": [ + "## 体测人员导入" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bbba6efc-73cd-4db6-bae7-014724fee731", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-26T12:30:54.402556Z", + "iopub.status.busy": "2023-11-26T12:30:54.402097Z", + "iopub.status.idle": "2023-11-26T12:30:54.454920Z", + "shell.execute_reply": "2023-11-26T12:30:54.453841Z", + "shell.execute_reply.started": "2023-11-26T12:30:54.402519Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "\n", + "wb = openpyxl.load_workbook('data/党建出版社2025.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, 4).value\n", + " dict1['unit'] = '党建出版社'\n", + " dict1['birth'] = sheet.cell(n,3).value\n", + " dict1['phone'] = sheet.cell(n,5).value\n", + " person[code] = dict1\n", + "filename = 'data/党建出版社2025.json'\n", + "with open(filename, 'w') as fl:\n", + " json.dump(person, fl, ensure_ascii=False)\n", + "print('ok')" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9448933d-527c-410d-ba55-4ce1819a8c1e", + "metadata": { + "execution": { + "iopub.execute_input": "2025-05-28T01:56:09.248016Z", + "iopub.status.busy": "2025-05-28T01:56:09.247344Z", + "iopub.status.idle": "2025-05-28T01:56:09.438873Z", + "shell.execute_reply": "2025-05-28T01:56:09.438386Z", + "shell.execute_reply.started": "2025-05-28T01:56:09.247957Z" + } + }, + "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", + " 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, 4).value\n", + " dict1['birth'] = 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": "048a95aa-1691-45f6-b933-6eaf95ae1d30", + "metadata": {}, + "source": [ + "## 生成读卡系统文件" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "ce406710-6b7d-4c51-98ec-78883bd3ce5f", + "metadata": { + "execution": { + "iopub.execute_input": "2025-05-28T01:57:01.051560Z", + "iopub.status.busy": "2025-05-28T01:57:01.050181Z", + "iopub.status.idle": "2025-05-28T01:57:01.063491Z", + "shell.execute_reply": "2025-05-28T01:57:01.062383Z", + "shell.execute_reply.started": "2025-05-28T01:57:01.051490Z" + }, + "tags": [] + }, + "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':'编号卡'}\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": "6bcd45c2-10af-4d5f-9e0b-5cd1df4f7a7f", + "metadata": {}, + "source": [ + "## 获取人员测试成绩" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "970e171e-1360-448f-a28c-520ccb8f314a", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-26T12:31:39.094899Z", + "iopub.status.busy": "2023-11-26T12:31:39.094370Z", + "iopub.status.idle": "2023-11-26T12:31:39.114981Z", + "shell.execute_reply": "2023-11-26T12:31:39.114071Z", + "shell.execute_reply.started": "2023-11-26T12:31:39.094860Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "16\n", + "16\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_20231126.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_北京党校20231126.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": "d034a61d-1fbd-417b-99bd-277e43ebb678", + "metadata": {}, + "source": [ + "## 导出测试人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "867ad6b0-9e9d-48bc-a10a-3b9cb6125890", + "metadata": { + "tags": [] + }, + "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/北京党校.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": "699c6a40-a6ae-4300-9646-708cb85aa5e8", + "metadata": {}, + "source": [ + "## 手工数据导入数据库" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "def3f47a-24ef-4815-b63b-2a16b79b4c15", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "filename = 'data/北京党校.json'\n", + "with open(filename,'r') as fl:\n", + " dict2 = json.load(fl)\n", + "wb = openpyxl.load_workbook('data/北京党校手工数据.xlsx')\n", + "sheet = wb.active\n", + "# sheets = wb.sheetnames\n", + "dict1 = {}\n", + "dict3 = {1:10,2:11,3:7,4:2,5:6,6:3,7:1}\n", + "sheet = wb.active\n", + "data1 =list(sheet.values)\n", + "del data1[0]\n", + "list1 = []\n", + "for item in data1:\n", + " code = int(item[0])\n", + " list1.append((496534,code,item[2],item[1],'2023-10-15','2023-10-15 14:00:00'))\n", + "print(list1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "67e63f07-3f20-4e0e-9c07-7bf6024eeb4b", + "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 +}