376 lines
11 KiB
Plaintext
376 lines
11 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "82e8dee5-178d-49bd-9849-ba652b0cabaa",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 人员基本信息导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "ed6c774c-e91d-4f99-9a38-318fade9e937",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-01T08:38:50.009649Z",
|
|
"iopub.status.busy": "2024-06-01T08:38:50.009121Z",
|
|
"iopub.status.idle": "2024-06-01T08:38:50.151368Z",
|
|
"shell.execute_reply": "2024-06-01T08:38:50.150654Z",
|
|
"shell.execute_reply.started": "2024-06-01T08:38:50.009599Z"
|
|
}
|
|
},
|
|
"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": 44,
|
|
"id": "c9430854-6f56-4854-bc6b-d22f812f6715",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-05-31T12:41:21.160561Z",
|
|
"iopub.status.busy": "2024-05-31T12:41:21.159834Z",
|
|
"iopub.status.idle": "2024-05-31T12:41:21.433867Z",
|
|
"shell.execute_reply": "2024-05-31T12:41:21.433333Z",
|
|
"shell.execute_reply.started": "2024-05-31T12:41:21.160496Z"
|
|
}
|
|
},
|
|
"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": 8,
|
|
"id": "1efe2b78-dd18-4d12-8bc9-058f6f0046c9",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-01T08:40:42.686238Z",
|
|
"iopub.status.busy": "2024-06-01T08:40:42.685496Z",
|
|
"iopub.status.idle": "2024-06-01T08:40:42.743042Z",
|
|
"shell.execute_reply": "2024-06-01T08:40:42.742507Z",
|
|
"shell.execute_reply.started": "2024-06-01T08:40:42.686153Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"709\n",
|
|
"709\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_20240601.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": 9,
|
|
"id": "dd6379bf-6a79-48de-b3fb-35e84f192ce2",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-01T08:41:07.934988Z",
|
|
"iopub.status.busy": "2024-06-01T08:41:07.934276Z",
|
|
"iopub.status.idle": "2024-06-01T08:41:08.095312Z",
|
|
"shell.execute_reply": "2024-06-01T08:41:08.094771Z",
|
|
"shell.execute_reply.started": "2024-06-01T08:41:07.934919Z"
|
|
}
|
|
},
|
|
"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/中安联合20240601.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": "8fa66e4e-c3b7-4c5a-a0ad-90e8b36f195e",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 统计未测试人员名单"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "314f9709-4c13-4f8b-bca6-fc2122a9054e",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2024-06-02T01:04:12.743929Z",
|
|
"iopub.status.busy": "2024-06-02T01:04:12.742863Z",
|
|
"iopub.status.idle": "2024-06-02T01:04:12.793583Z",
|
|
"shell.execute_reply": "2024-06-02T01:04:12.792951Z",
|
|
"shell.execute_reply.started": "2024-06-02T01:04:12.743871Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import openpyxl\n",
|
|
"\n",
|
|
"filename = 'data/result_中安联合.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"filename = 'data/中安联合.json'\n",
|
|
"list1 = []\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
"for k,v in dict2.items():\n",
|
|
" if k not in dict1.keys():\n",
|
|
" list2 = []\n",
|
|
" list2 =[k,v['name'],v['sex'],v['unit'],v['birth']]\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",
|
|
"wb.save(filename) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "53e0e519-4b61-42c7-9a75-dad453c0ff64",
|
|
"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
|
|
}
|