]> git.parisson.com Git - teleforma.git/commitdiff
exam: fix empty score when computing the mean value
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 13 Jul 2020 15:34:47 +0000 (17:34 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 13 Jul 2020 15:34:47 +0000 (17:34 +0200)
teleforma/exam/views.py

index 99cf014c3b69cc59310a438814ce2c9ad9445a44..82e0b6241c7d29636969271a09bdb381d9789e23 100755 (executable)
@@ -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()