Files
jupyter/体测单位/中安联合.ipynb
T
2024-05-29 23:48:44 +08:00

329 lines
9.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "82e8dee5-178d-49bd-9849-ba652b0cabaa",
"metadata": {},
"source": [
"## 人员基本信息导入"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "ed6c774c-e91d-4f99-9a38-318fade9e937",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-29T11:14:24.452076Z",
"iopub.status.busy": "2024-05-29T11:14:24.451311Z",
"iopub.status.idle": "2024-05-29T11:14:24.587987Z",
"shell.execute_reply": "2024-05-29T11:14:24.587402Z",
"shell.execute_reply.started": "2024-05-29T11:14:24.452004Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/中安联合体测花名册.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = int(sheet.cell(n, 4).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 6).value \n",
" xb = str(sheet.cell(n, 7).value)\n",
" if xb == '1':\n",
" sex = '男'\n",
" elif xb =='2':\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" dict1['unit'] = sheet.cell(n, 3).value\n",
" dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]\n",
" person[code] = dict1\n",
"filename = 'data/中安联合.json'\n",
"with open(filename, 'w') as fl:\n",
" json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "bafee365-2412-4287-a5d4-46209783953c",
"metadata": {},
"source": [
"## 人员编号校验"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "c9430854-6f56-4854-bc6b-d22f812f6715",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-29T11:14:29.628238Z",
"iopub.status.busy": "2024-05-29T11:14:29.627485Z",
"iopub.status.idle": "2024-05-29T11:14:29.764131Z",
"shell.execute_reply": "2024-05-29T11:14:29.763573Z",
"shell.execute_reply.started": "2024-05-29T11:14:29.628152Z"
}
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/中安联合体测花名册.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"list1 = []\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = int(sheet.cell(n, 4).value)\n",
" if code in list1:\n",
" print(code,sheet.cell(n, 3).value,sheet.cell(n, 6).value)\n",
" else:\n",
" list1.append(code)\n"
]
},
{
"cell_type": "markdown",
"id": "09a32766-daa8-4f1a-ad23-89b3e39e8d5f",
"metadata": {},
"source": [
"## 人员出生日期校验"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "dbc5af3a-1a2a-4094-ac89-f8efded12245",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-26T09:11:07.788399Z",
"iopub.status.busy": "2024-05-26T09:11:07.787797Z",
"iopub.status.idle": "2024-05-26T09:11:08.056837Z",
"shell.execute_reply": "2024-05-26T09:11:08.056306Z",
"shell.execute_reply.started": "2024-05-26T09:11:07.788344Z"
}
},
"outputs": [],
"source": [
"import re\n",
"from datetime import datetime\n",
"import openpyxl\n",
"import json\n",
"\n",
"wb = openpyxl.load_workbook('data/中安联合体测花名册.xlsx')\n",
"sheet = wb.active\n",
"\n",
"def validate_date(date_str):\n",
" try:\n",
" datetime.strptime(date_str, '%Y-%m-%d')\n",
" return True # valid date\n",
" except ValueError:\n",
" return False # invalid date\n",
"\n",
"\n",
"\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,2).value is None:\n",
" break\n",
" else: \n",
" code = str(sheet.cell(n,4).value)\n",
" rq = str(sheet.cell(n,8).value).split(' ')[0]\n",
" is_valid = validate_date(rq.replace('/','-'))\n",
" if not is_valid:\n",
" print(code,f\"Date '{rq}' 'is valid' \")\n",
" \n"
]
},
{
"cell_type": "markdown",
"id": "15444cd7-fe84-4adb-93bd-104d364a83c5",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "1efe2b78-dd18-4d12-8bc9-058f6f0046c9",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-29T11:14:46.382358Z",
"iopub.status.busy": "2024-05-29T11:14:46.381593Z",
"iopub.status.idle": "2024-05-29T11:14:46.412338Z",
"shell.execute_reply": "2024-05-29T11:14:46.411811Z",
"shell.execute_reply.started": "2024-05-29T11:14:46.382294Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"237\n",
"237\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"filename = 'data/中安联合.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20240529.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_中安联合.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": "2a28206b-f9b2-43f9-8afa-6a99fd19b39c",
"metadata": {},
"source": [
"## 导出测试人员信息"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "dd6379bf-6a79-48de-b3fb-35e84f192ce2",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-29T11:14:55.494999Z",
"iopub.status.busy": "2024-05-29T11:14:55.494275Z",
"iopub.status.idle": "2024-05-29T11:14:55.722705Z",
"shell.execute_reply": "2024-05-29T11:14:55.722177Z",
"shell.execute_reply.started": "2024-05-29T11:14:55.494935Z"
}
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"filename = 'data/result_中安联合.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/中安联合.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
" \n",
"list1 = []\n",
"for k, v in dict1.items():\n",
" if k in dict2.keys():\n",
" list2 = []\n",
" list2.append(str(k).rjust(5,'0'))\n",
" list2.append(v['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit'])\n",
" for item in items:\n",
" if item in v.keys():\n",
" list2.append(v[item]['成绩']) \n",
" elif item =='name':\n",
" list2.append(v[item])\n",
" else:\n",
" list2.append('') \n",
" list1.append(list2)\n",
"filename = 'data/中安联合20240529.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet.append(title)\n",
"for row in list1:\n",
" sheet.append(row)\n",
" \n",
"wb.save(filename)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7cb7cde8-0d5a-4b46-a304-10ebd54ea491",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}