20220806
This commit is contained in:
1 parent
268fd87e95
commit
f0667bdb25
3 files changed
+4509
-24
No files matched your search
+116
-6
@@ -889,6 +889,14 @@
|
|||||||
"## 获取人员测试成绩"
|
"## 获取人员测试成绩"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "8814b784-f561-455b-9125-b20672df2379",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### 读取数据库获取人员测试成绩"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@@ -945,6 +953,89 @@
|
|||||||
"print('ok')\n"
|
"print('ok')\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "9d517d8f-44ed-4672-8e31-e1673ffc9d1b",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### 读取csv文件获取人员测试成绩"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "93d73139-1734-49e5-a59a-15898af9b1d8",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2022-08-05T07:46:15.088786Z",
|
||||||
|
"iopub.status.busy": "2022-08-05T07:46:15.088219Z",
|
||||||
|
"iopub.status.idle": "2022-08-05T07:46:15.146141Z",
|
||||||
|
"shell.execute_reply": "2022-08-05T07:46:15.145040Z",
|
||||||
|
"shell.execute_reply.started": "2022-08-05T07:46:15.088739Z"
|
||||||
|
},
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"ok\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import pymysql\n",
|
||||||
|
"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",
|
||||||
|
"user_id = 5\n",
|
||||||
|
"place_id =130\n",
|
||||||
|
"#user = '包永'\n",
|
||||||
|
"\n",
|
||||||
|
"re_ta = {}\n",
|
||||||
|
"dict1 = {}\n",
|
||||||
|
"list1 = []\n",
|
||||||
|
"#print(\"\\n运动项目信息:\")\n",
|
||||||
|
"filename = 'data/130.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",
|
||||||
|
" item_name = item[m_item]['name']\n",
|
||||||
|
" re_ta[user].setdefault(item_name,{})\n",
|
||||||
|
" \n",
|
||||||
|
" #dict1.setdefault(item[m_item]['name'],{})\n",
|
||||||
|
" score = int(result[1])/item[m_item]['divisor']\n",
|
||||||
|
" #dict1[item[m_item]['name']]['成绩'] =f'{score} {item[m_item][\"unit\"]}'\n",
|
||||||
|
" #dict1[item[m_item]['name']]['得分'] =result[2]\n",
|
||||||
|
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
|
||||||
|
" re_ta[user][item_name]['得分'] =result[2]\n",
|
||||||
|
" \n",
|
||||||
|
" #re_ta[user] = dict1\n",
|
||||||
|
" #print(re_ta)\n",
|
||||||
|
"filename = 'data/result_130.json'\n",
|
||||||
|
"with open(filename,'w') as fl:\n",
|
||||||
|
" json.dump(re_ta, fl) \n",
|
||||||
|
"print('ok')\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "95df2637-7898-4446-bb8a-70d881bd9e44",
|
"id": "95df2637-7898-4446-bb8a-70d881bd9e44",
|
||||||
@@ -1007,17 +1098,36 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 7,
|
||||||
"id": "a7cf5e57-a381-4911-96ff-1e1469b6f9bc",
|
"id": "a7cf5e57-a381-4911-96ff-1e1469b6f9bc",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2022-08-05T07:49:14.416959Z",
|
||||||
|
"iopub.status.busy": "2022-08-05T07:49:14.416421Z",
|
||||||
|
"iopub.status.idle": "2022-08-05T07:49:14.474792Z",
|
||||||
|
"shell.execute_reply": "2022-08-05T07:49:14.473376Z",
|
||||||
|
"shell.execute_reply.started": "2022-08-05T07:49:14.416912Z"
|
||||||
|
},
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "KeyError",
|
||||||
|
"evalue": "'bm'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[0;32m<ipython-input-7-207983d31c51>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;31m#print(k,v)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0msheet\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34mf'A{n}'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 45\u001b[0;31m \u001b[0msheet\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34mf'B{n}'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'bm'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 46\u001b[0m \u001b[0msheet\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34mf'C{n}'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'身高'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;31mKeyError\u001b[0m: 'bm'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"import json\n",
|
"import json\n",
|
||||||
"import openpyxl\n",
|
"import openpyxl\n",
|
||||||
"\n",
|
"\n",
|
||||||
"filename = 'data/result_cl.json'\n",
|
"filename = 'data/result_130.json'\n",
|
||||||
"with open(filename,'r') as fl:\n",
|
"with open(filename,'r') as fl:\n",
|
||||||
" dict1 = json.load(fl)\n",
|
" dict1 = json.load(fl)\n",
|
||||||
"list1 = []\n",
|
"list1 = []\n",
|
||||||
@@ -1025,8 +1135,8 @@
|
|||||||
" for k in item.keys():\n",
|
" for k in item.keys():\n",
|
||||||
" list1.append(k)\n",
|
" list1.append(k)\n",
|
||||||
"list2 = set(list1)\n",
|
"list2 = set(list1)\n",
|
||||||
"list2.remove('name')\n",
|
"#list2.remove('name')\n",
|
||||||
"list2.remove('bm')\n",
|
"#list2.remove('bm')\n",
|
||||||
"list2.remove('身高')\n",
|
"list2.remove('身高')\n",
|
||||||
"list2.remove('体重')\n",
|
"list2.remove('体重')\n",
|
||||||
"#print(list2)\n",
|
"#print(list2)\n",
|
||||||
@@ -1041,7 +1151,7 @@
|
|||||||
" col1[item] = s[n+1]\n",
|
" col1[item] = s[n+1]\n",
|
||||||
" n += 2\n",
|
" n += 2\n",
|
||||||
"#print(col)\n",
|
"#print(col)\n",
|
||||||
"filename = 'data/长岭体检人员得分情况表.xlsx'\n",
|
"filename = 'data/130人员得分情况表.xlsx'\n",
|
||||||
"wb = openpyxl.Workbook()\n",
|
"wb = openpyxl.Workbook()\n",
|
||||||
"sheet = wb.active\n",
|
"sheet = wb.active\n",
|
||||||
"sheet['A1'] = '测试编号'\n",
|
"sheet['A1'] = '测试编号'\n",
|
||||||
|
|||||||
+4330
File diff suppressed because it is too large.
Load diff
+63
-18
@@ -64,6 +64,66 @@
|
|||||||
"#print(dict1)"
|
"#print(dict1)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 12,
|
||||||
|
"id": "4a43668e-47ba-491f-a29c-e289885badb0",
|
||||||
|
"metadata": {
|
||||||
|
"execution": {
|
||||||
|
"iopub.execute_input": "2022-08-05T09:28:50.166885Z",
|
||||||
|
"iopub.status.busy": "2022-08-05T09:28:50.166355Z",
|
||||||
|
"iopub.status.idle": "2022-08-05T09:28:50.380976Z",
|
||||||
|
"shell.execute_reply": "2022-08-05T09:28:50.379827Z",
|
||||||
|
"shell.execute_reply.started": "2022-08-05T09:28:50.166837Z"
|
||||||
|
},
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import os,sys,shutil\n",
|
||||||
|
"import openpyxl\n",
|
||||||
|
"import math\n",
|
||||||
|
"\n",
|
||||||
|
"fi_xls = os.getcwd() + '/data/高新区.xlsx'\n",
|
||||||
|
"fi_path = os.getcwd() + '/file/220720'\n",
|
||||||
|
"old = []\n",
|
||||||
|
"dict1 = {}\n",
|
||||||
|
"\n",
|
||||||
|
"wb = openpyxl.load_workbook(fi_xls)\n",
|
||||||
|
"sheet = wb.active\n",
|
||||||
|
"depart = []\n",
|
||||||
|
"for n in range(2,sheet.max_row+1): \n",
|
||||||
|
" m_name = str(sheet.cell(n,1).value)\n",
|
||||||
|
" m_depart = sheet.cell(n,5).value\n",
|
||||||
|
" if m_depart not in depart:\n",
|
||||||
|
" depart.append(sheet.cell(n,5).value)\n",
|
||||||
|
" dict1[sheet.cell(n,4).value] = [sheet.cell(n,6).value,sheet.cell(n,3).value]\n",
|
||||||
|
"#print(dict1)\n",
|
||||||
|
"fl=os.listdir(fi_path)\n",
|
||||||
|
"for fn in fl:\n",
|
||||||
|
" if os.path.isfile(fi_path + '/' + fn):\n",
|
||||||
|
" ofn = int(fn.split('.')[0])\n",
|
||||||
|
" old.append(ofn) \n",
|
||||||
|
"old.sort()\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"wb = openpyxl.Workbook()\n",
|
||||||
|
"sheet = wb.active\n",
|
||||||
|
"i = 0\n",
|
||||||
|
" \n",
|
||||||
|
"for item in old:\n",
|
||||||
|
" m_bh = item\n",
|
||||||
|
" m_name = dict1[item][0]\n",
|
||||||
|
" m_dep = dict1[item][1]\n",
|
||||||
|
" i += 1\n",
|
||||||
|
" sheet[f'A{i}'] = m_bh\n",
|
||||||
|
" sheet[f'B{i}'] = m_name\n",
|
||||||
|
" sheet[f'C{i}'] = m_dep\n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
"wb.save('data/高新区报告.xlsx') "
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "72866db8-89be-4498-b854-a3aefe4c897a",
|
"id": "72866db8-89be-4498-b854-a3aefe4c897a",
|
||||||
@@ -126,16 +186,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 38,
|
"execution_count": null,
|
||||||
"id": "a34c9f6b-4ef3-4678-89bb-8b692e183968",
|
"id": "a34c9f6b-4ef3-4678-89bb-8b692e183968",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2022-07-31T13:49:49.854261Z",
|
|
||||||
"iopub.status.busy": "2022-07-31T13:49:49.853622Z",
|
|
||||||
"iopub.status.idle": "2022-07-31T13:49:50.369847Z",
|
|
||||||
"shell.execute_reply": "2022-07-31T13:49:50.368685Z",
|
|
||||||
"shell.execute_reply.started": "2022-07-31T13:49:49.854177Z"
|
|
||||||
},
|
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -233,17 +286,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 37,
|
"execution_count": null,
|
||||||
"id": "d77c3ff5-91fb-4449-80fb-57bc467c27bd",
|
"id": "d77c3ff5-91fb-4449-80fb-57bc467c27bd",
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"execution": {
|
|
||||||
"iopub.execute_input": "2022-07-27T14:01:56.902136Z",
|
|
||||||
"iopub.status.busy": "2022-07-27T14:01:56.901602Z",
|
|
||||||
"iopub.status.idle": "2022-07-27T14:01:56.957533Z",
|
|
||||||
"shell.execute_reply": "2022-07-27T14:01:56.956472Z",
|
|
||||||
"shell.execute_reply.started": "2022-07-27T14:01:56.902088Z"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import json\n",
|
"import json\n",
|
||||||
|
|||||||
Reference in new issue
Block a user