Files
jupyter/体测单位/东营石油工程设计院.ipynb
T
2023-03-24 19:39:11 +08:00

305 lines
9.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "28695364-38de-442e-818d-cfab45902763",
"metadata": {},
"source": [
"## 导入人员信息"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "2f2feca4-e0bf-4d68-af95-d3cfe5ac28bb",
"metadata": {
"execution": {
"iopub.execute_input": "2023-03-24T07:08:15.339494Z",
"iopub.status.busy": "2023-03-24T07:08:15.338898Z",
"iopub.status.idle": "2023-03-24T07:08:16.235510Z",
"shell.execute_reply": "2023-03-24T07:08:16.233968Z",
"shell.execute_reply.started": "2023-03-24T07:08:15.339445Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/student_20140922(东营工程设计院监测花名册2023年) .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, 4).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 6).value\n",
" if sheet.cell(n, 7).value ==1:\n",
" sex = '男'\n",
" else:\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" dict1['unit'] = sheet.cell(n, 3).value\n",
"\n",
"\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": "76caa442-de4f-41eb-8743-b4a9d6c749d0",
"metadata": {},
"source": [
"## 获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "ab77e97a-de62-44dc-874e-72e9c8aaecf2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-03-24T07:12:38.950011Z",
"iopub.status.busy": "2023-03-24T07:12:38.949468Z",
"iopub.status.idle": "2023-03-24T07:12:39.008067Z",
"shell.execute_reply": "2023-03-24T07:12:39.006932Z",
"shell.execute_reply.started": "2023-03-24T07:12:38.949964Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\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",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/141.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[4])\n",
" m_item = str(result[0]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = str(result[6])\n",
" re_ta[user]['unit'] = str(result[5]) \n",
" item_name = item[m_item]['name']\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[1])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" re_ta[user][item_name]['得分'] =result[2]\n",
"filename = 'data/result_东营石油工程设计院.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "c4107446-c0c6-4d76-9062-284ff806ec86",
"metadata": {},
"source": [
"## 导出测试成绩"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "ee6db59f-dcc3-4a85-8dba-2e212c2b5be0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-03-24T07:12:42.339250Z",
"iopub.status.busy": "2023-03-24T07:12:42.338673Z",
"iopub.status.idle": "2023-03-24T07:12:42.489449Z",
"shell.execute_reply": "2023-03-24T07:12:42.488377Z",
"shell.execute_reply.started": "2023-03-24T07:12:42.339201Z"
},
"tags": []
},
"outputs": [],
"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",
" \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",
" \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": "code",
"execution_count": 10,
"id": "579fd3c1-7fe3-49ef-8875-0d823b7d0546",
"metadata": {
"execution": {
"iopub.execute_input": "2023-03-23T14:30:43.407552Z",
"iopub.status.busy": "2023-03-23T14:30:43.406666Z",
"iopub.status.idle": "2023-03-23T14:30:43.479839Z",
"shell.execute_reply": "2023-03-23T14:30:43.478772Z",
"shell.execute_reply.started": "2023-03-23T14:30:43.407511Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"338\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\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",
"#SQL语句为:\n",
"#SELECT a.item_id,a.performance,a.score,a.date AS DATE1,a.avatar_id,b.unit,b.name,a.date_joined FROM places_result AS a,_tianjin AS b WHERE a.place_id=134 AND a.avatar_id=b.id\n",
"filename = 'data/东营工程设计院人员名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"\n",
"list1 = []\n",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/141.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",
"dict3 = {}\n",
"for result in list1:\n",
" user = result[2]\n",
" if user in dict2.keys():\n",
" dict3.setdefault(user,{}) \n",
" dict3[user]['name'] = dict2[user]['name']\n",
" dict3[user]['unit'] = dict2[user]['unit']\n",
"\n",
"print(len(dict3))\n",
"list1 = []\n",
"for k, v in dict3.items():\n",
" list2 = [k,v['name'],v['unit']]\n",
" list1.append(list2)\n",
"filename = 'data/东营工程设计院参加测试人员情况表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"\n",
"for row in list1:\n",
" sheet.append(row)\n",
" \n",
"wb.save(filename) \n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d3647aa-9f06-4a96-9d60-690d61b1a384",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}