-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade.py
199 lines (158 loc) · 4.51 KB
/
grade.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import csv
def myprint(x):
print x
solutions={}
students={}
# score for a right answer
right=2
# score for a freebie
freebie=2
# score for a wrong answer
wrong=-1
# score for a blank answer
blank=0
# number of questions
testlength=50
# number of points to adjust the exam (raw score)
gradeadjustment=0
# if points don't roll over, specify question boundary
# start at 1, end at n+1
questionbounds = {
'A':[1,5,8,12,16,19,23,27,31,37,42,47,51],
'B':[1,6,11,15,19,22,26,30,34,40,44,47,51],
'X':[1,5,8,12,16,19,23,27,31,37,42,47,51]
}
# list of questions to skip grading (aka pretend they don't exist)
skipgrades={
'A':[37, 41],
'B':[1, 5],
'X':[37, 41]
}
SNUMtoCSID={}
SNUMtoName={}
# get classlist (change XXX to you're corse number e.g., 310):
# ssh remote.cs.ubc.ca '/cs/local/bin/classlist -T -L -f "\"%LN, %FN\",%SN,%ACCT" XXX' > classlist.csv
with open("classlist.csv",'rb') as infile:
csv_reader = csv.reader(infile)
header=None
for row in csv_reader:
# print "grading key is: "+str(row)
if not header:
header = row
# print "header is: "+str(row)
if not row[0] in solutions:
SNUMtoCSID[row[1]] = row[2]
SNUMtoName[row[1]] = row[0]
#rubric schema: rubricID , 1...n
with open("rubricAB.csv",'rU') as infile:
csv_reader = csv.reader(infile)
header=None
for row in csv_reader:
print "grading key is: "+str(row)
if not header:
header = row
print "rubric header is: "+str(row)
if not row[0] in solutions:
solutions[row[0]] = row[1:]
#print "all solutions is: "+str(solutions)
answers=[]
with open("realanswers.csv",'rU') as infile:
csv_reader = csv.reader(infile)
header=None
for row in csv_reader:
if not header:
header = row
print "answers header is: "+str(row)
else:
answers.append(row)
grades=[]
for answer in answers:
student_rec = []
student_rec.append(answer[0]) #keep track of their SNUM
student_rec.append(answer[1]) #keep track of their key
print "Grading student: ",answer
key = solutions[answer[1]]
sanswer = answer[2:]
print "Comparing against "+str(answer[1])+":"+str(key)
for i,(k,a) in enumerate(zip(key,sanswer)):
if i+1 in skipgrades[answer[1]]:
student_rec.append(freebie) # the answer is a freebie
print ">>>>>>>>>>>SKIPPED"
elif k=="x":
student_rec.append(freebie) # the answer is a freebie (x in sheet instead of in freebie list)
elif a == "BLANK":
student_rec.append(blank) # the answer is blank
elif k==a:
student_rec.append(right) # the answer is right
else:
student_rec.append(wrong) # the answer is wrong
grades.append(student_rec)
for grade in grades:
print grade
marks = []
for grade in grades:
student_mark = []
key=grade[1]
snum=grade[0]
student_mark.append(snum)
student_mark.append(key)
print grade
bounds=questionbounds[grade[1]]
sgrades=grade[2:]
print "len sgrades"
print len(sgrades)
for i in range(0,len(bounds)):
print "bounds index is: "+str(i)+" at question "+str(bounds[i])
if bounds[i]>=testlength:
break
# print "question is: ",question
qmark = 0
for j in range(bounds[i],bounds[i+1]):
qmark = qmark+sgrades[j-1] #question bounds are indexed from 1 so must subtract 1
print j
print "Qmark: ",qmark
if qmark<0:
qmark=0
student_mark.append(qmark)
marks.append(student_mark)
for mark in marks:
print mark
totals = []
the_total=0
for mark in marks:
student_total=[]
student_total.append(mark[0])
sum=0
for i in range(2,len(mark)):
sum=sum+mark[i]
student_total.append(sum+gradeadjustment)
totals.append(student_total)
the_total=the_total+float(sum)
# print "the total: ", the_total
def cvsexport(name,records,header):
with open(name,'wb') as out_file:
csvwriter = csv.writer(out_file)
csvwriter.writerow(header)
for i in range(0,len(grades)):
outrow=[]
outrow.append(records[i][0])
outrow.append(SNUMtoCSID[records[i][0]])
outrow.append(SNUMtoName[records[i][0]])
outrow=outrow+records[i][1:]
# csvwriter.writerow(records[i])
csvwriter.writerow(outrow)
cvsexport('totals.csv',totals,["SNUM","CSID","Name","Grade"])
marksheader=[i for i in range(0,len(marks[0]))]
cvsexport('qmarks.csv',marks,["SNUM","CSID","Name","Key"]+marksheader)
questionsheader=[i for i in range(1,testlength)]
cvsexport('grades.csv',grades,["SNUM","CSID","Name","Key"]+questionsheader)
total=0
for t in totals:
total += t[1]
numerator=total/len(totals)
denominator=testlength*right
#print "total: ",str(total)
#print "totals: ",str(len(totals))
#print "numerator: ",str(numerator)
#print "denominator: ",str(denominator)
print "AVERAGE: ",str( (float(numerator)/denominator) * 100)