diff options
author | ankitjavalkar | 2020-11-04 18:00:56 +0530 |
---|---|---|
committer | GitHub | 2020-11-04 18:00:56 +0530 |
commit | 2371058b9cf8fd953e8e089ac51702475a102ff7 (patch) | |
tree | 1764959aca48f835be56c0819cddd286aeb8b4df /yaksh/models.py | |
parent | 81f96a24954d375ab32ab8dfb1ee8aba299655c6 (diff) | |
parent | aef2589eadaf7f3252e281286ab1bb83e690ba6a (diff) | |
download | online_test-2371058b9cf8fd953e8e089ac51702475a102ff7.tar.gz online_test-2371058b9cf8fd953e8e089ac51702475a102ff7.tar.bz2 online_test-2371058b9cf8fd953e8e089ac51702475a102ff7.zip |
Merge pull request #784 from adityacp/improve_lesson_stats
Improve lesson statistics
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index cca2a2c..2a06cc8 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -25,6 +25,7 @@ import zipfile import tempfile from textwrap import dedent from ast import literal_eval +import pandas as pd # Django Imports from django.db import models @@ -2821,19 +2822,50 @@ class TOCManager(models.Manager): data = {} for toc in contents: data[toc] = LessonQuizAnswer.objects.filter( - toc_id=toc.id).values_list("toc_id").distinct().count() + toc_id=toc.id).values_list( + "student_id", flat=True).distinct().count() return data def get_question_stats(self, toc_id): answers = LessonQuizAnswer.objects.get_queryset().filter( toc_id=toc_id).order_by('id') - question = answers.first().toc.content_object - answers = answers.values( - "student__first_name", "student__last_name", "student__email", - "student_id", "toc_id" - ).distinct() + question = TableOfContents.objects.get(id=toc_id).content_object + if answers.exists(): + answers = answers.values( + "student__first_name", "student__last_name", "student__email", + "student_id", "toc_id" + ) + df = pd.DataFrame(answers) + answers = df.drop_duplicates().to_dict(orient='records') return question, answers + def get_per_tc_ans(self, toc_id, question_type, is_percent=True): + answers = LessonQuizAnswer.objects.filter(toc_id=toc_id).values( + "student_id", "answer__answer" + ).order_by("id") + data = None + if answers.exists(): + df = pd.DataFrame(answers) + grp = df.groupby(["student_id"]).tail(1) + total_count = grp.count().answer__answer + data = grp.groupby(["answer__answer"]).count().to_dict().get( + "student_id") + if question_type == "mcc": + tc_ids = [] + mydata = {} + for i in data.keys(): + tc_ids.extend(literal_eval(i)) + for j in tc_ids: + if j not in mydata: + mydata[j] = 1 + else: + mydata[j] +=1 + data = mydata.copy() + if is_percent: + for key, value in data.items(): + data[key] = (value/total_count)*100 + return data, total_count + def get_answer(self, toc_id, user_id): submission = LessonQuizAnswer.objects.filter( toc_id=toc_id, student_id=user_id).last() |