summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authoradityacp2020-10-24 16:42:10 +0530
committeradityacp2020-10-24 16:42:10 +0530
commit8747c671d87418be83c8c6b9849e2962cdbb0715 (patch)
tree73027483efd30183390e3d4f06a87634993ce01c /yaksh/models.py
parent430c8d1480d897e9fc0dc328bad173642d0a2946 (diff)
downloadonline_test-8747c671d87418be83c8c6b9849e2962cdbb0715.tar.gz
online_test-8747c671d87418be83c8c6b9849e2962cdbb0715.tar.bz2
online_test-8747c671d87418be83c8c6b9849e2962cdbb0715.zip
Improve lesson statistics
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py44
1 files changed, 38 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index da2327c..932e38c 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
@@ -2812,19 +2813,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()