diff options
author | adityacp | 2020-09-14 16:04:35 +0530 |
---|---|---|
committer | adityacp | 2020-09-14 16:04:35 +0530 |
commit | 98908b86a94da4a2552564e057457c48b46d4ac3 (patch) | |
tree | 000d9ed201008020d057ca7b0bdf59514e7f8c2f /yaksh/models.py | |
parent | b1d2b88746fc670d7362f9b4d175d5e570f3ac77 (diff) | |
download | online_test-98908b86a94da4a2552564e057457c48b46d4ac3.tar.gz online_test-98908b86a94da4a2552564e057457c48b46d4ac3.tar.bz2 online_test-98908b86a94da4a2552564e057457c48b46d4ac3.zip |
Show lesson quiz statistics
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 19f3302..9f8c634 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2748,13 +2748,47 @@ class Comment(ForumBase): class TOCManager(models.Manager): def get_data(self, course_id, lesson_id): - toc = TableOfContents.objects.filter( + contents = TableOfContents.objects.filter( course_id=course_id, lesson_id=lesson_id, content__in=[2, 3, 4] ) - answers = LessonQuizAnswer.objects.select_related("toc").filter( - toc__course_id=course_id, toc__lesson_id=lesson_id - ) - return answers + data = {} + for toc in contents: + data[toc] = LessonQuizAnswer.objects.filter( + toc_id=toc.id).values_list("toc_id").distinct().count() + return data + + def get_question_stats(self, toc_id): + answers = LessonQuizAnswer.objects.filter( + toc_id=toc_id) + question = answers.first().toc.content_object + answers = answers.values( + "student__first_name", "student__last_name", "student__email", + "student_id", "toc_id" + ).distinct() + return question, answers + + def get_answer(self, toc_id, user_id): + submission = LessonQuizAnswer.objects.filter( + toc_id=toc_id, student_id=user_id).last() + question = submission.toc.content_object + attempted_answer = submission.answer + if question.type == "mcq": + submitted_answer = literal_eval(attempted_answer.answer) + answers = [ + tc.options + for tc in question.get_test_cases(id=submitted_answer) + ] + answer = ",".join(answers) + elif question.type == "mcc": + submitted_answer = literal_eval(attempted_answer.answer) + answers = [ + tc.options + for tc in question.get_test_cases(id__in=submitted_answer) + ] + answer = ",".join(answers) + else: + answer = attempted_answer.answer + return answer, attempted_answer.correct class TableOfContents(models.Model): |