批阅论文和作业Python程序助手
【摘要】
简 介: 利用网络学堂下载的作业文件中包含学号的信息,通过Python程序,可以自动定位EXCEL表中记录表格,使得成绩记录精确可靠。 关键词: EXCEL,成绩,作业
...
简 介: 利用网络学堂下载的作业文件中包含学号的信息,通过Python程序,可以自动定位EXCEL表中记录表格,使得成绩记录精确可靠。
关键词
: EXCEL,成绩,作业
§01 批阅作业
1.1 背景介绍
每到学期末,批阅课程学生提交的作业和论文的工作量很大。对于作业和论文成绩的等级也许需要做到精确可靠。
从网络学堂上可以下载到如下文件:
- 学生信息表格,前两列为学号和姓名;
- 作业和论文的打包文件;
在作业和论文文件下载时,网络学堂自动会在文件名称前增加了学号,因此可以以此为索引完成成绩在EXCEL表格中的记录。
本文下面给出的程序,通过几个学期的使用,验证了它的高效与可靠性。
1.2 处理程序
1.2.1 使用环境
- TEASOFT辅助程序。并在当前DOP中建立起EXCEL索引文件名称。
SHZH:
H:\Teaching\NN2021A\Homework\SZH.xls
TSH:
H:\Teaching\NN2021A\Homework\TSH.xls
- 1
- 2
- 3
- 4
EXCEL表格中的抬头应该与setscore中对应:
▲ 图1.2.1 EXCEL表格信息
1.2.2 处理程序
(1)记录所有提交文件
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# SETALLSCORE.PY -- by Dr. ZhuoQing 2021-12-27
#
# Note:
#============================================================
from headm import * # =
#------------------------------------------------------------
import inforsub
#------------------------------------------------------------
def dropfile2studentid():
tspdropfile2pastetext()
pastestr = clipboard.paste()
strsect = pastestr.split('\\')
printf(strsect)
for s in strsect[-1:0:-1]:
if s.count('_') >= 1:
if s.split('_')[0].isdigit():
return s.split('_')[0]
if s.split('_')[0][0] == 'P':
return s.split('_')[0]
return "ERROR"
#------------------------------------------------------------
def setscore(idstr, hwstr, score):
ret = inforsub.setexcelcellstring(inforsub.tshfile, idstr, hwstr, score)
if ret >= 0: return 'TS',ret
ret = inforsub.setexcelcellstring(inforsub.shzhfile, idstr, hwstr, score)
if ret >= 0: return 'SHZH',ret
return ' ', -1
#------------------------------------------------------------
def appendscore(idstr, hwstr, score):
ret = inforsub.appendexcelcellstring(inforsub.tshfile, idstr, hwstr, score)
if ret >= 0:
return 'TS',ret
ret = inforsub.appendexcelcellstring(inforsub.shzhfile, idstr, hwstr, score)
if ret >= 0:
return 'SHZH',ret
return ' ', -1
def showscore(idstr):
ret = inforsub.showexcelinfor(inforsub.tshfile, idstr)
if ret >= 0: return 'TS', ret
ret = inforsub.showexcelinfor(inforsub.shzhfile, idstr)
if ret >=0: return 'SHZH', ret
return ' ', -1
#------------------------------------------------------------
tspdropfile2pastetext()
pastestr = clipboard.paste().split('\n')
#------------------------------------------------------------
id = []
for ps in pastestr:
pss = ps.split('\\')[-1]
pss = pss.split('_')[0]
if len(pss) > 0:
id.append(pss)
id = list(set(id))
printf(id, len(id))
#------------------------------------------------------------
if __name__ == "__main__":
hwstr = ''
scorestr = ''
if len(sys.argv) < 3:
printf("Usage: setallscore hw score\a")
exit()
#--------------------------------------------------------
if len(sys.argv) > 1:
hwstr = sys.argv[1]
if hwstr in "hw1 hw2 hw3 hw4".split():
hwstr = hwstr.upper()
if hwstr in "1 2 3 4".split():
hwstr = "HW%s"%hwstr
if hwstr == 'note':
hwstr = 'NOTE'
if hwstr == 'n':
hwstr = 'NOTE'
if hwstr == 'paper':
hwstr = 'PAPER'
if hwstr == 'p':
hwstr = 'PAPER'
if not hwstr in 'HW1 HW2 HW3 HW4 PAPER NOTE'.split():
printf('HW string error[%s].\a'%hwstr)
exit()
if len(sys.argv) > 2:
scorestr = sys.argv[2]
for idstr in id:
# printf('Begin Modified:')
# showscore(idstr)
if len(hwstr) > 0:
if hwstr == 'NOTE':
appendscore(idstr, 'NOTE', scorestr)
else: setscore(idstr, hwstr, scorestr)
# printf("After Modified:")
# showscore(idstr)
id = list(set(id))
printf(id, len(id))
printf('\a')
#------------------------------------------------------------
# END OF FILE : SETALLSCORE.PY
#============================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
(2)登记单个文件成绩
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# SETSCORE.PY -- by Dr. ZhuoQing 2021-01-02
#
# Note:
#============================================================
from head import *
import inforsub
#------------------------------------------------------------
def dropfile2studentid():
tspdropfile2pastetext()
pastestr = clipboard.paste()
strsect = pastestr.split('\\')
printf(strsect)
for s in strsect[-1:0:-1]:
if s.count('_') >= 1:
if s.split('_')[0].isdigit():
return s.split('_')[0]
if s.split('_')[0][0] == 'P':
return s.split('_')[0]
return "ERROR"
#------------------------------------------------------------
def setscore(idstr, hwstr, score):
ret = inforsub.setexcelcellstring(inforsub.tshfile, idstr, hwstr, score)
if ret >= 0: return 'TS',ret
ret = inforsub.setexcelcellstring(inforsub.shzhfile, idstr, hwstr, score)
if ret >= 0: return 'SHZH',ret
return ' ', -1
#------------------------------------------------------------
def appendscore(idstr, hwstr, score):
ret = inforsub.appendexcelcellstring(inforsub.tshfile, idstr, hwstr, score)
if ret >= 0:
return 'TS',ret
ret = inforsub.appendexcelcellstring(inforsub.shzhfile, idstr, hwstr, score)
if ret >= 0:
return 'SHZH',ret
return ' ', -1
def showscore(idstr):
ret = inforsub.showexcelinfor(inforsub.tshfile, idstr)
if ret >= 0: return 'TS', ret
ret = inforsub.showexcelinfor(inforsub.shzhfile, idstr)
if ret >=0: return 'SHZH', ret
return ' ', -1
#------------------------------------------------------------
if __name__ == "__main__":
idstr = dropfile2studentid()
if idstr == 'ERROR':
printf("No student id is found by drop file !\a")
exit()
printf('ID : %s\a'%idstr)
#--------------------------------------------------------
hwstr = ''
scorestr = ''
printf('Begin Modified:')
x, y = showscore(idstr)
printff(x,y)
if len(sys.argv) > 1:
hwstr = sys.argv[1]
if hwstr in "hw1 hw2 hw3 hw4".split():
hwstr = hwstr.upper()
if hwstr in "1 2 3 4".split():
hwstr = "HW%s"%hwstr
if hwstr == 'note':
hwstr = 'NOTE'
if hwstr == 'n':
hwstr = 'NOTE'
if hwstr == 'paper':
hwstr = 'PAPER'
if hwstr == 'p':
hwstr = 'PAPER'
if not hwstr in 'HW1 HW2 HW3 HW4 PAPER NOTE'.split():
printf('HW string error[%s].\a'%hwstr)
exit()
if len(sys.argv) > 2:
scorestr = sys.argv[2]
if len(hwstr) > 0:
if hwstr == 'NOTE':
appendscore(idstr, 'NOTE', scorestr)
else: setscore(idstr, hwstr, scorestr)
#--------------------------------------------------------
printf("After Modified:")
showscore(idstr)
printf(' \a')
#------------------------------------------------------------
# END OF FILE : SETSCORE.PY
#============================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
(3)辅助程序
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# INFORSUB.PY -- by Dr. ZhuoQing 2020-06-18
#
# Note:
#============================================================
from headm import * # =
import pandas as pd
#------------------------------------------------------------
tshfile = tspstring2text('TSH')
shzhfile = tspstring2text('SHZH')
HOMEWORK_SHEET = 'homework'
#------------------------------------------------------------
def showexcel(filename):
excelfile = pd.read_excel(filename, sheet_name=HOMEWORK_SHEET)
listdata = excelfile.values.tolist()
for id,l in enumerate(listdata):
printff(id, l)
def showexcelinfor(filename, sid):
excelfile = pd.read_excel(filename, sheet_name=HOMEWORK_SHEET)
rowid = -1
for id, content in excelfile.items():
if id == '学号':
content = [str(s) for s in content]
if str(sid) in content:
rowid = content.index(str(sid))
break
if rowid < 0:
return rowid
printf(excelfile.values.tolist()[rowid])
return rowid
#------------------------------------------------------------
def setexcelcellstring(filename, sid, col, num):
excelfile = pd.read_excel(filename, sheet_name=HOMEWORK_SHEET)
rowid = -1
for id, content in excelfile.items():
if id == '学号':
content = [str(s) for s in content]
if str(sid) in content:
rowid = content.index(str(sid))
break
if rowid < 0:
return rowid
printff(rowid, col)
excelfile[col] = excelfile[col].astype(str)
excelfile.at[rowid, col] = num
excelfile.to_excel(filename, sheet_name=HOMEWORK_SHEET, index=False)
return rowid
#------------------------------------------------------------
def appendexcelcellstring(filename, sid, col, num):
excelfile = pd.read_excel(filename, sheet_name=HOMEWORK_SHEET)
rowid = -1
for id, content in excelfile.items():
if id == '学号':
content = [str(s) for s in content]
if str(sid) in content:
rowid = content.index(str(sid))
break
if rowid < 0:
return rowid
printff(rowid, col)
excelfile[col] = excelfile[col].astype(str)
if excelfile.at[rowid, col] != 'nan':
excelfile.at[rowid, col] = num + ', ' + excelfile.at[rowid, col]
else: excelfile.at[rowid, col] = num
if len(num) == 0: excelfile.at[rowid, col] = ''
excelfile.to_excel(filename, sheet_name=HOMEWORK_SHEET, index=False)
return rowid
#------------------------------------------------------------
def getexcelcellstring(filename, sid, col):
excelfile = pd.read_excel(filename, sheet_name=HOMEWORK_SHEET)
rowid = -1
for id, content in excelfile.items():
if id == '学号':
content = [str(s) for s in content]
if str(sid) in content:
rowid = content.index(str(sid))
break
if rowid < 0:
return rowid
# printff(rowid, col)
# excelfile[col] = excelfile[col].astype(str)
return excelfile.at[rowid, col]
#------------------------------------------------------------
if __name__ == "__main__":
# setexcelcellstring(tshfile, '2020210975', 'HW1', 88)
# s = getexcelcellstring(tshfile, '2020210975', 'HW1')
# printf(s)
# showexcel(shzhfile)
x=showexcelinfor(shzhfile, '2020280355')
printf(x)
#------------------------------------------------------------
# END OF FILE : INFORSUB.PY
#============================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
(4)统计缺少信息
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# NOWORK.PY -- by Dr. ZhuoQing 2021-12-27
#
# Note:
#============================================================
from headm import * # =
strid = 14
tspgetdopstring(-strid)
allstr = [s for s in clipboard.paste().split("\r\n") if len(s) > 0]
printf(allstr)
#------------------------------------------------------------
infordim = []
for s in allstr:
ss = s.split('\t')
printf(ss)
flag = 0
str = ss[0] + ':'
for id,sss in enumerate(ss[2:]):
if not sss.replace('.', '').isdigit():
flag = 1
str = str + 'HW%d,'%(id+1)
if flag > 0:
infordim.append(str)
printf(infordim)
#------------------------------------------------------------
for s in infordim:
printf(s)
#------------------------------------------------------------
# END OF FILE : NOWORK.PY
#============================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
※ 总 结 ※
利用网络学堂下载的作业文件中包含学号的信息,通过Python程序,可以自动定位EXCEL表中记录表格,使得成绩记录精确可靠。
● 相关图表链接:
文章来源: zhuoqing.blog.csdn.net,作者:卓晴,版权归原作者所有,如需转载,请联系作者。
原文链接:zhuoqing.blog.csdn.net/article/details/122181741
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)