-
Notifications
You must be signed in to change notification settings - Fork 1
/
grade.py
64 lines (54 loc) · 1.59 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
"""Grading logic modeled after April King's Mozilla Web Observatory."""
from __future__ import division
class Grade(object):
def __init__(self):
self.grade_chart = {
100: 'A+',
95: 'A',
90: 'A',
85: 'A-',
80: 'B+',
75: 'B',
70: 'B',
65: 'B-',
60: 'C+',
55: 'C',
50: 'C',
45: 'C-',
40: 'D+',
35: 'D',
30: 'D',
25: 'D-',
20: 'F',
15: 'F',
10: 'F',
5: 'F',
0: 'F'
}
def get_grade(self, scored_test):
total_score = self._total_score(scored_test)
# Round up score to the nearest multiplier of 5
if total_score > 0:
total_score = int(round(total_score / 5.0) * 5.0)
else:
total_score = 0
# Score against the above grade chart
grade = self.grade_chart[total_score]
# Return
return {'score': total_score, 'grade': grade}
def _total_score(self, scored_test):
"""Returns total score as a percentage."""
score = 0
possible_points = 0
for k, v in scored_test.iteritems():
if 'check' in k:
score = score + v['score']
possible_points = possible_points + v['score_possible']
percentage_complete = (
int(
round(
float(int(score) / int(possible_points) * 100)
)
)
)
return percentage_complete