-
Notifications
You must be signed in to change notification settings - Fork 0
/
handback.py
106 lines (91 loc) · 2.66 KB
/
handback.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
import html_writer as HTML
import csv
prefix="CPSC310-2018W1-HB-"
dash="-"
extension=".html"
path='handback-files/'
path_to_pdf="https://www.ugrad.cs.ubc.ca/~cs310/handback/index2.php?file=CPSC310-2018WT1-MT1/CPSC310-2018WT1-MT1"
pdf_extension=".pdf"
snum_to_csid={}
snum_to_midterm={}
snum_to_answers={}
snum_to_grades={}
snum_to_key={}
testlength=50
right="E0E9CF"
wrong="pink"
rightScore='2'
wrongScore='-1'
blankScore='BLANK'
with open('totals.csv', 'rb') as recfile:
recfile_reader = csv.reader(recfile)
headerrow=None
for row in recfile_reader:
if not headerrow:
headerrow = row
else:
snum=row[0]
csid=row[1]
midterm=row[3]
snum_to_midterm[snum]=midterm
snum_to_csid[snum]=csid
with open('realanswers.csv', 'rb') as recfile:
recfile_reader = csv.reader(recfile)
headerrow=None
for row in recfile_reader:
if not headerrow:
headerrow = row
else:
snum=row[0]
key=row[1]
answers=row[2:]
snum_to_key[snum]=key
snum_to_answers[snum]=answers
with open('grades.csv', 'rb') as recfile:
recfile_reader = csv.reader(recfile)
headerrow=None
for row in recfile_reader:
if not headerrow:
headerrow = row
else:
snum=row[0]
grades=row[4:]
snum_to_grades[snum]=grades
def writeMTResultsTable(start,end):
handback.startTableRow()
for i in range(start,end):
handback.writeCell(i+1)
handback.endTableRow()
handback.startTableRow()
for i in range(start,end):
color='white'
if grades[i]==rightScore:
color=right
if grades[i]==wrongScore:
color=wrong
if answers[i]==blankScore:
answers[i]=""
color='white'
handback.writeColorCell(answers[i],color)
handback.endTableRow()
for snum in snum_to_csid:
csid = snum_to_csid[snum]
midterm = snum_to_midterm[snum]
answers = snum_to_answers[snum]
grades = snum_to_grades[snum]
key = snum_to_key[snum]
handback=HTML.Writer(path+prefix+csid+dash+snum+extension)
handback.startTable()
handback.writeTableTitle(csid+" : "+snum+"<h1>",1)
handback.startTableRow()
handback.writeCell("Midterm grade: "+str(midterm)+"/"+str(testlength*2)+''
# 'https://www.ugrad.cs.ubc.ca/~cs410/handback/index2.php?file=CPSC410-2018WT1-MT1/CPSC410-2018WT1-MT1-63522163-ebani.pdf'
' <br/> <a href="https://www.ugrad.cs.ubc.ca/~cs310/handback/index2.php">Your scanned answer sheet</a>'
' | <a href="https://docs.google.com/spreadsheets/d/1ULfBdS4V4hgD1aHsHl0_8fky9shY3kdYHEY1QWYkQ9w/edit?usp=sharing">Grading key</a>'
' <br/> Your exam version was: '+key+' -- Please look in the correct column for question numbers!!')
handback.endTableRow()
handback.endTable()
handback.startTable()
writeMTResultsTable(0,testlength/2)
writeMTResultsTable(testlength/2,testlength)
handback.endTable()