2020年,由于新冠疫情(Coronavirus-19)的影响, 2020年春季学期各班信号与系统期末考试 采用了网络考试的方式,同学将试卷上载的清华网络学堂之后。然后在统一下载。
信号与系统试卷 总共有八道试题,总分100分,考试过程进行了两小时15分钟。
批改试卷的过程就是通过阅读上载的电子文档,然后将八道题的题目给出分数,然后登录到学生成绩EXCEL中。随着批改试卷过程,判定分数的过程会越来熟练,但是将分数登录到EXCEL格过程则会出现一定的困难:
下面通过PYTHON命令完成自动程序录入过程,PYTHON 程序完成以下功能:
对于学生的信息进行一下处理:
1. 生成学生学号与姓名TEXT文件
具体过程参照: 2020信号与系统课程学生信息转换。
2. 下载学生答案答辩文件并加压缩
将加压缩后的文件进行名称转换。
具体过程参照: 2020信号与系统课程学生信息转换。
▲ 将解压文件进行名称转换
文件名称转换PYTHON程序:
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FILENAMECHANGE.PY -- by Dr. ZhuoQing 2020-06-19
#
# Note:
#============================================================
from headm import *
from inforsub import *
#------------------------------------------------------------
siau = text2infor(ssau)
sixy = text2infor(ssxy)
#------------------------------------------------------------
filedir = tspstring2text('ssxy')
printf(filedir)
filedim = os.listdir(filedir)
filenew = [(f.split('_')[0], os.path.splitext(f)[-1]) for f in filedim]
fileout = []
changecount = 0
for id,f in enumerate(filenew):
name = sixy[f[0]]
fo = '%s_%s%s'%(f[0],name,f[1])
fold = os.path.join(filedir, filedim[id])
fnew = os.path.join(filedir, fo)
if os.path.isfile(fold):
os.rename(fold, fnew)
changecount = changecount + 1
printf('Change:%d\a'%changecount)
#------------------------------------------------------------
# END OF FILE : FILENAMECHANGE.PY
#============================================================
3. 创建学生成绩EXCEL文件
这部分根据网络学堂下载所有学生的信息,并生成对应的EXCEL文件。
在EXCEL文件中重新生成一个表单“Exam”:
表单第一行为表头;表单前两列分别是ID和姓名。格式如下:
▲ 记录成绩的EXCEL表单结构
为了能够适应PYTHON对EXCEL处理,EXCEL表格的格式需要通过EXCEL另存为修改成.XLSX的格式。
1. 功能介绍
在此过程中需要对程序中的前面的变量进行正确的设置:
xyinfor = text2infor(ssxy)
auinfor = text2infor(ssau)
xyexcel = r'D:\Teaching\SignalsSystems\SS2020S\Examination\Excel\SSXY-SCORE.xlsx'
auexcel = r'D:\Teaching\SignalsSystems\SS2020S\Examination\Excel\SSAU-SCORE.xlsx'
这个程序可以自动根据学生ID号在判断对哪一个EXCEL文件进行修改。
在运行程序之前,先打开一个学生答案文件,可以是PDF,WORD,ZIP文件
(1) score (无参数): 显示当前学生的成绩信息
(2) score n1 n2: 对当前学生的第n1道题目的分数修改成n2
(3) score n1 n2 n3 n4 n5 n6 n7 n8 :
将当前评阅学生的八道题目的成绩录入。
2. 程序实现
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# SCORE.PY -- by Dr. ZhuoQing 2020-06-19
#
# Note:
#============================================================
from head import *
from inforsub import *
#------------------------------------------------------------
xyinfor = text2infor(ssxy)
auinfor = text2infor(ssau)
xyexcel = r'D:\Teaching\SignalsSystems\SS2020S\Examination\Excel\SSXY-SCORE.xlsx'
auexcel = r'D:\Teaching\SignalsSystems\SS2020S\Examination\Excel\SSAU-SCORE.xlsx'
if len(xyinfor) == 0:
printf("No student infor.\a")
exit()
if len(auinfor) == 0:
printf("No student infor.\a")
exit()
if os.path.isfile(xyexcel) == False:
printf("No output excel file.%s"%excelfile)
exit()
if os.path.isfile(auexcel) == False:
printf("No output excel file.%s"%excelfile)
exit()
#------------------------------------------------------------
printf('')
#------------------------------------------------------------
idstr = ''
namestr = ''
excelfile = ''
idsamecount = 0
title = tspgetwindowtitle()
for t in title:
ts = t.split('_')
if len(ts) < 2: continue
if ts[0] in xyinfor:
idstr = ts[0]
namestr = xyinfor[idstr]
excelfile = xyexcel
idsamecount = idsamecount + 1
printf('%s_%s:%s\a'%(idstr, namestr, excelfile))
# break
if ts[0] in auinfor:
idstr = ts[0]
namestr = auinfor[idstr]
excelfile = auexcel
idsamecount = idsamecount + 1
printf('%s_%s:%s\a'%(idstr, namestr, excelfile))
# break
if idsamecount != 1:
printf("ERROR: idsame count : %d.\a"%idsamecount)
exit()
#if len(idstr) == 0:
# printf("ERROR: No find id string.\a")
# exit()
#printf('%s_%s:%s\a'%(idstr, namestr, excelfile))
#------------------------------------------------------------
if len(sys.argv) < 3:
# printf("Usage: score s1 s2 s3....")
showexcelcell(excelfile, int(idstr))
exit()
if len(sys.argv) == 3:
scoreid = int(sys.argv[1])
score = float(sys.argv[2])
if scoreid < 1 or scoreid > 8:
printf("Score id ERROR.\a")
exit()
setexcelcell(excelfile, int(idstr), scoreid, score)
printf('\a')
exit()
#------------------------------------------------------------
if len(sys.argv) != 9:
printf("Usage: score s1 s2 ...s8\a")
exit()
scoredim = []
for s in sys.argv[1:]:
scoredim.append(float(s))
printf(scoredim)
setexcelcells(excelfile, int(idstr), scoredim)
printf('Total:%5.2f\a'%sum(scoredim))
#------------------------------------------------------------
# END OF FILE : SCORE.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# INFORSUB.PY -- by Dr. ZhuoQing 2020-06-18
#
# Note:
#============================================================
from headm import *
import pandas as pd
#------------------------------------------------------------
ssau = 2
ssxy = 3
#------------------------------------------------------------
def text2infor(fileid):
filename = tspgetdopfile(fileid)
# printf(filename)
studentdict = {}
with open(filename, 'r', encoding='gbk') as f:
for l in (f.readlines()):
l.rstrip('\n')
lsect = l.split()
if lsect[0] == '学号':
continue
studentdict[lsect[0]] = lsect[1]
return studentdict
#------------------------------------------------------------
def setexcelcell(filename, sid, col, num):
excelfile = pd.read_excel(filename, sheet_name='Exam')
listdata = excelfile.values.tolist()
rowid = -1
for id,l in enumerate(listdata):
if l[0] == sid:
rowid = id
printff(id, listdata[id])
break
if rowid < 0:
printf("ERROR: Can not find %d in %s.\a"%(sid, filename))
return
excelfile.iat[rowid, col+1] = num
listdata = excelfile.values.tolist()
printff(rowid, listdata[rowid], sum(listdata[rowid][2:]))
excelfile.to_excel(filename, sheet_name='Exam', index=False)
#------------------------------------------------------------
def showexcelcell(filename, sid):
excelfile = pd.read_excel(filename, sheet_name='Exam')
listdata = excelfile.values.tolist()
if sid == 0:
for l in listdata:
s = '%s %d'%(str(l), sum(l[2:]))
ss = s.replace('\'', '')
ss = ss.replace('[', '')
ss = ss.replace(']', '')
ss = ss.replace(',', '')
printf(ss)
return
#--------------------------------------------------------
rowid = -1
for id,l in enumerate(listdata):
if l[0] == sid:
rowid = id
printff(id, listdata[id],sum(listdata[id][2:]))
break
if rowid < 0:
printf("ERROR: Can not find %d in %s.\a"%(sid, filename))
return
#------------------------------------------------------------
def setexcelcells(filename, sid, num):
excelfile = pd.read_excel(filename, sheet_name='Exam')
listdata = excelfile.values.tolist()
rowid = -1
for id,l in enumerate(listdata):
if l[0] == sid:
rowid = id
printff(id, listdata[id])
break
if rowid < 0:
printf("ERROR: Can not find %d in %s.\a"%(sid, filename))
return
for id, n in enumerate(num):
excelfile.iat[rowid, id+2] = n
listdata = excelfile.values.tolist()
printff(rowid, listdata[rowid], sum(listdata[rowid][2:]))
excelfile.to_excel(filename, sheet_name='Exam', index=False)
#------------------------------------------------------------
if __name__ == "__main__":
filename = r'D:\Teaching\SignalsSystems\SS2020S\Examination\Excel\SSXY-SCORE.xlsx'
setexcelcell(filename, 2017013661, 1, 10)
'''
si = text2infor(ssau)
printff(len(si), si)
si = text2infor(ssxy)
printff(len(si), si)
'''
#------------------------------------------------------------
# END OF FILE : INFORSUB.PY
#============================================================
通过该程序,可提高试卷批改的速度,减少成绩录入过程中的错误。