@@ -16,13 +16,22 @@ def make(self):
16
16
17
17
if submission :
18
18
report ['submitted' ] = True
19
- questions = exercise .questions .all ()
19
+ questions = exercise .questions .all (). prefetch_related ( 'answers' )
20
20
answers = submission .answers .all ()
21
21
22
- report ['passage_1' ] = self .calculate_score (questions , answers , 1 )
23
- report ['passage_2' ] = self .calculate_score (questions , answers , 2 )
24
- report ['passage_3' ] = self .calculate_score (questions , answers , 3 )
25
- report ['total' ] = report ['passage_1' ] + report ['passage_2' ] + report ['passage_3' ]
22
+ passage_1_report = self .passage_report (questions , answers , 1 )
23
+ passage_2_report = self .passage_report (questions , answers , 2 )
24
+ passage_3_report = self .passage_report (questions , answers , 3 )
25
+
26
+ report ['passage_1_total' ], report ['passage_1_detail' ] = passage_1_report
27
+ report ['passage_2_total' ], report ['passage_2_detail' ] = passage_2_report
28
+ report ['passage_3_total' ], report ['passage_3_detail' ] = passage_3_report
29
+
30
+ report ['total' ] = (
31
+ report ['passage_1_total' ] +
32
+ report ['passage_2_total' ] +
33
+ report ['passage_3_total' ]
34
+ )
26
35
report ['band_score' ] = self .calculate_band (report ['total' ])
27
36
28
37
reports .append (report )
@@ -33,35 +42,58 @@ def make(self):
33
42
def new_report (exercise ):
34
43
return {
35
44
'exercise' : exercise .identifier ,
36
- 'passage_1' : 0 ,
37
- 'passage_2' : 0 ,
38
- 'passage_3' : 0 ,
45
+ 'passage_1_total' : 0 ,
46
+ 'passage_2_total' : 0 ,
47
+ 'passage_3_total' : 0 ,
48
+ 'passage_1_detail' : [],
49
+ 'passage_2_detail' : [],
50
+ 'passage_3_detail' : [],
39
51
'total' : 0 ,
40
52
'band_score' : 1 ,
41
53
'submitted' : False ,
42
54
}
43
55
56
+ @staticmethod
57
+ def new_detail ():
58
+ return {
59
+ 'question_number' : None ,
60
+ 'submitted_answer' : '' ,
61
+ 'possible_answers' : [],
62
+ 'is_correct' : False ,
63
+ }
64
+
44
65
def get_exercises (self ):
45
66
return self .classroom .reading_exercises .all ().prefetch_related ('questions' )
46
67
47
68
def get_submission (self , exercise ):
48
69
return exercise .submissions .filter (submitter = self .student ).prefetch_related ('answers' ).first ()
49
70
50
- def calculate_score (self , questions , answers , passage ):
71
+ def passage_report (self , questions , answers , passage ):
51
72
questions = filter (
52
73
lambda question : getattr (question , f'is_passage_{ passage } ' )(),
53
74
questions
54
75
)
55
76
56
77
score = 0
78
+ details = []
57
79
for question in questions :
80
+ detail = self .new_detail ()
58
81
answer = self .get_answer (answers , question )
82
+
83
+ detail ['question_number' ] = question .number
84
+ detail ['possible_answers' ] = question .get_answers_content ()
85
+
59
86
if answer :
60
87
is_correct = question .check_answer (answer .content )
61
88
if is_correct :
62
89
score += 1
63
90
64
- return score
91
+ detail ['submitted_answer' ] = answer .content
92
+ detail ['is_correct' ] = is_correct
93
+
94
+ details .append (detail )
95
+
96
+ return score , details
65
97
66
98
@staticmethod
67
99
def calculate_band (score ):
0 commit comments