{ "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/天宫院街道2024.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, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " \n", " \n", " dict1['sex'] = sheet.cell(n,3).value\n", " birth = str(sheet.cell(n, 4).value).split()[0]\n", " dict1['birth'] = birth.replace('/','-')\n", " \n", " person[code] = dict1\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/天宫院街道2024.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print('ok')" ] }, { "cell_type": "code", "execution_count": 8, "id": "b29a6f3c-035c-4c74-bbac-61e83be2b37c", "metadata": { "execution": { "iopub.execute_input": "2024-07-11T08:18:28.633340Z", "iopub.status.busy": "2024-07-11T08:18:28.632568Z", "iopub.status.idle": "2024-07-11T08:18:28.654035Z", "shell.execute_reply": "2024-07-11T08:18:28.653382Z", "shell.execute_reply.started": "2024-07-11T08:18:28.633268Z" } }, "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, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " person[code] = dict1\n", "filename = 'data/天宫院街道all.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", "re_ta = {}\n", "dict1 = {}\n", "list1 = []\n", "filename = 'data/天宫院街道2024.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20240710.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", " 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_天宫院街道2024.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": "code", "execution_count": 9, "id": "590775c3-16ef-43ad-99a2-85e847fe4079", "metadata": { "execution": { "iopub.execute_input": "2024-07-11T08:19:29.653063Z", "iopub.status.busy": "2024-07-11T08:19:29.652598Z", "iopub.status.idle": "2024-07-11T08:19:29.662479Z", "shell.execute_reply": "2024-07-11T08:19:29.661939Z", "shell.execute_reply.started": "2024-07-11T08:19:29.653037Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "61\n", "61\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/天宫院街道all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20240710.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", " 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_天宫院街道all.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": "dd96c378-f40c-4c21-b91e-78224a18e105", "metadata": {}, "source": [ "## 导出测试成绩" ] }, { "cell_type": "code", "execution_count": 10, "id": "c2ee2c71-7e28-4201-af85-ed7f001c6872", "metadata": { "execution": { "iopub.execute_input": "2024-07-11T08:19:59.192307Z", "iopub.status.busy": "2024-07-11T08:19:59.191555Z", "iopub.status.idle": "2024-07-11T08:19:59.221577Z", "shell.execute_reply": "2024-07-11T08:19:59.220830Z", "shell.execute_reply.started": "2024-07-11T08:19:59.192234Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "101 李先生\n" ] }, { "ename": "KeyError", "evalue": "'sex'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[10], line 20\u001b[0m\n\u001b[1;32m 18\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mstr\u001b[39m(k)\u001b[38;5;241m.\u001b[39mrjust(\u001b[38;5;241m3\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m 19\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(v[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]) \n\u001b[0;32m---> 20\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[43mdict2\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msex\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m)\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m items:\n\u001b[1;32m 24\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m v\u001b[38;5;241m.\u001b[39mkeys():\n", "\u001b[0;31mKeyError\u001b[0m: 'sex'" ] } ], "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/天宫院街道all.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/天宫院社区体测情况表_all.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": 11, "id": "ddba1233-6ab2-480d-8bde-ed8e1c34e48e", "metadata": { "execution": { "iopub.execute_input": "2024-07-11T08:20:48.587834Z", "iopub.status.busy": "2024-07-11T08:20:48.587065Z", "iopub.status.idle": "2024-07-11T08:20:48.615936Z", "shell.execute_reply": "2024-07-11T08:20:48.615410Z", "shell.execute_reply.started": "2024-07-11T08:20:48.587764Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "101 李有才\n", "44 星众豪\n", "94 谢红印\n", "14 孙一萂\n", "132 梁正文\n", "123 刘\n", "93 李洪芝\n", "71 李羽馨\n", "91 孙婧祎\n", "8 王红晶\n", "126 马\n", "125 陈\n", "6 刘艳\n", "96 薛颖\n", "2 刘书本\n", "40 杨春华\n", "9 霍思诺\n", "124 苗\n", "128 张\n", "78 朱蕊\n", "10 李晨曦\n", "5 李芳\n", "100 聂彦芹\n", "4 富红\n", "68 冯瑞文\n", "108 杨\n", "130 徐\n", "86 阎树芹\n", "83 张万成\n", "116 白景香\n", "103 王梓涵\n", "15 王慧兰\n", "36 冯玉红\n", "118 王玉芬\n", "102 王岩东\n", "19 张竹辰\n", "38 路德慧\n", "111 张\n", "37 张影\n", "25 孟现春\n", "41 朱朝云\n", "85 武宜国\n", "107 刘连英\n", "20 王韵琪\n", "7 李雪\n", "18 王真秀\n", "98 张建霞\n", "131 陈艳莉\n", "106 沈建新\n", "43 杨桂兰\n", "127 张\n", "39 韩润壮\n", "129 薛\n", "110 赵\n", "79 郭忠臣\n", "81 赵淑芬\n", "115 朱\n", "114 王淑云\n", "62 赵秀香\n", "31 张成林\n", "99 张东喜\n" ] } ], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "title = ['编号','姓名','性别','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "filename = 'data/result_天宫院街道all.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "filename = 'data/天宫院街道all.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", " \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/天宫院社区体测情况表_all.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": null, "id": "08ce9a37-b40c-4cb7-8c12-f18e2ecfc462", "metadata": { "tags": [] }, "outputs": [], "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }