summaryrefslogtreecommitdiff
path: root/stats/models.py
diff options
context:
space:
mode:
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()}")