diff --git a/体测单位/天宫院社区.ipynb b/体测单位/天宫院社区.ipynb new file mode 100644 index 0000000..eb28e6f --- /dev/null +++ b/体测单位/天宫院社区.ipynb @@ -0,0 +1,351 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a4aa8953-df5c-4389-a26b-254f4b07e8ff", + "metadata": {}, + "source": [ + "## 导入人员信息" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a03a5289-9766-4a60-9d38-245deb2ee4e6", + "metadata": { + "tags": [] + }, + "outputs": [], + "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", + "\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, 1).value)\n", + " person.setdefault(code, {})\n", + " dict1 = {}\n", + " dict1['name'] = sheet.cell(n, 2).value\n", + " \n", + " if sheet.cell(n,4).value is not None:\n", + " dict1['sex'] = sheet.cell(n,4).value\n", + " else:\n", + " dict1['sex'] = ''\n", + " dict1['birth'] = sheet.cell(n, 3).value\n", + " if sheet.cell(n,5).value is not None:\n", + " dict1['phone'] = sheet.cell(n,5).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": "6c1f6f1a-80cd-4451-a9ad-e706c4df9083", + "metadata": {}, + "source": [ + "## 生成手工记录插入格式" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7302951-5960-4686-808f-7e73aa66e025", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "filename = 'data/天宫院社区人员名单.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl) \n", + "filename = 'data/天宫院手工记录成绩.xlsx'\n", + "wb = openpyxl.load_workbook(filename)\n", + "sheet = wb.active\n", + "\n", + "s = ''\n", + "place = \"587256\"\n", + "sql = []\n", + "for n in range(2, sheet.max_row+1):\n", + " if sheet.cell(n,1).value is not None:\n", + " code = str(sheet.cell(n, 1).value)\n", + " print(code)\n", + " if dict1[code]['sex'] == '男':\n", + " item = 5\n", + " else:\n", + " item = 9\n", + " sj = '2023-04-20 22:00:00'\n", + " s = f'({place},{code},{item},{sheet.cell(n, 7).value},\"2023-04-20\",0,\"{sj}\")'\n", + " sql.append(s)\n", + "s = ','.join(sql)\n", + "print(s)" + ] + }, + { + "cell_type": "markdown", + "id": "be31057b-a543-4053-9209-307e9a8688c3", + "metadata": {}, + "source": [ + "## 获取人员测试成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db39190f-47d4-4a7c-b727-c79e2a64452f", + "metadata": { + "tags": [] + }, + "outputs": [], + "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/places_result_20230422.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", + " \n", + " m_item = str(result[3]) \n", + " re_ta.setdefault(user,{}) \n", + " re_ta[user]['name'] = dict1[user]['name']\n", + " if 'sex' in dict1[user].keys():\n", + " re_ta[user]['sex'] = dict1[user]['sex']\n", + " else:\n", + " re_ta[user]['sex'] = ' '\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", + " 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": "markdown", + "id": "dd96c378-f40c-4c21-b91e-78224a18e105", + "metadata": {}, + "source": [ + "## 导出测试成绩" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c2ee2c71-7e28-4201-af85-ed7f001c6872", + "metadata": { + "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", + " print(k,v['name'])\n", + " list2.append(str(k).rjust(3,'0'))\n", + " list2.append(v['name']) \n", + " list2.append(dict2[k]['sex'])\n", + " \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": "markdown", + "id": "39f2ae5b-c87d-4bb3-bbfb-574899136ed8", + "metadata": {}, + "source": [ + "## 体测报告更名分组" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "852cb395-ac79-4525-bb42-2d5078579a7b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import os,sys,shutil\n", + "import json\n", + "import math\n", + "import openpyxl\n", + "\n", + "fi_path = 'file/天宫院'\n", + "old = []\n", + "fl=os.listdir(fi_path)\n", + "\n", + "for fn in fl:\n", + " if os.path.isfile(fi_path + '/' + fn):\n", + " ofn = int(fn.split('.')[0])\n", + " old.append(ofn) \n", + "old.sort()\n", + "for n in old: \n", + " o_name = f'{fi_path}/{n}.pdf'\n", + " name = dict1[str(n)]['name']\n", + " n_name = f'{m_path}/{str(n).rjust(3,\"0\")}-{name}.pdf'\n", + " #print(o_name,n_name)\n", + " if not os.path.exists(n_name):\n", + " shutil.copyfile(o_name,n_name)\n", + " print(n_name)" + ] + }, + { + "cell_type": "markdown", + "id": "b8287c5d-c249-4e56-99e6-a7b0865127e0", + "metadata": {}, + "source": [ + "## 生成下载文件JSON文件" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "08ce9a37-b40c-4cb7-8c12-f18e2ecfc462", + "metadata": { + "execution": { + "iopub.execute_input": "2023-04-23T08:52:01.769840Z", + "iopub.status.busy": "2023-04-23T08:52:01.768890Z", + "iopub.status.idle": "2023-04-23T08:52:01.785005Z", + "shell.execute_reply": "2023-04-23T08:52:01.783964Z", + "shell.execute_reply.started": "2023-04-23T08:52:01.769799Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n" + ] + } + ], + "source": [ + "import os,sys,shutil\n", + "import json\n", + "import math\n", + "import openpyxl\n", + "\n", + "filename = 'data/天宫院社区人员名单.json'\n", + "with open(filename,'r') as fl:\n", + " dict1 = json.load(fl)\n", + "fi_path = 'file/天宫院'\n", + "old = []\n", + "fl=os.listdir(fi_path)\n", + "\n", + "for fn in fl:\n", + " if os.path.isfile(fi_path + '/' + fn):\n", + " ofn = int(fn.split('.')[0])\n", + " old.append(ofn) \n", + "old.sort()\n", + "dict2 = {}\n", + "for n in old:\n", + " if str(n) in dict1.keys() and 'phone' in dict1[str(n)].keys():\n", + " dict2[n] = {'name':dict1[str(n)]['name'].strip(),'phone':str(dict1[str(n)]['phone']).strip()}\n", + " \n", + "filename = 'data/tiangongyuan.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict2, fl, ensure_ascii=False) \n", + "print('ok') \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07d4850a-fccd-4759-b360-3762ada7c5b2", + "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 +}