{ "cells": [ { "cell_type": "markdown", "id": "bf152e7d-6a36-4877-98d9-f11e3a73792e", "metadata": {}, "source": [ "## 导入人员信息" ] }, { "cell_type": "code", "execution_count": null, "id": "1b92b7c5-cb77-49da-95b7-34827ecf1d16", "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", "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", " if sheet.cell(n, 7).value ==1:\n", " sex = '男'\n", " else:\n", " sex = '女'\n", " dict1['sex'] = sheet.cell(n, 3).value\n", " birth = str(sheet.cell(n, 6).value).split()[0]\n", " dict1['birth'] = birth\n", " if sheet.cell(n,5).value is not None:\n", " dict1['phone'] = sheet.cell(n, 5).value\n", " if sheet.cell(n,7).value is not None:\n", " dict1['id_num'] = sheet.cell(n, 7).value\n", " if sheet.cell(n,8).value is not None:\n", " dict1['SAP'] = sheet.cell(n, 8).value\n", " if sheet.cell(n,9).value is not None:\n", " dict1['工作单位'] = sheet.cell(n, 9).value\n", " if sheet.cell(n,10).value is not None:\n", " dict1['车间'] = sheet.cell(n, 10).value\n", " else:\n", " dict1['车间'] =''\n", " if sheet.cell(n,11).value is not None:\n", " dict1['班组'] = sheet.cell(n, 11).value\n", " else:\n", " dict1['班组'] =''\n", " if sheet.cell(n,12).value is not None:\n", " dict1['工作性质'] = sheet.cell(n, 11).value\n", " person[code] = dict1\n", "#jianyuan = [6484,7110,6441,6541,6543,6549,6555,6600,2958,2981,3033,3231,3249,3287,3228,7741,7749,7794,7799,7806,7837,7863,7870,7880,7894,7895,7904,7936,7947,7953,7958,7968,7969,7974,8086,8114]\n", "\n", "print(len(person))\n", "#for k in jianyuan:\n", "# if k in person.keys():\n", "# del person[k]\n", "print(len(person))\n", "#bianwai =[449,6839]\n", "#for i in range(7139,7200):\n", "# bianwai.append(i)\n", "#for k in bianwai:\n", "# if k in person.keys():\n", "# del person[k]\n", "print(len(person))\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": "f5c73dff-697d-4ba5-a90c-9bed68eaf4b3", "metadata": {}, "source": [ "## 每日成绩导入" ] }, { "cell_type": "code", "execution_count": null, "id": "71e1ec6a-6797-4496-969a-1d1461b9ea58", "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/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20230517.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]['部门'] = dict1[user]['工作单位']\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 = 'data/result_燕山石化(20230517).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": "79147ba8-4b90-40ba-81a9-e6062600c239", "metadata": {}, "source": [ "## 每日成绩导出" ] }, { "cell_type": "code", "execution_count": null, "id": "c24880ad-bbbd-4ad8-a894-cbcea389e822", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "title = ['编号','姓名','性别','单位','车间','班组','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_燕山石化(20230517).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]['工作单位']) \n", " list2.append(dict2[k]['车间'])\n", " list2.append(dict2[k]['班组'])\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/燕山石化体测情况表(20230517).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": "1cd93a0e-8340-4bd0-a8fd-747f149b256d", "metadata": {}, "source": [ "## 总成绩导出" ] }, { "cell_type": "code", "execution_count": null, "id": "79c9c728-12e9-4107-bc5a-8c3e3d8b64a6", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "title = ['编号','姓名','性别','单位','车间','班组','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_燕山石化-all.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]['工作单位']) \n", " list2.append(dict2[k]['车间'])\n", " list2.append(dict2[k]['班组'])\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": "6d431fc1-b743-467c-91b3-9788e245becb", "metadata": {}, "source": [ "## 统计部门测试人数" ] }, { "cell_type": "code", "execution_count": null, "id": "68454877-f1fe-4eed-8a48-265e428f892e", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "filename = 'data/result_燕山石化(20230516).json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "dict2 = {}\n", "for k, v in dict1.items():\n", " unit = v['部门']\n", " dict2.setdefault(unit,0)\n", " dict2[unit] = dict2[unit] + 1\n", "print(dict2)\n", "title =['单位','体测人数']\n", "list1 = [] \n", "for k, v in dict2.items():\n", " list2 = []\n", " list2 = [k,v]\n", " list1.append(list2)\n", "filename = 'data/燕山石化部门测试人数情况表(20230516).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": "8becc0af-d22b-46a2-b35e-9122942515d4", "metadata": {}, "source": [ "## 每日未测试人员情况表" ] }, { "cell_type": "code", "execution_count": null, "id": "7085bf6f-7465-44fb-bddb-38130fbe5618", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "title = ['编号','姓名','性别','单位','车间','班组']\n", "filename = 'data/result_燕山石化(20230417).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", "list1 = []\n", "for k, v in dict2.items():\n", " list2 = []\n", " if k not in dict1.keys():\n", " list2.append(str(k).rjust(5,'0'))\n", " list2.append(v['name']) \n", " list2.append(dict2[k]['sex'])\n", " list2.append(dict2[k]['工作单位']) \n", " list2.append(dict2[k]['车间'])\n", " list2.append(dict2[k]['班组'])\n", " list1.append(list2)\n", "filename = 'data/燕山石化未体测人员名单(20230417).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": "3231f52d-776f-4d29-b6f5-c28f6a0c30a9", "metadata": {}, "source": [ "## 汇总未测试人员情况表" ] }, { "cell_type": "code", "execution_count": null, "id": "eddf7dab-b28d-402a-aeaf-27c120048ecb", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "\n", "\n", "title = ['编号','姓名','性别','单位','车间','班组']\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "# 筛选重名剔除名单\n", "chongming = []\n", "filename = 'data/燕山石化重名人员测试情况(20230515).xlsx'\n", "wb = openpyxl.load_workbook(filename)\n", "sheet = wb.active\n", "for n in range(1, sheet.max_row+1,2):\n", " if sheet.cell(n,1).value is not None:\n", " code1 = int(sheet.cell(n, 1).value)\n", " code2 = int(sheet.cell(n+1, 1).value)\n", " bz1 = sheet.cell(n, 4).value\n", " bz2 = sheet.cell(n+1, 4).value\n", " if bz1 =='否' and bz2 =='否':\n", " chongming.append(max(code1,code2))\n", " else:\n", " chongming.append(code1)\n", " chongming.append(code2)\n", "\n", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl)\n", "list1 = []\n", "for k, v in dict2.items():\n", " list2 = []\n", " if k not in dict1.keys() and int(k) not in chongming:\n", " list2.append(str(k).rjust(5,'0'))\n", " list2.append(v['name']) \n", " list2.append(dict2[k]['sex'])\n", " list2.append(dict2[k]['工作单位']) \n", " list2.append(dict2[k]['车间'])\n", " list2.append(dict2[k]['班组'])\n", " list1.append(list2)\n", "filename = 'data/燕山石化未体测人员名单(截至20230516).xlsx'\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": "4dd9b2b7-bd3d-4d5b-ac84-3a49bcada8b5", "metadata": {}, "source": [ "## 统计测试项目不足人员" ] }, { "cell_type": "code", "execution_count": 73, "id": "641863ef-324f-4c33-a0a9-699031afb6f1", "metadata": { "execution": { "iopub.execute_input": "2023-05-26T14:47:09.071920Z", "iopub.status.busy": "2023-05-26T14:47:09.071521Z", "iopub.status.idle": "2023-05-26T14:47:09.257365Z", "shell.execute_reply": "2023-05-26T14:47:09.256643Z", "shell.execute_reply.started": "2023-05-26T14:47:09.071892Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[]\n" ] } ], "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", "dict3 = {}\n", "for k, v in dict1.items():\n", " list1 = []\n", " for item in v.keys():\n", " if item in items:\n", " list1.append(item)\n", " dict3[k] = list1\n", "list1 = []\n", "for k, v in dict3.items():\n", " if len(v)<4 and '身高' in v and '体重' in v or ((len(v)<3 and '身高' not in v and '体重' not in v)):\n", " list2 = []\n", " xm = ','.join(v)\n", " list2.append(k)\n", " list2.append(dict2[k]['name'])\n", " list2.append(dict2[k]['工作单位'])\n", " list2.append(xm)\n", " list1.append(list2)\n", "print(list1)\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) \n" ] }, { "cell_type": "markdown", "id": "d3a69840-29fc-434d-af47-ad864f9e511c", "metadata": {}, "source": [ "## 汇总成绩导入" ] }, { "cell_type": "code", "execution_count": null, "id": "b735248a-c1b0-4e90-8df4-37cd7625cb1a", "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/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "filename = 'data/places_result_20230526.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]['部门'] = dict1[user]['工作单位']\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 = 'data/result_燕山石化.json'\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": "fbdf2c54-7303-43ad-bbec-0fbcd033603a", "metadata": {}, "source": [ "## 统计测试人数" ] }, { "cell_type": "code", "execution_count": null, "id": "6d10738f-8da8-4f18-970b-e67433a06661", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import time\n", "import csv\n", "\n", "person = set()\n", "filename = 'data/places_result_20230526.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", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "\n", "for result in list1:\n", " user = str(result[2])\n", " if user in dict1.keys():\n", " person.add(user)\n", "\n", "print(len(person))" ] }, { "cell_type": "markdown", "id": "5bdcad97-309f-4d29-82c4-b53c68b9ee22", "metadata": {}, "source": [ "## 统计重复人员信息" ] }, { "cell_type": "code", "execution_count": null, "id": "0dd5da15-92e0-45c2-b9e9-11417210974e", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import time\n", "import csv\n", "\n", "\n", "list1 = []\n", "list2 = set()\n", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/result_燕山石化-all.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "\n", "for k,v in dict1.items():\n", " name = v['name']\n", " if name in list1:\n", " list2.add(name)\n", " list1.append(name)\n", "list3 = []\n", "for item in list2:\n", " for k,v in dict1.items():\n", " if v['name'] == item:\n", " list3.append([k,v['name'],v['sex'],v['birth']])\n", "filename = 'data/燕山石化重名人员名单.xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "#sheet.append(title)\n", "for row in list3:\n", " sheet.append(row)\n", " \n", "wb.save(filename) " ] }, { "cell_type": "markdown", "id": "96375506-0cca-4a9b-b0da-162460d25e51", "metadata": {}, "source": [ "## 重复人员测试情况" ] }, { "cell_type": "code", "execution_count": null, "id": "5df8eb8f-3594-40be-a491-b4d750bbd554", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import time\n", "import csv\n", "\n", "\n", "list1 = []\n", "list2 = set()\n", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict2 = json.load(fl) \n", "\n", "\n", "list3 = []\n", "\n", "filename = 'data/燕山石化重名人员名单.xlsx'\n", "wb = openpyxl.load_workbook(filename)\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "\n", "\n", "for n in range(1, sheet.max_row+1):\n", " if sheet.cell(n,1).value is not None:\n", " code = int(sheet.cell(n, 1).value)\n", " name = dict1[str(code)]['name']\n", " unit = dict1[str(code)]['工作单位']\n", " if str(code) in dict2.keys():\n", " ce = '是'\n", " else:\n", " ce = '否'\n", " list3.append([code,name,unit,ce])\n", "filename = 'data/燕山石化重名人员测试情况(20230516).xlsx'\n", "wb = openpyxl.Workbook()\n", "sheet = wb.active\n", "#sheet.append(title)\n", "for row in list3:\n", " sheet.append(row)\n", " \n", "wb.save(filename) " ] }, { "cell_type": "markdown", "id": "0513a787-f2e2-4ee6-9c67-c94c50e62393", "metadata": {}, "source": [ "## 统计部门测试情况" ] }, { "cell_type": "code", "execution_count": null, "id": "48a0b2b8-c069-4d2d-9813-d65474749000", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "import openpyxl\n", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict3 = json.load(fl)\n", "dict2 = {}\n", "for k, v in dict1.items():\n", " unit = v['工作单位']\n", " dict2.setdefault(unit,0)\n", " dict2[unit] = dict2[unit] + 1\n", "dict4 = {}\n", "for k, v in dict3.items():\n", " unit = v['部门']\n", " dict4.setdefault(unit,0)\n", " dict4[unit] = dict4[unit] + 1\n", "list1 = []\n", "for k, v in dict2.items():\n", " list2 = []\n", " list2.append(k)\n", " list2.append(v)\n", " if k in dict4.keys():\n", " list2.append(dict4[k])\n", " else:\n", " list2.append(0)\n", " list1.append(list2)\n", "print(list1)\n", "filename = 'data/燕山石化部门测试情况(截止5月6日).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) \n" ] }, { "cell_type": "code", "execution_count": null, "id": "c294db76-adc4-41bf-9ee6-811dde1905e8", "metadata": { "tags": [] }, "outputs": [], "source": [ "#C2EDC1A2D1C7\n", "gbs = 'C2EDC1A2D1C7'\n", "import binascii\n", "bs = binascii.a2b_hex(gbs)\n", "print('bs', bs)\n", "print('decode-bs:', bs.decode('gb2312'))" ] }, { "cell_type": "code", "execution_count": null, "id": "9924d06a-8753-4856-9ccc-f3d5f8956bb2", "metadata": { "tags": [] }, "outputs": [], "source": [ "s = '马立亚'\n", "gbcode = s.encode('gb2312') # 先转成 bytes格式\n", "print('gbcode:', gbcode)\n", "gbs = \"\".join([hex(ch)[2:] for ch in gbcode]) #\n", "print('gbs:', gbs)" ] }, { "cell_type": "markdown", "id": "ce1487ed-2b11-4a3c-a305-5499af4526d1", "metadata": {}, "source": [ "## 数据分析" ] }, { "cell_type": "markdown", "id": "08500016-4f33-446c-bc44-28e0a22a591a", "metadata": {}, "source": [ "### 获取清理后数据" ] }, { "cell_type": "code", "execution_count": 106, "id": "aab3ed2b-54f1-42de-8e83-cc559827a4b5", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:09.829773Z", "iopub.status.busy": "2023-05-27T13:07:09.829372Z", "iopub.status.idle": "2023-05-27T13:07:10.760194Z", "shell.execute_reply": "2023-05-27T13:07:10.759179Z", "shell.execute_reply.started": "2023-05-27T13:07:09.829747Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "7734\n", "['3520', '7790', '3125', '4025', '3231', '5690', '4551']\n", "7727\n", "ok\n", "7727\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", "filename = 'data/燕山石化人员名单.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "\n", "re_ta = {}\n", "list1 = []\n", "#print(\"\\n运动项目信息:\")\n", "filename = 'data/places_result_20230527.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]['unit'] = dict1[user]['工作单位']\n", " re_ta[user]['sex'] = dict1[user]['sex']\n", " re_ta[user]['birth'] = dict1[user]['birth'].replace('-','/')\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[5]\n", "filename = 'data/result_燕山石化1.json'\n", "print(len(re_ta))\n", "liwai = []\n", "for k, v in re_ta.items():\n", " if (len(v)<8 and '身高' in v and '体重' in v) or (len(v)<7 and '身高' not in v and '体重' not in v) :\n", " liwai.append(k)\n", "print(liwai)\n", "for k in liwai:\n", " del re_ta[k]\n", "print(len(re_ta))\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(re_ta, fl) \n", "print('ok')\n", "print(len(re_ta))" ] }, { "cell_type": "markdown", "id": "a3ce7905-c849-48dc-996c-2eeee59e75aa", "metadata": {}, "source": [ "### 计算人员年龄" ] }, { "cell_type": "code", "execution_count": 107, "id": "9851d728-8c85-48fd-b7d6-d0104318e89d", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:15.219600Z", "iopub.status.busy": "2023-05-27T13:07:15.219207Z", "iopub.status.idle": "2023-05-27T13:07:15.684092Z", "shell.execute_reply": "2023-05-27T13:07:15.683071Z", "shell.execute_reply.started": "2023-05-27T13:07:15.219573Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "import datetime\n", "\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "for k, v in dict1.items(): \n", " birth = v['birth'].split()[0].split('/') \n", " nian = int(birth[0].strip())\n", " yue = int(birth[1].strip())\n", " ri = int(birth[2].strip())\n", " #print(k,nian,yue,ri)\n", " days = (datetime.date(2023, 5, 18)-datetime.date(nian,yue,ri)).days\n", " v['age'] = round(days/365)\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok') " ] }, { "cell_type": "code", "execution_count": 99, "id": "e0f26f0a-6374-4903-a6c9-99cf25e5db2a", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T12:56:45.270021Z", "iopub.status.busy": "2023-05-27T12:56:45.269580Z", "iopub.status.idle": "2023-05-27T12:56:45.401202Z", "shell.execute_reply": "2023-05-27T12:56:45.400687Z", "shell.execute_reply.started": "2023-05-27T12:56:45.269990Z" }, "tags": [] }, "outputs": [], "source": [ "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "for k,v in dict1.items():\n", " if v['age'] < 19:\n", " print(k,v['name'],v['age'] )\n" ] }, { "cell_type": "markdown", "id": "34ae5549-b31c-481e-986a-e1ad8bb1ccc5", "metadata": {}, "source": [ "### 汇总人员信息及成绩" ] }, { "cell_type": "code", "execution_count": 108, "id": "d171e87d-9709-4de8-8261-e1eb4343e002", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:18.957951Z", "iopub.status.busy": "2023-05-27T13:07:18.957558Z", "iopub.status.idle": "2023-05-27T13:07:19.475930Z", "shell.execute_reply": "2023-05-27T13:07:19.475170Z", "shell.execute_reply.started": "2023-05-27T13:07:18.957923Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "\n", "\n", "items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for k,v in dict1.items():\n", " score = 0\n", " i = 0 \n", " for k1,v1 in v.items(): \n", " if k1 in items:\n", " score = score + int(v1['得分'])\n", " i+=1\n", " dict1[k]['score'] = round(score/i,2) \n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "8ccea925-2396-4dd9-8cc7-731f11aa3529", "metadata": {}, "source": [ "### 计算测试等级" ] }, { "cell_type": "code", "execution_count": 109, "id": "864da63f-bc6a-4246-81ec-e626680cf300", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:24.343430Z", "iopub.status.busy": "2023-05-27T13:07:24.342578Z", "iopub.status.idle": "2023-05-27T13:07:24.834062Z", "shell.execute_reply": "2023-05-27T13:07:24.833272Z", "shell.execute_reply.started": "2023-05-27T13:07:24.343389Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0~255分人数:3667人,男性:3136人,女性:531人\n", "256~332分人数:3117人,男性:2033人,女性:1084人\n", "333~367分人数:745人,男性:383人,女性:362人\n", "368~500分人数:198人,男性:74人,女性:124人\n", "ok\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "\n", "for k1, v1 in dict2.items():\n", " di = v1[0]\n", " gao = v1[1]\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if int(v['score']*100) in range(di,gao+1):\n", " dict1[k]['level'] = k1\n", " i+=1\n", " if v['sex'] == '男':\n", " m = m +1\n", " else:\n", " f = f+1\n", " print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "c58f8632-7588-4f4d-8117-91f1a7b11688", "metadata": {}, "source": [ "### 根据年龄汇总人员信息及成绩" ] }, { "cell_type": "code", "execution_count": 110, "id": "b605b817-da5f-407f-916b-ce4750727335", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:41.685574Z", "iopub.status.busy": "2023-05-27T13:07:41.685226Z", "iopub.status.idle": "2023-05-27T13:07:41.804179Z", "shell.execute_reply": "2023-05-27T13:07:41.803229Z", "shell.execute_reply.started": "2023-05-27T13:07:41.685551Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20~24岁平均成绩:2.4分,人数:429人,男性:312人\n", "25~29岁平均成绩:2.58分,人数:400人,男性:245人\n", "30~34岁平均成绩:2.6分,人数:309人,男性:210人\n", "35~39岁平均成绩:2.7分,人数:553人,男性:317人\n", "40~44岁平均成绩:2.57分,人数:1339人,男性:844人\n", "45~49岁平均成绩:2.55分,人数:1687人,男性:1071人\n", "50~54岁平均成绩:2.53分,人数:1920人,男性:1559人\n", "55~69岁平均成绩:2.43分,人数:1090人,男性:1068人\n" ] } ], "source": [ "import json\n", "\n", "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " i = 1\n", " score = 0\n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1):\n", " score = score+v['score']\n", " i+=1\n", " if v['sex'] == '男':\n", " m = m +1\n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人,男性:{m}人')" ] }, { "cell_type": "markdown", "id": "1ea7f10f-7c80-4888-a00e-69dbaeceb100", "metadata": {}, "source": [ "#### 根据年龄汇总人员信息及成绩(男)" ] }, { "cell_type": "code", "execution_count": 111, "id": "96506507-439f-42b5-93f7-bcba8930dae9", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:07:48.465152Z", "iopub.status.busy": "2023-05-27T13:07:48.464314Z", "iopub.status.idle": "2023-05-27T13:07:48.630296Z", "shell.execute_reply": "2023-05-27T13:07:48.629582Z", "shell.execute_reply.started": "2023-05-27T13:07:48.465113Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20~24岁平均成绩:2.31分,人数:312人\n", "25~29岁平均成绩:2.44分,人数:245人\n", "30~34岁平均成绩:2.43分,人数:210人\n", "35~39岁平均成绩:2.5分,人数:317人\n", "40~44岁平均成绩:2.43分,人数:844人\n", "45~49岁平均成绩:2.38分,人数:1071人\n", "50~54岁平均成绩:2.44分,人数:1559人\n", "55~80岁平均成绩:2.41分,人数:1068人\n" ] } ], "source": [ "import json\n", "\n", "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " i = 1\n", " score = 0\n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1) and v['sex'] == '男':\n", " score = score+v['score']\n", " i+=1\n", " \n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')" ] }, { "cell_type": "markdown", "id": "bd906618-8b50-450d-bb32-a2554da91b9a", "metadata": {}, "source": [ "#### 根据年龄汇总人员信息及成绩(女)" ] }, { "cell_type": "code", "execution_count": 112, "id": "10cc353b-32cb-45eb-9362-da22b170c301", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:02.434443Z", "iopub.status.busy": "2023-05-27T13:08:02.434037Z", "iopub.status.idle": "2023-05-27T13:08:02.593896Z", "shell.execute_reply": "2023-05-27T13:08:02.593181Z", "shell.execute_reply.started": "2023-05-27T13:08:02.434415Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20~24岁平均成绩:2.63分,人数:117人\n", "25~29岁平均成绩:2.8分,人数:155人\n", "30~34岁平均成绩:2.95分,人数:99人\n", "35~39岁平均成绩:2.95分,人数:236人\n", "40~44岁平均成绩:2.79分,人数:495人\n", "45~49岁平均成绩:2.84分,人数:616人\n", "50~54岁平均成绩:2.94分,人数:361人\n", "55~80岁平均成绩:2.91分,人数:22人\n" ] } ], "source": [ "import json\n", "\n", "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "filename = 'data/result_燕山石化.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " i = 1\n", " score = 0\n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1) and v['sex'] == '女':\n", " score = score+v['score']\n", " i+=1\n", " \n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')" ] }, { "cell_type": "markdown", "id": "f0c57ed7-4ab6-4415-aac4-f55ca117743e", "metadata": {}, "source": [ "### 计算平均成绩" ] }, { "cell_type": "code", "execution_count": 113, "id": "532b4d97-df50-4fd9-9e85-1181afcd366e", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:06.957835Z", "iopub.status.busy": "2023-05-27T13:08:06.957012Z", "iopub.status.idle": "2023-05-27T13:08:07.096914Z", "shell.execute_reply": "2023-05-27T13:08:07.096024Z", "shell.execute_reply.started": "2023-05-27T13:08:06.957795Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "平均成绩:2.4206分,男性:5626人\n", "平均成绩:2.859分,女性:2101人\n", "平均成绩:2.5398分,总体:7727人\n" ] } ], "source": [ "import json\n", "\n", "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "#filename = 'data/result_石家庄.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "i = 1\n", "m = 0\n", "f = 0\n", "score = 0\n", "t_score = 0\n", "for k,v in dict1.items():\n", " if v['sex'] == '男':\n", " m = m +1\n", " score = score+v['score']\n", "print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')\n", "t_score = t_score + score\n", "score = 0\n", "for k,v in dict1.items():\n", " if v['sex'] == '女':\n", " f = f +1\n", " score = score+v['score']\n", "print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n", "t_score = t_score + score\n", "print(f'平均成绩:{round(t_score/7727,4)}分,总体:7727人')" ] }, { "cell_type": "markdown", "id": "b18769df-ccfb-4013-82ea-51e6a3e24565", "metadata": {}, "source": [ "### 计算测试等级" ] }, { "cell_type": "code", "execution_count": 114, "id": "4377cf1d-83f0-4e6b-819f-f274915886b9", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:27.764353Z", "iopub.status.busy": "2023-05-27T13:08:27.763918Z", "iopub.status.idle": "2023-05-27T13:08:28.264684Z", "shell.execute_reply": "2023-05-27T13:08:28.263691Z", "shell.execute_reply.started": "2023-05-27T13:08:27.764325Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0~255分人数:3667人,男性:3136人,女性:531人\n", "256~332分人数:3117人,男性:2033人,女性:1084人\n", "333~367分人数:745人,男性:383人,女性:362人\n", "368~500分人数:198人,男性:74人,女性:124人\n", "ok\n" ] } ], "source": [ "import json\n", "\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "\n", "for k1, v1 in dict2.items():\n", " di = v1[0]\n", " gao = v1[1]\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if int(v['score']*100) in range(di,gao+1):\n", " dict1[k]['level'] = k1\n", " i+=1\n", " if v['sex'] == '男':\n", " m = m +1\n", " else:\n", " f = f+1\n", " print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n", "#filename = 'data/result_石家庄.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "ee6b0500-bf94-458f-8d1c-0e75e8dcc1f5", "metadata": {}, "source": [ "### 计算各年龄段测试等级(女)" ] }, { "cell_type": "code", "execution_count": 115, "id": "4fafdc11-c93b-4a8d-854e-61748713d0f8", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:31.927585Z", "iopub.status.busy": "2023-05-27T13:08:31.927169Z", "iopub.status.idle": "2023-05-27T13:08:32.089666Z", "shell.execute_reply": "2023-05-27T13:08:32.088681Z", "shell.execute_reply.started": "2023-05-27T13:08:31.927557Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20-24 {'不合格': 44, '合格': 65, '良好': 5, '优秀': 3}\n", "25-29 {'不合格': 43, '良好': 35, '合格': 74, '优秀': 3}\n", "30-34 {'不合格': 17, '合格': 58, '良好': 19, '优秀': 5}\n", "35-39 {'不合格': 44, '合格': 128, '良好': 52, '优秀': 12}\n", "40-44 {'良好': 72, '不合格': 146, '合格': 241, '优秀': 36}\n", "45-49 {'不合格': 167, '合格': 316, '优秀': 38, '良好': 95}\n", "50-54 {'不合格': 65, '合格': 193, '良好': 77, '优秀': 26}\n", "55-80 {'合格': 9, '不合格': 5, '优秀': 1, '良好': 7}\n" ] } ], "source": [ "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "dict3 = {}\n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " age = f'{di}-{gao}'\n", " dict3.setdefault(age,{})\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1): \n", " dict3[age].setdefault(v['level'],0)\n", " if v['sex'] == '女':\n", " dict3[age][v['level']] = dict3[age][v['level']]+1\n", " \n", "for k, v in dict3.items():\n", " print(k,v)" ] }, { "cell_type": "markdown", "id": "bebb0307-62e7-458c-a78a-90c593595a67", "metadata": {}, "source": [ "### 计算各年龄段测试等级(男)" ] }, { "cell_type": "code", "execution_count": 116, "id": "cae4d5b6-20ef-4a24-91ea-59ddc691349a", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:35.357895Z", "iopub.status.busy": "2023-05-27T13:08:35.357070Z", "iopub.status.idle": "2023-05-27T13:08:35.520889Z", "shell.execute_reply": "2023-05-27T13:08:35.520000Z", "shell.execute_reply.started": "2023-05-27T13:08:35.357854Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20-24 {'不合格': 204, '合格': 96, '良好': 11, '优秀': 1}\n", "25-29 {'不合格': 140, '良好': 19, '合格': 84, '优秀': 2}\n", "30-34 {'不合格': 111, '合格': 81, '良好': 15, '优秀': 3}\n", "35-39 {'不合格': 161, '合格': 124, '良好': 27, '优秀': 5}\n", "40-44 {'良好': 63, '不合格': 462, '合格': 302, '优秀': 17}\n", "45-49 {'不合格': 606, '合格': 389, '优秀': 11, '良好': 65}\n", "50-54 {'不合格': 853, '合格': 567, '良好': 117, '优秀': 22}\n", "55-80 {'合格': 390, '不合格': 599, '优秀': 13, '良好': 66}\n" ] } ], "source": [ "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "dict3 = {}\n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " age = f'{di}-{gao}'\n", " dict3.setdefault(age,{})\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1): \n", " dict3[age].setdefault(v['level'],0)\n", " if v['sex'] == '男':\n", " dict3[age][v['level']] = dict3[age][v['level']]+1\n", " \n", "for k, v in dict3.items():\n", " print(k,v)" ] }, { "cell_type": "markdown", "id": "f7ce0701-4f39-46fd-b284-2274abf7d329", "metadata": {}, "source": [ "### 按照部门计算平均成绩" ] }, { "cell_type": "code", "execution_count": 117, "id": "9d5660b9-2046-4319-b2c2-29ba5ddf818f", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:41.550284Z", "iopub.status.busy": "2023-05-27T13:08:41.549870Z", "iopub.status.idle": "2023-05-27T13:08:41.722994Z", "shell.execute_reply": "2023-05-27T13:08:41.722259Z", "shell.execute_reply.started": "2023-05-27T13:08:41.550257Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "热电厂工会 2.41 681\n", "炼油厂工会 2.48 1006\n", "有机化工厂工会 2.57 446\n", "储运厂工会 2.37 983\n", "合成橡胶厂工会 2.46 713\n", "检验计量中心工会 2.62 632\n", "烯烃厂工会 2.59 410\n", "化学品厂工会 2.4 368\n", "合成树脂厂 2.46 443\n", "生产运行保障中心 2.56 371\n", "高科公司工会 2.69 304\n", "机关工会 2.84 378\n", "行政事务中心(离退中心)工会 2.76 524\n", "教育培训中心工会 2.73 72\n", "物装中心工会 2.67 182\n", "消防中心工会 2.81 214\n" ] } ], "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "depart = []\n", "for k, v in dict1.items():\n", " if v['unit'] not in depart:\n", " depart.append(v['unit'])\n", "\n", "for item in depart:\n", " score = 0\n", " n = 0\n", " for k, v in dict1.items():\n", " if item == v['unit']:\n", " score = score + v['score']\n", " n = n +1 \n", " print(item,round(score/n,2),n)\n", " " ] }, { "cell_type": "markdown", "id": "d9122bbd-5767-4fe5-9bb2-c4d73a27a433", "metadata": {}, "source": [ "### 计算各项目成绩" ] }, { "cell_type": "code", "execution_count": 118, "id": "38d9f91d-18de-4df1-8179-03579008c2d0", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:45.314635Z", "iopub.status.busy": "2023-05-27T13:08:45.314235Z", "iopub.status.idle": "2023-05-27T13:08:45.484153Z", "shell.execute_reply": "2023-05-27T13:08:45.483219Z", "shell.execute_reply.started": "2023-05-27T13:08:45.314607Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "体重 3.41 7724\n", "肺活量 2.96 7651\n", "握力 2.36 7677\n", "坐位体前屈 2.78 6752\n", "纵跳 1.89 7302\n", "俯卧撑 1.99 4557\n", "一分钟仰卧起坐 3.81 1680\n", "单脚站立 1.7 7561\n", "选择反应时 2.76 7579\n", "台阶指数 2.77 5257\n" ] } ], "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "for item in items:\n", " score = 0\n", " n = 0\n", " for k, v in dict1.items():\n", " if item in v.keys():\n", " n = n + 1\n", " score =score + int(v[item]['得分'])\n", " print(item,round(score/n,2),n)" ] }, { "cell_type": "markdown", "id": "bce1d676-d5f5-47b0-8a51-a1bb74a66674", "metadata": {}, "source": [ "### 生成倒班人员信息表" ] }, { "cell_type": "code", "execution_count": 119, "id": "0bf8400c-060e-420e-ba66-04fb67bfc09a", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:08:51.679613Z", "iopub.status.busy": "2023-05-27T13:08:51.678996Z", "iopub.status.idle": "2023-05-27T13:08:54.061451Z", "shell.execute_reply": "2023-05-27T13:08:54.060702Z", "shell.execute_reply.started": "2023-05-27T13:08:51.679572Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3478\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", "daoban = {}\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \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", " if sheet.cell(n, 12).value == '倒班' and str(code) in dict1.keys():\n", " daoban[str(code)] = dict1[str(code)]\n", "\n", "filename = 'data/daoban_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(daoban, fl, ensure_ascii=False) \n", "print(len(daoban)) " ] }, { "cell_type": "markdown", "id": "8b6e02ac-0ce7-4cd3-8da9-025d93a24a53", "metadata": {}, "source": [ "### 倒班人员构成" ] }, { "cell_type": "code", "execution_count": 120, "id": "daa09874-e7a1-4aaa-b648-023e8358adfb", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:09:05.580283Z", "iopub.status.busy": "2023-05-27T13:09:05.579869Z", "iopub.status.idle": "2023-05-27T13:09:05.825237Z", "shell.execute_reply": "2023-05-27T13:09:05.824360Z", "shell.execute_reply.started": "2023-05-27T13:09:05.580256Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0~255分人数:1933人,男性:1675人,女性:258人\n", "256~332分人数:1263人,男性:906人,女性:357人\n", "333~367分人数:228人,男性:140人,女性:88人\n", "368~500分人数:54人,男性:30人,女性:24人\n", "ok\n" ] } ], "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "\n", "for k1, v1 in dict2.items():\n", " di = v1[0]\n", " gao = v1[1]\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if int(v['score']*100) in range(di,gao+1):\n", " dict1[k]['level'] = k1\n", " i+=1\n", " if v['sex'] == '男':\n", " m = m +1\n", " else:\n", " f = f+1\n", " print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n", "filename = 'data/daoban_燕山石化.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "8ad58c29-eb07-48d9-8d62-c5af158c02bf", "metadata": {}, "source": [ "### 倒班人员年龄段成绩" ] }, { "cell_type": "code", "execution_count": 121, "id": "43d4e63d-a615-4ac0-b075-c938dc346e98", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:09:44.193852Z", "iopub.status.busy": "2023-05-27T13:09:44.192991Z", "iopub.status.idle": "2023-05-27T13:09:44.545582Z", "shell.execute_reply": "2023-05-27T13:09:44.544856Z", "shell.execute_reply.started": "2023-05-27T13:09:44.193810Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20~24岁平均成绩:2.31分,人数:184人\n", "25~29岁平均成绩:2.41分,人数:96人\n", "30~34岁平均成绩:2.33分,人数:99人\n", "35~39岁平均成绩:2.36分,人数:113人\n", "40~44岁平均成绩:2.35分,人数:527人\n", "45~49岁平均成绩:2.32分,人数:616人\n", "50~54岁平均成绩:2.35分,人数:739人\n", "55~80岁平均成绩:2.32分,人数:377人\n" ] } ], "source": [ "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " i = 1\n", " score = 0\n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1) and v['sex'] == '男':\n", " score = score+v['score']\n", " i+=1\n", " \n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')" ] }, { "cell_type": "code", "execution_count": 122, "id": "69d07666-1a7d-42a0-85df-e88f956b9444", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:09:52.831237Z", "iopub.status.busy": "2023-05-27T13:09:52.830821Z", "iopub.status.idle": "2023-05-27T13:09:52.930980Z", "shell.execute_reply": "2023-05-27T13:09:52.930197Z", "shell.execute_reply.started": "2023-05-27T13:09:52.831209Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20~24岁平均成绩:2.57分,人数:69人\n", "25~29岁平均成绩:2.67分,人数:32人\n", "30~34岁平均成绩:2.73分,人数:18人\n", "35~39岁平均成绩:2.62分,人数:43人\n", "40~44岁平均成绩:2.63分,人数:228人\n", "45~49岁平均成绩:2.7分,人数:295人\n", "50~54岁平均成绩:2.71分,人数:42人\n", "55~80岁平均成绩:0.0分,人数:0人\n" ] } ], "source": [ "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "for item in nld:\n", " di = item[0]\n", " gao = item[1]\n", " i = 1\n", " score = 0\n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if v['age'] in range(di,gao+1) and v['sex'] == '女':\n", " score = score+v['score']\n", " i+=1\n", " \n", " \n", " print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')" ] }, { "cell_type": "markdown", "id": "aca6bfe1-b0c3-41b5-a0be-a5c1af071cbf", "metadata": {}, "source": [ "## 倒班人员测试等级" ] }, { "cell_type": "code", "execution_count": 123, "id": "798112d0-63e6-4a4b-9959-dbadf3c4ed54", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:11:29.890108Z", "iopub.status.busy": "2023-05-27T13:11:29.889257Z", "iopub.status.idle": "2023-05-27T13:11:30.148770Z", "shell.execute_reply": "2023-05-27T13:11:30.148046Z", "shell.execute_reply.started": "2023-05-27T13:11:29.890066Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0~255分人数:1933人,男性:1675人,女性:258人\n", "256~332分人数:1263人,男性:906人,女性:357人\n", "333~367分人数:228人,男性:140人,女性:88人\n", "368~500分人数:54人,男性:30人,女性:24人\n", "ok\n" ] } ], "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "dict2 = {}\n", "dict2['不合格'] = [0,255]\n", "dict2['合格'] = [256,332]\n", "dict2['良好'] = [333,367]\n", "dict2['优秀'] = [368,500]\n", "\n", "for k1, v1 in dict2.items():\n", " di = v1[0]\n", " gao = v1[1]\n", " i = 0 \n", " m = 0\n", " f = 0\n", " for k,v in dict1.items():\n", " if int(v['score']*100) in range(di,gao+1):\n", " dict1[k]['level'] = k1\n", " i+=1\n", " if v['sex'] == '男':\n", " m = m +1\n", " else:\n", " f = f+1\n", " print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')\n", "#filename = 'data/result_石家庄.json'\n", "with open(filename,'w') as fl:\n", " json.dump(dict1, fl) \n", "print('ok')" ] }, { "cell_type": "markdown", "id": "5afed106-e77b-453b-bcdf-29c00665a4bd", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:57:01.082474Z", "iopub.status.busy": "2023-05-27T13:57:01.082047Z", "iopub.status.idle": "2023-05-27T13:57:01.086797Z", "shell.execute_reply": "2023-05-27T13:57:01.085545Z", "shell.execute_reply.started": "2023-05-27T13:57:01.082445Z" }, "tags": [] }, "source": [ "### 倒班人员平均成绩" ] }, { "cell_type": "code", "execution_count": 125, "id": "e9444e38-450c-4e70-a98e-aa312d83d9c4", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T13:58:22.704523Z", "iopub.status.busy": "2023-05-27T13:58:22.703677Z", "iopub.status.idle": "2023-05-27T13:58:22.796742Z", "shell.execute_reply": "2023-05-27T13:58:22.795740Z", "shell.execute_reply.started": "2023-05-27T13:58:22.704483Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "平均成绩:2.3453分,男性:2751人\n", "平均成绩:2.6869分,女性:727人\n", "平均成绩:2.4167分,总体:3478人\n" ] } ], "source": [ "nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\n", "#filename = 'data/result_石家庄.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "i = 1\n", "m = 0\n", "f = 0\n", "score = 0\n", "t_score = 0\n", "for k,v in dict1.items():\n", " if v['sex'] == '男':\n", " m = m +1\n", " score = score+v['score']\n", "print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')\n", "t_score = t_score + score\n", "score = 0\n", "for k,v in dict1.items():\n", " if v['sex'] == '女':\n", " f = f +1\n", " score = score+v['score']\n", "print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')\n", "t_score = t_score + score\n", "print(f'平均成绩:{round(t_score/(m+f),4)}分,总体:{m+f}人')" ] }, { "cell_type": "markdown", "id": "8e52fd0b-c4db-4b88-b88e-7edf37714b6e", "metadata": {}, "source": [ "### 计算倒班员工各项目成绩" ] }, { "cell_type": "code", "execution_count": 126, "id": "3248d9c5-bea2-492c-9a7a-ac2c9632b514", "metadata": { "execution": { "iopub.execute_input": "2023-05-27T14:58:29.579314Z", "iopub.status.busy": "2023-05-27T14:58:29.578870Z", "iopub.status.idle": "2023-05-27T14:58:29.689623Z", "shell.execute_reply": "2023-05-27T14:58:29.688913Z", "shell.execute_reply.started": "2023-05-27T14:58:29.579287Z" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "体重 3.29 3478\n", "肺活量 2.8 3438\n", "握力 2.34 3449\n", "坐位体前屈 2.74 2993\n", "纵跳 1.7 3288\n", "俯卧撑 1.94 2198\n", "一分钟仰卧起坐 3.65 535\n", "单脚站立 1.44 3390\n", "选择反应时 2.65 3418\n", "台阶指数 2.82 2179\n" ] } ], "source": [ "with open(filename,'r') as fl:\n", " dict1 = json.load(fl) \n", "items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n", "for item in items:\n", " score = 0\n", " n = 0\n", " for k, v in dict1.items():\n", " if item in v.keys():\n", " n = n + 1\n", " score =score + int(v[item]['得分'])\n", " print(item,round(score/n,2),n)" ] }, { "cell_type": "code", "execution_count": null, "id": "12f5e54e-635d-450f-8a4f-54de18f3519d", "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 }