01 成绩整理
一、卷面分数
1、公众号成绩查询
将助教发送过来批改后的成绩经过整理, 形成在公众号 TSINGHUAZHUOQING 中可以公布的文档。 文档的格式如下图所示:
▲ 图1.1.1 公众号成绩查询文档格式
查询成绩的命令, 是在公众号后台发送查询命令:
公众号便会返回查询结果:
▲ 图1.1.2 考试成绩在公众号ZHUOQINGJOKING查询返回结果
2、成绩处理程序
下面代码是将 EXCEL 表格中的成绩进行统计之后,形成最终的公布文档。
from headm import *
import openpyxl
filename = r'D:\Temp\SCORE-ALL.xlsx'
wb = openpyxl.load_workbook(filename)
wss = wb.sheetnames
printf(wss)
ws = wb.get_sheet_by_name('期末考试')
outfile = r'd:\temp\ex2023.txt'
allcount = 0
average = 0
with open(outfile, 'w') as f:
f.write('信号与系统2023考试卷面分数\n\n学号:$1\n姓名:$2\n')
f.write('选择题:$3, 对错题:$4\n')
f.write('填空题:$5, 简答题:$6\n')
f.write('计算题:$7, 系统分析:$8\n')
f.write('欠采样:$9, 系统响应:$10\n')
f.write('A4纸:$11\n')
f.write('卷面总分:$12\n\n')
f.write('同学们可以在本周六(6月17日)上午9:00-11:30到中央主楼626B查看试卷批改情况。\n\n')
f.write('试卷平均分数(包括A4)为80.3分。\n\n')
f.write('-----------------------------------------------------\n\n')
for id,line in enumerate(ws):
if id == 0: continue
allscore = 0
scoredim = []
for iidd, l in enumerate(line):
v = l.value
vv = 0
if type(v) == int:
vv = int(v)
elif type(v) == float:
vv = float(v)
if iidd == 11:
vv = vv * 5
if iidd <= 9 and iidd >= 2:
scoredim.append(vv)
elif iidd == 11:
scoredim.append(vv)
allscore = sum(scoredim)
if allscore > 0:
allcount += 1
average += allscore
if allscore > 100:
printff('*****', scoredim)
f.write('%s\t%s\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\t%2.1f\n'%(
line[0].value, line[1].value,
scoredim[0],scoredim[1],scoredim[2],scoredim[3],
scoredim[4],scoredim[5],scoredim[6],scoredim[7],
scoredim[8], allscore))
printf(scoredim)
printff(allcount, average/allcount)
printf('\a')
二、合并期中考试
在 2023 年 4 月 20 日进行了 信号与系统2023随堂测验-60道选择题 测试。 下面将其中的分数与期末考试成绩进行合并。
1、结果写入 EXCEL
参考下面网络连接:
使用下面测试程序, 可以创建一个 EXCEL表格, 并写入测试内容。
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST1.PY -- by Dr. ZhuoQing 2023-06-15
#
# Note:
#============================================================
from headm import *
import openpyxl
#------------------------------------------------------------
outfile = r'd:\temp\scoreall.xlsx'
#------------------------------------------------------------
wb = openpyxl.Workbook()
#ws = wb.create_sheet('期中期末')
ws = wb.active
ws.title = '期中期末成绩'
fields = ['学号', '姓名', '期中成绩', '期末成绩']
for field in range(1, len(fields)+1):
_= ws.cell(row=1, column=field, value=fields[field-1])
for i in range(20):
ws.cell(row=2+i, column=1, value='11122233')
ws.cell(row=2+i, column=2, value='无名氏')
ws.cell(row=2+i, column=3, value=str(89.0))
ws.cell(row=2+i, column=4, value=str(11.0))
wb. save(outfile)
printf("\a")
#------------------------------------------------------------
#------------------------------------------------------------
# END OF FILE : TEST1.PY
#============================================================
▲ 图1.2.1 测试表单表格
2、合并其中期末程序
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST2.PY -- by Dr. ZhuoQing 2023-06-15
#
# Note:
#============================================================
from headm import *
import openpyxl
mfilename = r'D:\Teaching\SignalsSystems\SS2023S\Examination\FinalExam\Score\SCORE_MIDDLE.xlsx'
ffilename = r'D:\Teaching\SignalsSystems\SS2023S\Examination\FinalExam\Score\SCORE-AUTO.xlsx'
hwfilename = r'D:\Teaching\SignalsSystems\SS2023S\Examination\FinalExam\Score\hw2023only.txt'
msheet = '信号与系统随堂测验2023年试题_试卷'
fsheet = '期末考试'
#------------------------------------------------------------
mwb = openpyxl.load_workbook(mfilename)
mwbs = mwb.get_sheet_by_name(msheet)
mid = []
mname = []
mscore = []
for id,l in enumerate(mwbs):
if id < 2: continue
mid.append(l[0].value)
mname.append(l[3].value)
mscore.append(l[4].value)
#------------------------------------------------------------
fwb = openpyxl.load_workbook(ffilename, data_only=True)
fwbs = fwb.get_sheet_by_name(fsheet)
fid = []
fname = []
fscore = []
for id, l in enumerate(fwbs):
# if id > 10: break
if id < 1: continue
fid.append(l[0].value)
fname.append(l[1].value)
score = 0
if type(l[10].value) == int or type(l[10].value) == float:
score = float(l[10].value)
if type(l[11].value) == int or type(l[11].value) == float:
score += float(l[11].value) * 5
if score > 100: score = 100
# printff(l[0].value, l[1].value, l[10].value, l[11].value, score)
fscore.append(score)
#------------------------------------------------------------
hwid = []
hwscore = []
hwoption = []
with open(hwfilename, 'r') as f:
for l in f.readlines():
ll = l.split('\t')
hwid.append(ll[0])
hwscore.append(float(ll[2]))
hwoption.append(float(ll[3]))
#------------------------------------------------------------
outfile = r'd:\temp\scoreall.xlsx'
wb = openpyxl.Workbook()
#ws = wb.create_sheet('期中期末')
ws = wb.active
ws.title = '期中期末成绩'
fields = ['学号', '姓名', '期中成绩', '期末成绩', '作业成绩', '选做题', '小论文', '课堂成绩', '总成绩']
for field in range(1, len(fields)+1):
_= ws.cell(row=1, column=field, value=fields[field-1])
for i in range(len(fid)):
id = mid.index(fid[i])
hid = hwid.index(fid[i])
ws.cell(row=2+i, column=1, value=fid[i])
ws.cell(row=2+i, column=2, value=fname[i])
ws.cell(row=2+i, column=3, value=str(mscore[id]))
ws.cell(row=2+i, column=4, value=str(fscore[i]))
ws.cell(row=2+i, column=5, value=str(hwscore[hid]))
ws.cell(row=2+i, column=6, value=str(hwoption[hid]))
wb.save(outfile)
#------------------------------------------------------------
printf('Save the result file:%s\a'%outfile)
#------------------------------------------------------------
# END OF FILE : TEST2.PY
#============================================================
三、课程成绩统计
from headm import *
import openpyxl
clfilename = r'D:\Teaching\SignalsSystems\SS2023S\Examination\FinalExam\Score\PHONENAME_DATA.TXT'
scfilename = r'D:\Teaching\SignalsSystems\SS2023S\Examination\FinalExam\Score\scoreall.xlsx'
wb = openpyxl.load_workbook(scfilename)
wbs = wb.active
iddim = []
namedim = []
for id,l in enumerate(wbs):
if id < 1: continue
iddim.append(l[0].value)
namedim.append(l[1].value)
printf(iddim, namedim)
scoredim = [0]*len(iddim)
with open(clfilename, 'r') as f:
for l in f.readlines():
ll = l.split(' ')
if not ll[0] in namedim:
printf(ll[0])
else:
id = namedim.index(ll[0])
score = int(ll[4])
scoredim[id] = score
outfile = r'd:\temp\1.txt'
with open(outfile, 'w') as f:
for i in range(len(iddim)):
f.write('%s\t%s\t%d\n'%(iddim[i], namedim[i], scoredim[i]))
printf(scoredim)
printf('\a')
■ 相关文献链接:
● 相关图表链接: