summaryrefslogtreecommitdiff
path: root/stats/models.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2020-11-18 18:45:21 +0530
committerGitHub2020-11-18 18:45:21 +0530
commit544c796a8b55e742975c6714b5bc0208a198df95 (patch)
tree3d1a43b712b0bbae35df087360403118066193e0 /stats/models.py
parenta00348278009bcfdafaba9ba7e10383036b601f3 (diff)
parent5f02880d022053ed07ed218fd52d9e436f6455ee (diff)
downloadonline_test-544c796a8b55e742975c6714b5bc0208a198df95.tar.gz
online_test-544c796a8b55e742975c6714b5bc0208a198df95.tar.bz2
online_test-544c796a8b55e742975c6714b5bc0208a198df95.zip
Merge pull request #800 from adityacp/improve_video_tracking
Improve video tracking and lesson statistics
Diffstat (limited to 'stats/models.py')
-rw-r--r--stats/models.py16
1 files changed, 16 insertions, 0 deletions
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()}")