This commit is contained in:
512song@sina.com committed 2022-08-06 16:47:05 +08:00
1 parent 268fd87e95
commit f0667bdb25
3 files changed
+4509 -24

No files matched your search

+116 -6
View File
@@ -889,6 +889,14 @@
"## 获取人员测试成绩"
]
},
{
"cell_type": "markdown",
"id": "8814b784-f561-455b-9125-b20672df2379",
"metadata": {},
"source": [
"### 读取数据库获取人员测试成绩"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -945,6 +953,89 @@
"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",
"id": "95df2637-7898-4446-bb8a-70d881bd9e44",
@@ -1007,17 +1098,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "a7cf5e57-a381-4911-96ff-1e1469b6f9bc",
"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": []
},
"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": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/result_cl.json'\n",
"filename = 'data/result_130.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"list1 = []\n",
@@ -1025,8 +1135,8 @@
" for k in item.keys():\n",
" list1.append(k)\n",
"list2 = set(list1)\n",
"list2.remove('name')\n",
"list2.remove('bm')\n",
"#list2.remove('name')\n",
"#list2.remove('bm')\n",
"list2.remove('身高')\n",
"list2.remove('体重')\n",
"#print(list2)\n",
@@ -1041,7 +1151,7 @@
" col1[item] = s[n+1]\n",
" n += 2\n",
"#print(col)\n",
"filename = 'data/长岭体检人员得分情况表.xlsx'\n",
"filename = 'data/130人员得分情况表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet['A1'] = '测试编号'\n",