From 5f02880d022053ed07ed218fd52d9e436f6455ee Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 16 Nov 2020 16:54:07 +0530 Subject: Change stats and yaksh - Show total visits per student in lesson statistics - Remove settimeout ajax calls for tracking video positions - Show initial views per lesson in the course modules section --- stats/models.py | 16 +++++++++++++ stats/templates/view_lesson_tracking.html | 39 ++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 13 deletions(-) (limited to 'stats') diff --git a/stats/models.py b/stats/models.py index 0200a80..56c7f0d 100644 --- a/stats/models.py +++ b/stats/models.py @@ -1,7 +1,11 @@ +# Python Imports +import pandas as pd + # Django Imports from django.db import models from django.utils import timezone from django.contrib.auth.models import User +from django.db.models import F # Local Imports from yaksh.models import Course, Lesson @@ -93,6 +97,18 @@ class TrackLesson(models.Model): return str(timezone.timedelta(seconds=total_duration)) return self.get_current_time() + def get_no_of_vists(self): + lesson_logs = self.lessonlog_set.values("last_access_time").annotate( + visits=F('last_access_time') + ) + df = pd.DataFrame(lesson_logs) + visits = 1 + if not df.empty: + visits = df.groupby( + [df['visits'].dt.date] + ).first().count()['visits'] + return visits + def __str__(self): return (f"Track {self.lesson} in {self.course} " f"for {self.user.get_full_name()}") diff --git a/stats/templates/view_lesson_tracking.html b/stats/templates/view_lesson_tracking.html index ef5c9ae..d8d35c2 100644 --- a/stats/templates/view_lesson_tracking.html +++ b/stats/templates/view_lesson_tracking.html @@ -5,26 +5,29 @@ {% endblock %} {% block content %} -