From bb960037685accde4ad561c7f46a00d0f2bfee1b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 13 Jul 2020 17:34:47 +0200 Subject: [PATCH] exam: fix empty score when computing the mean value --- teleforma/exam/views.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/teleforma/exam/views.py b/teleforma/exam/views.py index 99cf014c..82e0b624 100755 --- a/teleforma/exam/views.py +++ b/teleforma/exam/views.py @@ -30,7 +30,7 @@ class ScriptMixinView(View): courses = [ c for c in courses if c.has_exam_scripts ] courses = [ c for c in courses if c.is_for_period(self.period) ] return [ c.id for c in courses ] - + def get_context_data(self, **kwargs): context = super(ScriptMixinView, self).get_context_data(**kwargs) self.period = Period.objects.get(id=self.kwargs['period_id']) @@ -164,7 +164,7 @@ class ScriptsView(ScriptsListMixinView, ListView): if platform_only: QT &= Q(author__student__platform_only = int(platform_only)) return QT - + def get_base_queryset(self): QT = self.get_form_queryset() & Q(period_id=self.kwargs['period_id']) if self.status_filter: @@ -201,7 +201,7 @@ class ScriptsPendingView(ScriptsView): def get_queryset(self): qs = super(ScriptsPendingView, self).get_queryset() - + if self.request.GET.get('corrector') is None: user = self.request.user # Exclude status=2 but not author=user @@ -218,7 +218,7 @@ class ScriptsPendingView(ScriptsView): class ScriptsTreatedView(ScriptsView): status_filter = (4, 5 ,7) - + def get_context_data(self, **kwargs): context = super(ScriptsTreatedView, self).get_context_data(**kwargs) period = Period.objects.get(id=self.kwargs['period_id']) @@ -259,7 +259,7 @@ class ScriptCreateView(ScriptMixinView, CreateView): messages.error(self.request, _("There was a problem with your submission. Please try again, later if possible.")) return super(ScriptCreateView, self).form_invalid(form) - def get_context_data(self, **kwargs): + def get_context_data(self, **kwargs): context = super(ScriptCreateView, self).get_context_data(**kwargs) context['create_fields'] = ['course', 'session', 'file' ] context['form'].fields['course'].queryset = context['courses'] @@ -296,7 +296,7 @@ class QuotasView(ListView): class ScriptsScoreAllView(ScriptsTreatedView): perso_name = 'Moyenne personnelle' - + template_name='exam/scores.html' def score_data_setup(self, x, y): @@ -329,7 +329,7 @@ class ScriptsScoreAllView(ScriptsTreatedView): context = super(ScriptsScoreAllView, self).get_context_data(**kwargs) user = self.request.user period_id = self.kwargs['period_id'] - + if 'course_id' in self.kwargs: course = Course.objects.get(id=self.kwargs['course_id']) else: @@ -350,7 +350,7 @@ class ScriptsScoreAllView(ScriptsTreatedView): if course: scripts = scripts.filter(course=course) all_scripts = all_scripts.filter(course=course) - + sessions = set() scores = [] @@ -363,19 +363,20 @@ class ScriptsScoreAllView(ScriptsTreatedView): res = { s: [] for s in sessions } for script in scripts.values('score', 'session'): if script['session'] in res: - res[script['session']].append(script['score']) + if script['score']: + res[script['session']].append(script['score']) return [ np.mean(res[s]) for s in sessions ] - + if not staff_or_teacher: scores.append({'name': self.perso_name, 'data': by_session(scripts)}) - + scores.append({'name': 'Moyenne generale', 'data': by_session(all_scripts)}) for script_type in ScriptType.objects.all(): scripts = all_scripts.filter(type=script_type) - scores.append({'name': 'Moyenne ' + script_type.name, + scores.append({'name': 'Moyenne ' + script_type.name, 'data': by_session(scripts)}) context['data'] = self.score_data_setup(sessions_x, scores) @@ -436,19 +437,19 @@ class MassScoreCreateView(ScoreCreateView): session = session, course_id = course_id).values('author_id') scripts = set([s['author_id'] for s in scripts]) - - students = students.exclude(user_id__in = scripts) + + students = students.exclude(user_id__in = scripts) res = [] for student in students: user = student.user # FIXME : Filter those who access the course, but that's very slow, - # so I disable it for now - we'll see if we can do that faster later + # so I disable it for now - we'll see if we can do that faster later # courses = get_courses(user) # if course_id in [ c['course'].id for c in courses ]: res.append({ 'id': user.id, 'name': str(user) }) - + return res def form_valid(self, form): @@ -477,7 +478,7 @@ class MassScoreCreateView(ScoreCreateView): session = session, author_id = student, type = sc_type, - score = score, + score = score, status = 7) obj.save() -- 2.39.5