1671 lines
50 KiB
Plaintext
1671 lines
50 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4626da6c-d228-4270-8d8d-c98784a106ad",
|
|
"metadata": {
|
|
"jp-MarkdownHeadingCollapsed": true,
|
|
"tags": [],
|
|
"toc-hr-collapsed": true
|
|
},
|
|
"source": [
|
|
"# 第一次体测"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ba2deee7-9c63-4115-bcee-ad341175fc02",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 人员信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "dea5e486-6927-469f-aa57-e5efac4670be",
|
|
"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, 2).value)\n",
|
|
" person.setdefault(code, {})\n",
|
|
" dict1 = {}\n",
|
|
" dict1['name'] = sheet.cell(n, 3).value\n",
|
|
" if sheet.cell(n, 4).value ==1:\n",
|
|
" sex = '男'\n",
|
|
" else:\n",
|
|
" sex = '女'\n",
|
|
" dict1['sex'] = sex\n",
|
|
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
|
|
" dict1['birth'] = birth\n",
|
|
" dict1['unit'] = sheet.cell(n, 1).value\n",
|
|
" if sheet.cell(n,10).value is not None:\n",
|
|
" dict1['phone'] = sheet.cell(n, 10).value \n",
|
|
" person[code] = dict1\n",
|
|
"\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": "1c00e1e4-101a-4e9f-a7ed-9c65200d19df",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 成绩导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "fd73b8be-d3fe-49aa-99d2-3cc6df4a3eb0",
|
|
"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/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20230918.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",
|
|
" re_ta[user][item_name]['得分'] = result[5]\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": "928790e6-d8a4-4b2b-852a-3c323380a80f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 成绩导出"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b870bd6e-f972-4073-b13d-5fda8cc92bb7",
|
|
"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/北京农行人员名单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",
|
|
" 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",
|
|
" list2.append(v[item]['得分']) \n",
|
|
" elif item =='name':\n",
|
|
" list2.append(v[item])\n",
|
|
" else:\n",
|
|
" list2.append('') \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": "dd2034ca-fe8b-4322-b06d-8c5eaf96373d",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 报告按部门分类更名"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "04967ec6-b9a0-4097-9e1f-8beaf8a9e75f",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import math\n",
|
|
"import glob\n",
|
|
"from pathlib import Path\n",
|
|
"\n",
|
|
"fi_path = 'file/2023-05-23'\n",
|
|
"old = []\n",
|
|
"dict2 = {}\n",
|
|
"\n",
|
|
"filename = 'data/result_北京农行.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"for k, v in dict1.items():\n",
|
|
" m_name = v['name']\n",
|
|
" m_depart = v['unit'] \n",
|
|
" dict2[int(k)] = [m_name,m_depart]\n",
|
|
"\n",
|
|
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
|
"\n",
|
|
"for fn in fls:\n",
|
|
" old.append(os.path.basename(fn).split('.')[0])\n",
|
|
"\n",
|
|
"for n in old: \n",
|
|
" o_name = f'{fi_path}/{n}.pdf'\n",
|
|
" new_path = Path(fi_path,'new',dict1[n]['unit'])\n",
|
|
" new_path.mkdir(parents = True, exist_ok = True)\n",
|
|
" n_name = Path(new_path,f'{str(n).rjust(5,\"0\")}-{dict2[int(n)][0]}.pdf')\n",
|
|
" if not os.path.exists(n_name):\n",
|
|
" shutil.copyfile(o_name,n_name)\n",
|
|
" print(n_name)\n",
|
|
" \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "515bc854-5745-4c38-8633-f56a078ea9a8",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-05-25T09:28:28.615647Z",
|
|
"iopub.status.busy": "2023-05-25T09:28:28.614774Z",
|
|
"iopub.status.idle": "2023-05-25T09:28:28.619865Z",
|
|
"shell.execute_reply": "2023-05-25T09:28:28.618821Z",
|
|
"shell.execute_reply.started": "2023-05-25T09:28:28.615607Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"## 生成人员电话信息表"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c925d850-ff06-4be5-bf9f-31f4385c37c0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"wb = openpyxl.load_workbook('data/农业银行测试手机号码统计表.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"dict1 = {}\n",
|
|
"\n",
|
|
"for n in range(2, sheet.max_row+1):\n",
|
|
" if sheet.cell(n,5).value is not None:\n",
|
|
" phone = str(sheet.cell(n, 5).value)\n",
|
|
" dict1.setdefault(phone,{})\n",
|
|
" code = str(sheet.cell(n, 2).value)\n",
|
|
" unit = sheet.cell(n, 1).value\n",
|
|
" name = sheet.cell(n, 3).value\n",
|
|
" sex = sheet.cell(n, 4).value\n",
|
|
" dict1[phone]['code'] = code\n",
|
|
" dict1[phone]['name'] = name\n",
|
|
" #dict1[phone]['unit'] = unit\n",
|
|
" #dict1[phone]['sex'] = sex\n",
|
|
"filename = 'data/农业银行测试手机号码.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0f13e837-15d9-4dc6-b356-78b79bbb5b17",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成验证码"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a87384c6-dc46-4d09-b757-b42462ed818d",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import random\n",
|
|
"import json\n",
|
|
"\n",
|
|
"code_list = []\n",
|
|
"for i in range(10): # 0~9\n",
|
|
" code_list.append(str(i))\n",
|
|
" \n",
|
|
"list1 = []\n",
|
|
"#print(code_num)\n",
|
|
"i = 1\n",
|
|
"while i < 165:\n",
|
|
" code = random.sample(code_list,6) #随机取6位数\n",
|
|
" code_num = ''.join(code)\n",
|
|
" if code_num not in list1:\n",
|
|
" list1.append(code_num)\n",
|
|
" i +=1\n",
|
|
"print(len(list1))\n",
|
|
"print(list1)\n",
|
|
"i = 0\n",
|
|
"filename = 'data/农业银行测试手机号码.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict1[k]['yzm'] = list1[i]\n",
|
|
" i +=1\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6efc1c2b-7af1-49ec-9b48-8930a8dd2801",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成下载链接"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "10845b90-48b4-4418-9dac-dd4a6f0147c0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"filename = 'data/农业银行测试手机号码.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"dict2 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict2.setdefault(v['yzm'],{})\n",
|
|
" dict2[v['yzm']]['code'] = v['code']\n",
|
|
" dict2[v['yzm']]['name'] = v['name']\n",
|
|
"print(len(dict2))\n",
|
|
"filename = 'data/yzm.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict2, fl, ensure_ascii=False) \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fba0a0c4-edf2-45c2-9199-c6a86919f191",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 发送短信"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "62733f52-62c1-43aa-964a-232eab8b5251",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendSmsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.SignName = \"坤铭教育\"\n",
|
|
" req.TemplateId = \"1875765\" \n",
|
|
" req.TemplateParamSet = [\"北京石油分公司体测者\",\"01740518\"]\n",
|
|
" req.PhoneNumberSet = [\"+8613793180751\"]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" resp = client.SendSms(req)\n",
|
|
" print(resp.to_json_string(indent=2))\n",
|
|
"except TencentCloudSDKException as err:\n",
|
|
" print(err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e924a0a9-65a5-49c4-bdf2-b9152d278ad5",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"dict1 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"print(dict1['SendStatusSet'][0][\"Message\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c55a8af0-4e4d-4bd4-b5b1-0a7d9170958c",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 批量发送短信(测试)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "910d1881-d090-48dc-ac87-685ccaaf9553",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"from tencentcloud.common import credential\n",
|
|
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
|
|
"from tencentcloud.sms.v20210111 import sms_client, models\n",
|
|
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
|
|
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/短信测试手机号码.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" phone = '+86'+str(k)\n",
|
|
" yzm = v['yzm']\n",
|
|
" try: \n",
|
|
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
|
|
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
|
|
" cred = credential.Credential(secretId, secretKey) \n",
|
|
" httpProfile = HttpProfile()\n",
|
|
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
|
|
" httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n",
|
|
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
|
|
" clientProfile = ClientProfile()\n",
|
|
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
|
|
" clientProfile.language = \"en-US\"\n",
|
|
" clientProfile.httpProfile = httpProfile\n",
|
|
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
|
|
" req = models.SendSmsRequest()\n",
|
|
" req.SmsSdkAppId = \"1400140089\"\n",
|
|
" req.SignName = \"坤铭教育\"\n",
|
|
" req.TemplateId = \"1808914\" \n",
|
|
" req.TemplateParamSet = [yzm]\n",
|
|
" req.PhoneNumberSet = [phone]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" #resp = client.SendSms(req)\n",
|
|
" dict2 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
" print(v['name'],dict2['SendStatusSet'][0][\"Message\"])\n",
|
|
" except TencentCloudSDKException as err:\n",
|
|
" print(v['name'],err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "59d38404-e097-4f08-a3fd-565e351f09bb",
|
|
"metadata": {
|
|
"jp-MarkdownHeadingCollapsed": true,
|
|
"tags": [],
|
|
"toc-hr-collapsed": true
|
|
},
|
|
"source": [
|
|
"# 第二次体测"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "deeb7606-5752-4337-9117-4ba9edc762e9",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 人员信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d803a2b2-4a61-42ba-84a3-e9846e3e9f5c",
|
|
"metadata": {},
|
|
"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, 3).value\n",
|
|
" if sheet.cell(n, 4).value ==1:\n",
|
|
" sex = '男'\n",
|
|
" else:\n",
|
|
" sex = '女'\n",
|
|
" dict1['sex'] = sex\n",
|
|
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
|
|
" dict1['birth'] = birth\n",
|
|
" dict1['unit'] = sheet.cell(n, 2).value\n",
|
|
" if sheet.cell(n,6).value is not None:\n",
|
|
" dict1['phone'] = sheet.cell(n, 6).value \n",
|
|
" person[code] = dict1\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单2308.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(person, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ff97823f-fd67-45ae-bd78-f209317be6b9",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 成绩导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4adf86dd-addf-490a-9954-5dcac4693868",
|
|
"metadata": {},
|
|
"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/北京农行人员名单2308.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20230825.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_北京农行0825.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": null,
|
|
"id": "bb01b9a9-418d-4a1b-8ea9-1215af0b8285",
|
|
"metadata": {},
|
|
"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/北京农行人员名单2308.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"filename = 'data/places_result_20230825.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_北京农行0825.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": "4d2a0d63-4124-4063-96a7-a02478b9eabe",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 查看项目不足人员"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b26857af-5fa3-42d0-bf79-bc33d9f5e4a8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"filename = 'data/result_北京农行0825.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"i= 0\n",
|
|
"for k, v in dict1.items():\n",
|
|
" if len(v.keys())< 8:\n",
|
|
" print(k,v['name'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "1966307c-4161-4c5b-b19a-b8a143972223",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 导出测试人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "288e39fb-b7e3-4566-ac13-ba98d7e72edb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/result_北京农行0825.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"list1 =[]\n",
|
|
"for k, v in dict1.items():\n",
|
|
" list2 = []\n",
|
|
" list2 = [k,v['name'],v['sex'],v['unit']]\n",
|
|
" list1.append(list2)\n",
|
|
"filename = 'data/北京农行测试人员202308.xlsx'\n",
|
|
"wb = openpyxl.Workbook()\n",
|
|
"sheet = wb.active\n",
|
|
"\n",
|
|
"for row in list1:\n",
|
|
" sheet.append(row)\n",
|
|
" \n",
|
|
"wb.save(filename)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "a42cb587-8673-4655-8943-3cbd63f22b73",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 检查性别"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6352b95c-0e19-4943-9e99-218138213060",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/result_北京农行0825.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" if v['sex'] == '男' and '一分钟仰卧起坐' in v.keys():\n",
|
|
" print(k,'应为女性!')\n",
|
|
" if v['sex'] == '女' and '俯卧撑' in v.keys():\n",
|
|
" print(k,'应为男性!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fddd68cd-b20c-4cf9-b503-5d59f52e3c1b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 手工数据生成SQL"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "372294de-5370-41c0-9883-b18de9d8ef7e",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"wb = openpyxl.load_workbook('data/北京农行测试人员202308.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"dict1 = {}\n",
|
|
"\n",
|
|
"data1 =list(sheet.values)\n",
|
|
"del data1[0]\n",
|
|
"list1 = []\n",
|
|
"for item in data1:\n",
|
|
" code = int(item[0])\n",
|
|
" list1.append((309118,code,5,item[4],'2023-08-23','2023-08-23 22:00:00'))\n",
|
|
"print(list1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c32bdb5c-d987-4b0f-98e3-9ce4e3ef3671",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 核对问卷人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c1b187e0-f566-43fa-88d8-090deb9ead19",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单2308.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
" \n",
|
|
"filename = 'data/Survey_20230913.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",
|
|
" code = str(line[4])\n",
|
|
" name = line[3]\n",
|
|
" \n",
|
|
" if code not in dict1.keys() or name!= dict1[code]['name']:\n",
|
|
" print(code,name)\n",
|
|
" \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "39cd284f-99fe-4ba0-928c-9da01042e394",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 合并人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7ef51041-ad78-4c6a-af83-ed3e0473b199",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单2308.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",
|
|
"for k, v in dict2.items():\n",
|
|
" dict1[k] = v\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(re_ta))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3877fc60-171c-434a-aa27-8f1fe9936dd2",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 报告按部门分类"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "80a85fcd-0597-4b58-898f-de420239919f",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import glob\n",
|
|
"from pathlib import Path\n",
|
|
"\n",
|
|
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'\n",
|
|
"new_path = 'file/309118'\n",
|
|
"old = []\n",
|
|
"dict2 = {}\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
|
"for fn in fls:\n",
|
|
" fi_name =Path(fn).stem.split('-')[0]\n",
|
|
" code = int(fi_name)\n",
|
|
" unit_path = Path(new_path,dict1[str(code)]['unit'])\n",
|
|
" unit_path.mkdir(parents = True, exist_ok = True)\n",
|
|
" n_name = Path(unit_path,Path(fn).stem+'.pdf')\n",
|
|
" if not os.path.exists(n_name):\n",
|
|
" shutil.copyfile(fn,n_name)\n",
|
|
" print(n_name)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3022dcdd-8700-468f-86ab-6ce43b118e1c",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成体测报告打印明细表"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "24433f75-6397-4b12-870e-611b77db8ded",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import glob\n",
|
|
"from pathlib import Path\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'\n",
|
|
"new_path = 'file/309118'\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
|
|
"for fn in fls:\n",
|
|
" list2 = []\n",
|
|
" fi_name =Path(fn).stem.split('-')[0] \n",
|
|
" code = int(fi_name)\n",
|
|
" unit = dict1[str(code)]['unit']\n",
|
|
" list2 = [fi_name,Path(fn).stem.split('-')[1],unit]\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) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d71a24d1-ab29-4852-9bfc-384deb8f57a5",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 数据分析"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d70ab6c9-4fb7-4f0d-864d-96e0ce05fb64",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 获取清理后数据"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ac3b256e-7470-4cfa-b2ee-eb1110c9097c",
|
|
"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/北京农行人员名单all.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_20230922-1695356859947.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",
|
|
" \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",
|
|
"\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_北京农行all.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(re_ta, fl, ensure_ascii=False) \n",
|
|
"print('ok')\n",
|
|
"print(len(re_ta))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "43c0dad1-9b96-4480-ae3d-d7fb4a2a8df5",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算人员年龄"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 49,
|
|
"id": "567f512c-2f8a-4441-99c1-f091b40dfd3b",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:11:03.405894Z",
|
|
"iopub.status.busy": "2023-09-23T09:11:03.405430Z",
|
|
"iopub.status.idle": "2023-09-23T09:11:03.475250Z",
|
|
"shell.execute_reply": "2023-09-23T09:11:03.474127Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:11:03.405856Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"ok\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import datetime\n",
|
|
"\n",
|
|
"filename = 'data/result_北京农行all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" #print(k,v)\n",
|
|
" if '.' in v['birth']:\n",
|
|
" birth = v['birth'].split()[0].split('.')\n",
|
|
" else:\n",
|
|
" birth = v['birth'].split()[0].split('/')\n",
|
|
" \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",
|
|
" if int(k) < 199:\n",
|
|
" days = (datetime.date(2023, 5, 11)-datetime.date(nian,yue,ri)).days\n",
|
|
" else:\n",
|
|
" days = (datetime.date(2023, 8, 24)-datetime.date(nian,yue,ri)).days\n",
|
|
" v['age'] = int(days/365)\n",
|
|
"filename = 'data/result_北京农行all.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print('ok') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7b2974f0-8b5e-40b9-a872-b0df27097096",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 汇总人员信息及成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "576f9b57-237f-4376-b795-122a4cd2222a",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"\n",
|
|
"items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
|
|
"\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k,v in dict1.items():\n",
|
|
" print(k)\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",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0fd37ce2-f965-4a46-8207-c5ce9a7b426a",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算测试等级"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"id": "ec2773cb-16ff-4957-aa51-627bfe0caf95",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T08:20:11.144070Z",
|
|
"iopub.status.busy": "2023-09-23T08:20:11.143557Z",
|
|
"iopub.status.idle": "2023-09-23T08:20:11.211460Z",
|
|
"shell.execute_reply": "2023-09-23T08:20:11.210353Z",
|
|
"shell.execute_reply.started": "2023-09-23T08:20:11.144030Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0~255分人数:107人,男性:60人,女性:47人\n",
|
|
"256~332分人数:229人,男性:83人,女性:146人\n",
|
|
"333~367分人数:128人,男性:35人,女性:93人\n",
|
|
"368~500分人数:58人,男性:16人,女性:42人\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",
|
|
"\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl) \n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "058f29fc-6de5-42b6-ba07-95d39e014418",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 根据年龄汇总人员信息及成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"id": "c605482a-3aa5-46ff-8648-2675408470a8",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:11:19.016454Z",
|
|
"iopub.status.busy": "2023-09-23T09:11:19.015975Z",
|
|
"iopub.status.idle": "2023-09-23T09:11:19.033986Z",
|
|
"shell.execute_reply": "2023-09-23T09:11:19.033423Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:11:19.016418Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20~24岁平均成绩:2.74分,人数:40人,男性:16人\n",
|
|
"25~29岁平均成绩:2.98分,人数:102人,男性:48人\n",
|
|
"30~34岁平均成绩:2.98分,人数:107人,男性:38人\n",
|
|
"35~39岁平均成绩:3.1分,人数:95人,男性:27人\n",
|
|
"40~44岁平均成绩:3.19分,人数:37人,男性:14人\n",
|
|
"45~49岁平均成绩:3.13分,人数:66人,男性:23人\n",
|
|
"50~54岁平均成绩:3.07分,人数:60人,男性:13人\n",
|
|
"55~69岁平均成绩:2.85分,人数:15人,男性:15人\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]\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 = 0\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}人,男性:{m}人')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "8a15ed82-93bb-4e25-a59e-2358c4d47ca5",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 根据年龄汇总人员信息及成绩(男)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 51,
|
|
"id": "a75f1748-444a-4b0f-a38c-79d814a16ae0",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:11:22.695232Z",
|
|
"iopub.status.busy": "2023-09-23T09:11:22.694925Z",
|
|
"iopub.status.idle": "2023-09-23T09:11:22.717627Z",
|
|
"shell.execute_reply": "2023-09-23T09:11:22.716976Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:11:22.695205Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20~24岁平均成绩:2.75分,人数:16人\n",
|
|
"25~29岁平均成绩:2.85分,人数:48人\n",
|
|
"30~34岁平均成绩:2.81分,人数:38人\n",
|
|
"35~39岁平均成绩:3.01分,人数:27人\n",
|
|
"40~44岁平均成绩:2.99分,人数:14人\n",
|
|
"45~49岁平均成绩:2.88分,人数:23人\n",
|
|
"50~54岁平均成绩:2.87分,人数:13人\n",
|
|
"55~80岁平均成绩:2.85分,人数:15人\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"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 = 0\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",
|
|
" if i >0:\n",
|
|
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')\n",
|
|
" else:\n",
|
|
" print(f'{di}~{gao}岁平均成绩:0分,人数:0人') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "9840c5a8-2a06-4d7b-91f5-d3c2d43d1d02",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 根据年龄汇总人员信息及成绩(女)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 52,
|
|
"id": "d735d1e2-02d3-4768-a5eb-22792791ca23",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:11:26.628891Z",
|
|
"iopub.status.busy": "2023-09-23T09:11:26.628391Z",
|
|
"iopub.status.idle": "2023-09-23T09:11:26.652254Z",
|
|
"shell.execute_reply": "2023-09-23T09:11:26.651303Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:11:26.628854Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20~24岁平均成绩:2.73分,人数:24人\n",
|
|
"25~29岁平均成绩:3.1分,人数:54人\n",
|
|
"30~34岁平均成绩:3.07分,人数:69人\n",
|
|
"35~39岁平均成绩:3.14分,人数:68人\n",
|
|
"40~44岁平均成绩:3.31分,人数:23人\n",
|
|
"45~49岁平均成绩:3.27分,人数:43人\n",
|
|
"50~54岁平均成绩:3.13分,人数:47人\n",
|
|
"55~80岁平均成绩:0分,人数:0人\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]\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 = 0\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",
|
|
" if i >0:\n",
|
|
" print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')\n",
|
|
" else:\n",
|
|
" print(f'{di}~{gao}岁平均成绩:0分,人数:0人') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f4a02b1d-2468-4430-8f55-3ffaf07efd34",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算平均成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"id": "fc897a81-7727-4f37-8ab3-8e9de72855d6",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T08:23:38.968301Z",
|
|
"iopub.status.busy": "2023-09-23T08:23:38.968098Z",
|
|
"iopub.status.idle": "2023-09-23T08:23:38.980306Z",
|
|
"shell.execute_reply": "2023-09-23T08:23:38.979851Z",
|
|
"shell.execute_reply.started": "2023-09-23T08:23:38.968286Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"平均成绩:2.8683分,男性:194人\n",
|
|
"平均成绩:3.1148分,女性:328人\n",
|
|
"平均成绩:3.0232分,总体:522人\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/522,4)}分,总体:522人')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f4911bde-1a29-4fdf-a7f7-4ebef0905936",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算各年龄段测试等级(女)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 53,
|
|
"id": "43c8fd61-4bdb-4d8e-8061-f4f186bd1845",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:11:32.394933Z",
|
|
"iopub.status.busy": "2023-09-23T09:11:32.394468Z",
|
|
"iopub.status.idle": "2023-09-23T09:11:32.420499Z",
|
|
"shell.execute_reply": "2023-09-23T09:11:32.419180Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:11:32.394896Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20-24 {'良好': 1, '合格': 15, '不合格': 7, '优秀': 1}\n",
|
|
"25-29 {'合格': 25, '良好': 19, '不合格': 7, '优秀': 3}\n",
|
|
"30-34 {'合格': 31, '不合格': 11, '优秀': 8, '良好': 19}\n",
|
|
"35-39 {'合格': 31, '不合格': 10, '良好': 15, '优秀': 12}\n",
|
|
"40-44 {'良好': 10, '合格': 7, '优秀': 4, '不合格': 2}\n",
|
|
"45-49 {'优秀': 6, '合格': 18, '良好': 16, '不合格': 3}\n",
|
|
"50-54 {'不合格': 7, '合格': 19, '优秀': 8, '良好': 13}\n",
|
|
"55-80 {'良好': 0, '合格': 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",
|
|
"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": "6b5d0882-6c64-4e39-813b-a4c3ebb98006",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算各年龄段测试等级(男)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"id": "aefe62b7-8fcf-43e0-a525-a8584b064167",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T09:20:16.478192Z",
|
|
"iopub.status.busy": "2023-09-23T09:20:16.477735Z",
|
|
"iopub.status.idle": "2023-09-23T09:20:16.503089Z",
|
|
"shell.execute_reply": "2023-09-23T09:20:16.501855Z",
|
|
"shell.execute_reply.started": "2023-09-23T09:20:16.478154Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"20-24 {'良好': 3, '合格': 7, '不合格': 6, '优秀': 0}\n",
|
|
"25-29 {'合格': 22, '良好': 8, '不合格': 15, '优秀': 3}\n",
|
|
"30-34 {'合格': 16, '不合格': 12, '优秀': 3, '良好': 7}\n",
|
|
"35-39 {'合格': 12, '不合格': 7, '良好': 4, '优秀': 4}\n",
|
|
"40-44 {'良好': 3, '合格': 5, '优秀': 2, '不合格': 4}\n",
|
|
"45-49 {'优秀': 1, '合格': 10, '良好': 5, '不合格': 7}\n",
|
|
"50-54 {'不合格': 4, '合格': 5, '优秀': 2, '良好': 2}\n",
|
|
"55-80 {'良好': 3, '合格': 6, '不合格': 5, '优秀': 1}\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": "446217a9-4805-4627-a904-ca734e348433",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 计算各项目成绩"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 48,
|
|
"id": "23b7518c-7434-467d-8d38-642f78bde7d9",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-23T08:25:08.604892Z",
|
|
"iopub.status.busy": "2023-09-23T08:25:08.604367Z",
|
|
"iopub.status.idle": "2023-09-23T08:25:08.629527Z",
|
|
"shell.execute_reply": "2023-09-23T08:25:08.628314Z",
|
|
"shell.execute_reply.started": "2023-09-23T08:25:08.604852Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"体重 3.8 517\n",
|
|
"肺活量 3.73 518\n",
|
|
"握力 1.88 519\n",
|
|
"坐位体前屈 2.93 503\n",
|
|
"纵跳 2.54 505\n",
|
|
"俯卧撑 3.64 184\n",
|
|
"一分钟仰卧起坐 4.29 303\n",
|
|
"单脚站立 2.57 514\n",
|
|
"选择反应时 3.19 488\n",
|
|
"台阶指数 2.57 486\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": "88b726b3-16db-4df5-af9d-24409934593f",
|
|
"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.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|