diff options
author | adityacp | 2020-12-03 14:32:15 +0530 |
---|---|---|
committer | adityacp | 2020-12-03 14:32:15 +0530 |
commit | e461b7c71d3d33f7e1cde4415ae35733078f4070 (patch) | |
tree | 8c193ad48b882cae31c32501a7a197f2df083b30 /stats/views.py | |
parent | 3a442d0142aac2bb6f1d5379e1d533b9b8fc6da6 (diff) | |
download | online_test-e461b7c71d3d33f7e1cde4415ae35733078f4070.tar.gz online_test-e461b7c71d3d33f7e1cde4415ae35733078f4070.tar.bz2 online_test-e461b7c71d3d33f7e1cde4415ae35733078f4070.zip |
Show graphs for the lesson video statistics
Diffstat (limited to 'stats/views.py')
-rw-r--r-- | stats/views.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/stats/views.py b/stats/views.py index 53b7cf7..a5cdeb7 100644 --- a/stats/views.py +++ b/stats/views.py @@ -27,14 +27,14 @@ def add_tracker(request, tracker_id): if current_time: track.set_current_time(current_time) track.video_duration = video_duration - LessonLog.objects.create( - track_id=track.id, current_time=current_time, - last_access_time=timezone.now() - ) track.save() if not track.watched: track.set_watched() track.save() + LessonLog.objects.create( + track_id=track.id, current_time=current_time, + last_access_time=timezone.now() + ) success = True else: success = False @@ -46,16 +46,25 @@ def add_tracker(request, tracker_id): @email_verified def view_lesson_watch_stats(request, course_id, lesson_id): user = request.user - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404( + Course.objects.prefetch_related("students"), id=course_id + ) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') trackings = TrackLesson.objects.get_queryset().filter( course_id=course_id, lesson_id=lesson_id ).order_by("id") - total = trackings.count() + percentage_data = TrackLesson.objects.get_percentage_data(trackings) + visited = trackings.count() + completed = trackings.filter(watched=True).count() + students_total = course.students.count() paginator = Paginator(trackings, 30) page = request.GET.get('page') trackings = paginator.get_page(page) - context = {'objects': trackings, 'total': total, 'course_id': course_id, - 'lesson_id': lesson_id} + context = { + 'objects': trackings, 'total': visited, 'course_id': course_id, + 'lesson_id': lesson_id, "percentage_data": percentage_data, + 'completion': [completed, students_total-completed, students_total], + 'visits': [visited, students_total-visited, students_total] + } return render(request, 'view_lesson_tracking.html', context) |