This commit is contained in:
512song committed 2023-10-06 17:38:17 +08:00
1 parent 19dc6ed276
commit 564b01f993
1 file changed
+413
+413
View File
@@ -4,6 +4,7 @@
"cell_type": "markdown",
"id": "55644860-57e6-466b-b6e9-e6fdd807498d",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@@ -1124,6 +1125,418 @@
"wb.save(filename)"
]
},
{
"cell_type": "markdown",
"id": "16473cee-7ca6-4092-a29a-ce0de31af247",
"metadata": {},
"source": [
"## 汇总学生得分"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "38b01352-28cc-448f-8ca7-19d61cbeebc0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T07:40:45.818048Z",
"iopub.status.busy": "2023-10-06T07:40:45.817653Z",
"iopub.status.idle": "2023-10-06T07:40:46.111376Z",
"shell.execute_reply": "2023-10-06T07:40:46.110921Z",
"shell.execute_reply.started": "2023-10-06T07:40:45.818014Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'data/长岭学生名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
"dict1 = {}\n",
"wb = openpyxl.load_workbook('data/长岭学生体测成绩表.xlsx')\n",
"sheet = wb.active\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = str(sheet.cell(n,1).value)\n",
" dict1[code] = dict2[code]\n",
" dict1[code]['grade'] = dict2[code]['unit'][:1]\n",
" if sheet.cell(n,5).value is not None:\n",
" dict1[code]['BMI'] = int(sheet.cell(n,5).value)\n",
" if sheet.cell(n,6).value is not None:\n",
" dict1[code]['肺活量'] = int(sheet.cell(n,6).value)\n",
" if sheet.cell(n,7).value is not None:\n",
" dict1[code]['坐位体前屈'] = int(sheet.cell(n,7).value)\n",
" if sheet.cell(n,8).value is not None:\n",
" dict1[code]['50米跑'] = int(sheet.cell(n,8).value)\n",
" if sheet.cell(n,9).value is not None:\n",
" dict1[code]['一分钟跳绳'] = int(sheet.cell(n,9).value)\n",
" if sheet.cell(n,10).value is not None:\n",
" dict1[code]['仰卧起坐'] = int(sheet.cell(n,10).value)\n",
" if sheet.cell(n,11).value is not None:\n",
" dict1[code]['往返跑'] = int(sheet.cell(n,11).value)\n",
" \n",
"filename = f'data/score_长岭学生.json'\n",
"\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok') \n",
" \n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"id": "48ed4623-63db-4abc-bf42-3873df1bff03",
"metadata": {},
"source": [
"## 计算学生总分及平均分"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "ab7cc750-bff0-44ec-8652-21f8dc3100ef",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T07:50:23.851597Z",
"iopub.status.busy": "2023-10-06T07:50:23.851131Z",
"iopub.status.idle": "2023-10-06T07:50:23.884379Z",
"shell.execute_reply": "2023-10-06T07:50:23.883103Z",
"shell.execute_reply.started": "2023-10-06T07:50:23.851548Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = f'data/score_长岭学生.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"items =['BMI','肺活量','坐位体前屈','50米跑','一分钟跳绳','仰卧起坐','往返跑']\n",
"for k, v in dict1.items():\n",
" i = 0\n",
" t_score = 0\n",
" for item in items:\n",
" if item in v.keys():\n",
" i+=1\n",
" t_score = t_score + v[item]\n",
" dict1[k]['总分'] = t_score\n",
" dict1[k]['平均分'] =round(t_score/i,2)\n",
" dict1[k]['项目数'] = i\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False)\n",
"print('ok') "
]
},
{
"cell_type": "markdown",
"id": "0c903c43-8577-4075-b9bb-7fb37ec1a685",
"metadata": {},
"source": [
"## 统计男女学生数据"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "5e15984f-0747-48ea-b71e-ffc8e30775c9",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T07:58:16.601462Z",
"iopub.status.busy": "2023-10-06T07:58:16.600990Z",
"iopub.status.idle": "2023-10-06T07:58:16.616444Z",
"shell.execute_reply": "2023-10-06T07:58:16.615337Z",
"shell.execute_reply.started": "2023-10-06T07:58:16.601425Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"男性学生人数: 281\n",
"男性学生平均成绩: 71.68982206405693\n",
"女性学生人数: 237\n",
"女性学生平均成绩: 73.33818565400843\n",
"参加测试学生人数: 518\n",
"所有学生平均成绩: 72.44399613899613\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = f'data/score_长岭学生.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"n = 0\n",
"f = 0\n",
"m = 0\n",
"m_score = 0\n",
"f_score = 0\n",
"for k, v in dict1.items():\n",
" if v['sex'] == '男':\n",
" m+=1\n",
" m_score = m_score + v['平均分']\n",
" else:\n",
" f+=1\n",
" f_score = f_score + v['平均分']\n",
"print('男性学生人数:',m)\n",
"print('男性学生平均成绩:',m_score/m)\n",
"print('女性学生人数:',f)\n",
"print('女性学生平均成绩:',f_score/f)\n",
"print('参加测试学生人数:',f+m)\n",
"print('所有学生平均成绩:',(f_score+m_score)/(f+m)) \n",
" "
]
},
{
"cell_type": "markdown",
"id": "016c6e24-5f4e-4eee-9d01-de93c745fa0d",
"metadata": {},
"source": [
"## 统计各年级学生数据"
]
},
{
"cell_type": "markdown",
"id": "1de34752-0ed3-4601-9f55-88df263b3a62",
"metadata": {},
"source": [
"### 按年级整理数据"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "bb71c8d2-e445-48c3-8673-84c965f6efe2",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T08:46:27.643939Z",
"iopub.status.busy": "2023-10-06T08:46:27.643406Z",
"iopub.status.idle": "2023-10-06T08:46:27.677668Z",
"shell.execute_reply": "2023-10-06T08:46:27.676266Z",
"shell.execute_reply.started": "2023-10-06T08:46:27.643901Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = f'data/score_长岭学生.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"grade =['一','二','三','四','五','六']\n",
"dict2 = {}\n",
"items =['BMI','肺活量','坐位体前屈','50米跑','一分钟跳绳','仰卧起坐','往返跑']\n",
"for k, v in dict1.items():\n",
" sex = v['sex']\n",
" dict2.setdefault(v['grade'],{})\n",
" dict2[v['grade']].setdefault(sex,{})\n",
" for item in v.keys():\n",
" if item in items:\n",
" dict2[v['grade']][sex].setdefault(item,[0.00,0,0])\n",
" dict2[v['grade']][sex][item][0] = dict2[v['grade']][sex][item][0]+v[item]\n",
" dict2[v['grade']][sex][item][1] = dict2[v['grade']][sex][item][1] + 1\n",
" dict2[v['grade']][sex][item][2] = round(dict2[v['grade']][sex][item][0]/dict2[v['grade']][sex][item][1],2)\n",
"filename = f'data/grade_长岭学生.json'\n",
"\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict2, fl, ensure_ascii=False)\n",
"print('ok') "
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "35558059-3e86-4e74-8fde-794d1b2933c4",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T09:09:19.094296Z",
"iopub.status.busy": "2023-10-06T09:09:19.093852Z",
"iopub.status.idle": "2023-10-06T09:09:19.120750Z",
"shell.execute_reply": "2023-10-06T09:09:19.119594Z",
"shell.execute_reply.started": "2023-10-06T09:09:19.094259Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"\n",
"filename = f'data/score_长岭学生.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"grade =['一','二','三','四','五','六']\n",
"dict2 = {}\n",
"items =['BMI','肺活量','坐位体前屈','50米跑','一分钟跳绳','仰卧起坐','往返跑']\n",
"for k, v in dict1.items():\n",
" sex = v['sex']\n",
" dict2.setdefault(v['grade'],{}) \n",
" for item in v.keys():\n",
" if item in items:\n",
" dict2[v['grade']].setdefault(item,[0.00,0,0])\n",
" dict2[v['grade']][item][0] = dict2[v['grade']][item][0]+v[item]\n",
" dict2[v['grade']][item][1] = dict2[v['grade']][item][1] + 1\n",
" dict2[v['grade']][item][2] = round(dict2[v['grade']][item][0]/dict2[v['grade']][item][1],2)\n",
"filename = f'data/grade_长岭学生(不区分性别).json'\n",
"\n",
"with open(filename, 'w') as fl:\n",
" json.dump(dict2, fl, ensure_ascii=False)\n",
"print('ok') "
]
},
{
"cell_type": "markdown",
"id": "3e5e1db3-3f2a-42b4-afb4-5249067ef441",
"metadata": {},
"source": [
"### 按年级计算平均分"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "68de3c86-53e5-470f-9afb-6781df3c1449",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-06T09:01:17.624309Z",
"iopub.status.busy": "2023-10-06T09:01:17.623830Z",
"iopub.status.idle": "2023-10-06T09:01:17.635805Z",
"shell.execute_reply": "2023-10-06T09:01:17.634865Z",
"shell.execute_reply.started": "2023-10-06T09:01:17.624272Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"六年级测试得分情况:\n",
"男生测试得分情况: 74.24\n",
"女生测试得分情况: 74.14\n",
"年级测试得分情况: 74.19\n",
"五年级测试得分情况:\n",
"男生测试得分情况: 72.11\n",
"女生测试得分情况: 72.54\n",
"年级测试得分情况: 72.33\n",
"四年级测试得分情况:\n",
"男生测试得分情况: 69.87\n",
"女生测试得分情况: 71.98\n",
"年级测试得分情况: 70.93\n",
"三年级测试得分情况:\n",
"男生测试得分情况: 67.49\n",
"女生测试得分情况: 71.17\n",
"年级测试得分情况: 69.33\n",
"二年级测试得分情况:\n",
"男生测试得分情况: 75.3\n",
"女生测试得分情况: 76.06\n",
"年级测试得分情况: 75.68\n",
"一年级测试得分情况:\n",
"男生测试得分情况: 72.66\n",
"女生测试得分情况: 73.44\n",
"年级测试得分情况: 73.05\n"
]
}
],
"source": [
"filename = f'data/grade_长岭学生.json'\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"for k, v in dict1.items():\n",
" print(f'{k}年级测试得分情况:')\n",
" i = 0\n",
" m_score = 0\n",
" for k1,v1 in v['男'].items():\n",
" i+=1\n",
" m_score = m_score + v1[0]/v1[1]\n",
" print(f'男生测试得分情况:',round(m_score/i,2))\n",
" n = 0\n",
" f_score = 0\n",
" for k1,v1 in v['女'].items():\n",
" n+=1\n",
" f_score = f_score + v1[0]/v1[1]\n",
" print(f'女生测试得分情况:',round(f_score/n,2))\n",
" print(f'年级测试得分情况:',round((m_score+f_score)/(i+n),2))"
]
},
{
"cell_type": "markdown",
"id": "da69c668-57e7-41bb-b4c6-5eac86d7e2b8",
"metadata": {},
"source": [
"### 按年级计算项目平均分"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eae0a7f3-ae42-499d-8b65-667b0b320dff",
"metadata": {},
"outputs": [],
"source": [
"filename = f'data/grade_长岭学生.json'\n",
"\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"items =['BMI','肺活量','坐位体前屈','50米跑','一分钟跳绳','仰卧起坐','往返跑']\n",
"for k, v in dict1.items():\n",
" print(f'{k}年级测试得分情况:')\n",
" f = 0\n",
" m = 0\n",
" f_score = 0\n",
" m_score = 0\n",
" for item in items:\n",
" for k1,v1 in v['男'].items():\n",
" if item in v1.keys():\n",
" \n",
" \n",
" i+=1\n",
" score = score + v1[0]/v1[1]"
]
},
{
"cell_type": "markdown",
"id": "6cd42cb2-37a4-44e8-87cb-afd71b32e81f",