From fa8020b9f39b4e75a0a5d8b26653cc61cb9ae981 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 27 Jan 2021 16:36:51 +0530 Subject: Refactor monitor for a quiz --- yaksh/models.py | 19 +++++++- yaksh/templates/yaksh/grade_user.html | 4 +- yaksh/templates/yaksh/monitor.html | 88 +++++++++++++++++++---------------- yaksh/templatetags/custom_filters.py | 3 ++ yaksh/test_views.py | 3 -- yaksh/views.py | 71 +++++++++++++--------------- 6 files changed, 103 insertions(+), 85 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index bbb6900..662a8b4 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1953,6 +1953,12 @@ class QuestionPaper(models.Model): list(self.random_questions.all()) return len(questions) > 0 + def get_questions_count(self): + que_count = self.fixed_questions.count() + for r_set in self.random_questions.all(): + que_count += r_set.num_questions + return que_count + def __str__(self): return "Question Paper for " + self.quiz.description @@ -2214,6 +2220,17 @@ class AnswerPaperManager(models.Manager): user.pop("id") user["total_marks"] = user_marks + def get_questions_attempted(self, answerpaper_ids): + answers = Answer.objects.filter( + answerpaper__id__in=answerpaper_ids + ).values("question_id", "answerpaper__id") + df = pd.DataFrame(answers) + answerpapers = df.groupby("answerpaper__id") + question_attempted = {} + for ap in answerpapers: + question_attempted[ap[0]] = len(ap[1]["question_id"].unique()) + return question_attempted + ############################################################################### class AnswerPaper(models.Model): @@ -2472,7 +2489,7 @@ class AnswerPaper(models.Model): """ q_a = {} for question in self.questions.all(): - answers = question.answer_set.filter(answerpaper=self) + answers = question.answer_set.filter(answerpaper=self).distinct() if not answers.exists(): q_a[question] = [None, 0.0] continue diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index 86b7c47..4e1db2b 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -2,9 +2,9 @@ {% load custom_filters %} {% load static %} -{% block title %} Grader {% endblock %} +{% block title %} Quizzes {% endblock %} -{% block pagetitle %} Grader {% endblock pagetitle %} +{% block pagetitle %} Quizzes {% endblock pagetitle %} {% block script %}