Skip to content

Commit be52683

Browse files
calculate band score
1 parent 89b48b7 commit be52683

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

classroom/business/all/band_score.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
BAND_SCORE_MAPPER = {
2+
40: 9,
3+
39: 9,
4+
38: 8.5,
5+
37: 8.5,
6+
36: 8,
7+
35: 8,
8+
34: 7.5,
9+
33: 7.5,
10+
32: 7,
11+
31: 7,
12+
30: 7,
13+
29: 6.5,
14+
28: 6.5,
15+
27: 6.5,
16+
26: 6,
17+
25: 6,
18+
24: 6,
19+
23: 6,
20+
22: 5.5,
21+
21: 5.5,
22+
20: 5.5,
23+
19: 5.5,
24+
18: 5,
25+
17: 5,
26+
16: 5,
27+
15: 5,
28+
14: 4.5,
29+
13: 4.5,
30+
12: 4,
31+
11: 4,
32+
10: 4,
33+
9: 3.5,
34+
8: 3.5,
35+
7: 3,
36+
6: 3,
37+
5: 2.5,
38+
4: 2.5,
39+
3: 2,
40+
2: 2,
41+
1: 1,
42+
0: 1,
43+
}

classroom/business/all/student_report.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from .band_score import BAND_SCORE_MAPPER
2+
3+
14
class ReadingReportMaker:
25
def __init__(self, classroom, student):
36
self.classroom = classroom
@@ -19,11 +22,8 @@ def make(self):
1922
report['passage_1'] = self.calculate_score(questions, answers, 1)
2023
report['passage_2'] = self.calculate_score(questions, answers, 2)
2124
report['passage_3'] = self.calculate_score(questions, answers, 3)
22-
report['band_score'] = (
23-
self.calculate_band(report['passage_1']) +
24-
self.calculate_band(report['passage_2']) +
25-
self.calculate_band(report['passage_3'])
26-
)
25+
report['total'] = report['passage_1'] + report['passage_2'] + report['passage_3']
26+
report['band_score'] = self.calculate_band(report['total'])
2727

2828
reports.append(report)
2929

@@ -56,15 +56,16 @@ def calculate_score(self, questions, answers, passage):
5656
score = 0
5757
for question in questions:
5858
answer = self.get_answer(answers, question)
59-
is_correct = question.check_answer(answer.content)
60-
if is_correct:
61-
score += 1
59+
if answer:
60+
is_correct = question.check_answer(answer.content)
61+
if is_correct:
62+
score += 1
6263

6364
return score
6465

6566
@staticmethod
6667
def calculate_band(score):
67-
pass
68+
return BAND_SCORE_MAPPER[score]
6869

6970
@staticmethod
7071
def get_answer(answers, question):

classroom/models/abstracts/question.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def check_answer(self, answer):
6666
answer = f' {answer} ' # Add 2 spaces to both side to help with regex matching
6767

6868
for correct_answer in possible_answers:
69-
regex = correct_answer
69+
regex = correct_answer.content
7070
if regex.startswith('('):
7171
regex = r'(?:' + regex[1:]
7272

classroom/serializers/classroom.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ class RemoveReadingExerciseSerializer(serializers.Serializer):
7272

7373
class StudentReadingReportSerializer(serializers.Serializer):
7474
student = serializers.IntegerField(write_only=True)
75+
exercise = serializers.CharField(read_only=True)
76+
passage_1 = serializers.IntegerField(read_only=True)
77+
passage_2 = serializers.IntegerField(read_only=True)
78+
passage_3 = serializers.IntegerField(read_only=True)
79+
total = serializers.IntegerField(read_only=True)
80+
band_score = serializers.FloatField(read_only=True)
81+
submitted = serializers.BooleanField(read_only=True)

classroom/views/classroom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ def student_reading_report(self, request, pk):
103103
student = get_object_or_404(User.students.all(), pk=serializer.validated_data['student'])
104104
report_maker = ReadingReportMaker(classroom, student)
105105
report = report_maker.make()
106-
return Response(report)
106+
serializer = self.get_serializer(instance=report, many=True)
107+
return Response(serializer.data)

0 commit comments

Comments
 (0)