Skip to content

Commit 6f77776

Browse files
committed
Split student_statistics into two functions
1 parent 98b83bf commit 6f77776

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

web/courses/models.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,7 @@ def results_archive(self, user):
309309
files.append((spreadsheet_filename, spreadsheet_contents))
310310
return archive_name, files
311311

312-
def student_statistics(self, student=None):
313-
if student is None:
314-
students = self.course.observed_students()
315-
parts = Part.objects.filter(problem__problem_set=self)
316-
else:
317-
students = User.objects.filter(id=student.id)
318-
parts = Part.objects.filter(
319-
problem__problem_set=self, problem__visible=True
320-
)
321-
outcomes = Outcome.group_dict(parts, students, ("id",), ())
312+
def outcomes_statistics(self, outcomes):
322313
statistics = []
323314
for problem in self.problems.prefetch_related("parts"):
324315
parts = []
@@ -341,6 +332,18 @@ def student_statistics(self, student=None):
341332
)
342333
return statistics
343334

335+
def single_student_statistics(self, student):
336+
students = User.objects.filter(id=student.id)
337+
parts = Part.objects.filter(problem__problem_set=self, problem__visible=True)
338+
outcomes = Outcome.group_dict(parts, students, ("id",), ())
339+
return self.outcomes_statistics(outcomes)
340+
341+
def all_students_statistics(self):
342+
students = self.course.observed_students()
343+
parts = Part.objects.filter(problem__problem_set=self)
344+
outcomes = Outcome.group_dict(parts, students, ("id",), ())
345+
return self.outcomes_statistics(outcomes)
346+
344347
def toggle_visible(self):
345348
self.visible = not self.visible
346349
self.save()

web/courses/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ def problem_set_detail(request, problem_set_pk):
103103
part__problem__problem_set=problem_set, part__problem__visible=True
104104
)
105105
if request.user.is_teacher(problem_set.course):
106-
student_statistics = problem_set.student_statistics()
106+
student_statistics = problem_set.all_students_statistics()
107107
else:
108-
user_attempts = user_attempts.filter(part__problem__visible=True)
109-
student_statistics = problem_set.student_statistics(student=request.user)
108+
student_statistics = problem_set.single_student_statistics(request.user)
110109
valid_parts_ids = user_attempts.filter(valid=True).values_list("part_id", flat=True)
111110
invalid_parts_ids = user_attempts.filter(valid=False).values_list(
112111
"part_id", flat=True

0 commit comments

Comments
 (0)