diff options
-rw-r--r-- | stats/models.py | 28 | ||||
-rw-r--r-- | stats/templates/view_lesson_tracking.html | 59 | ||||
-rw-r--r-- | stats/test_models.py | 8 | ||||
-rw-r--r-- | stats/tests.py | 4 | ||||
-rw-r--r-- | stats/views.py | 25 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_added_modules.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_forum.html | 3 | ||||
-rw-r--r-- | yaksh/templates/yaksh/lessons_forum.html | 26 | ||||
-rw-r--r-- | yaksh/templates/yaksh/show_lesson_statistics.html | 6 | ||||
-rw-r--r-- | yaksh/templates/yaksh/sidebar.html | 18 | ||||
-rw-r--r-- | yaksh/templatetags/custom_filters.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 4 |
12 files changed, 146 insertions, 39 deletions
diff --git a/stats/models.py b/stats/models.py index 6774721..84ac7ae 100644 --- a/stats/models.py +++ b/stats/models.py @@ -24,6 +24,22 @@ def time_to_seconds(time): seconds=time.second).total_seconds() +class TrackLessonManager(models.Manager): + def get_percentage_data(self, tracked_lessons): + percentage_data = {"1": 0, "2": 0, "3": 0, "4": 0} + for tracked in tracked_lessons: + percent = tracked.get_percentage_complete() + if percent < 25: + percentage_data["1"] = percentage_data["1"] + 1 + elif percent >= 25 and percent < 50: + percentage_data["2"] = percentage_data["2"] + 1 + elif percent >= 50 and percent < 75: + percentage_data["3"] = percentage_data["3"] + 1 + elif percent >= 75: + percentage_data["4"] = percentage_data["4"] + 1 + return percentage_data + + class TrackLesson(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete=models.CASCADE) @@ -33,6 +49,8 @@ class TrackLesson(models.Model): creation_time = models.DateTimeField(auto_now_add=True) watched = models.BooleanField(default=False) + objects = TrackLessonManager() + class Meta: unique_together = ('user', 'course', 'lesson') @@ -41,12 +59,12 @@ class TrackLesson(models.Model): def get_current_time(self): if self.current_time == '00:00:00': - return 'just started' + return '00:00:00' return self.current_time def get_video_duration(self): if self.video_duration == '00:00:00': - return 'will be available after 25% completion' + return '00:00:00' return self.video_duration def set_current_time(self, ct): @@ -60,13 +78,13 @@ class TrackLesson(models.Model): ctime = self.current_time vduration = self.video_duration if ctime == '00:00:00' and vduration == '00:00:00': - return 'less than 25%' + return 0 duration = str_to_time(vduration) watch_time = str_to_time(ctime) duration_seconds = time_to_seconds(duration) watched_seconds = time_to_seconds(watch_time) percentage = round((watched_seconds / duration_seconds) * 100) - return 'approx {0} %'.format(percentage) + return percentage def get_last_access_time(self): lesson_logs = self.lessonlog_set @@ -81,7 +99,7 @@ class TrackLesson(models.Model): if ctime != '00:00:00' and vduration != '00:00:00': duration = str_to_time(vduration) watch_time = (str_to_datetime(ctime) + timezone.timedelta( - seconds=10)).time() + seconds=120)).time() self.watched = watch_time >= duration def get_watched(self): diff --git a/stats/templates/view_lesson_tracking.html b/stats/templates/view_lesson_tracking.html index d8d35c2..a9d3025 100644 --- a/stats/templates/view_lesson_tracking.html +++ b/stats/templates/view_lesson_tracking.html @@ -1,6 +1,6 @@ {% extends "manage.html" %} {% load static %} -{% block title %} Lesson Views {% endblock %} +{% block title %} Lesson Video Stats {% endblock %} {% block script %} <script type="text/javascript" src="{% static 'yaksh/js/jquery.tablesorter.min.js' %}"> </script> @@ -33,7 +33,58 @@ <br><br> {% include "yaksh/paginator.html" %} <br> - <h4><strong>{{total}} student(s) viewed this lesson</strong></h4> + <div class="row"> + <div class="col" id='barDiv1'></div> + <div class="col" id="barDiv2"></div> + <div class="col" id="barDiv3"></div> + </div> + <script type="text/javascript"> + var config = {responsive: true} + var data = [ + { + x: ["Completed", "Not Completed"], + y: ["{{completion.0}}", "{{completion.1}}"], + type: 'bar' + } + ]; + var layout = { + title: "Number of completions (Out of {{visits.2}})", + xaxis: {title: 'Completion status'}, + yaxis: {title: 'Count'}, + width: 400, + height: 400, + }; + Plotly.newPlot('barDiv1', data, layout, config); + var data = [ + { + x: ["Visited", "Not Visited"], + y: ["{{visits.0}}", "{{visits.1}}"], + type: 'bar' + } + ]; + var layout = { + title: "Number of visits (Out of {{visits.2}})", + xaxis: {title: 'Visit status'}, + yaxis: {title: 'Count'}, + width: 400, + height: 400, + }; + Plotly.newPlot('barDiv2', data, layout, config); + var x_data = ["0-25", "25-50", "50-75", "75-100"], y_data = []; + {% for i, j in percentage_data.items %} + y_data.push("{{j}}") + {% endfor %} + var data = [{x: x_data, y: y_data, type: 'bar'}]; + var layout = { + title: "Range wise completion (Out of {{total}})", + xaxis: {title: 'Percentage Range'}, + yaxis: {title: 'Count'}, + width: 400, + height: 400, + }; + Plotly.newPlot('barDiv3', data, layout, config); + </script> + <br> <table class="table table-responsive" id="stats-table"> <thead> <tr> @@ -57,13 +108,13 @@ <td>{{track.creation_time}}</td> <td>{{track.get_current_time}}</td> <td>{{track.get_video_duration}}</td> - <td>{{track.get_percentage_complete}}</td> + <td>{{track.get_percentage_complete}} %</td> <td> {% with track.get_watched as watched %} {% if watched %} <span class="badge-pill badge-success">{{watched}}</span> {% else %} - <span class="badge-pill badge-success">{{watched}}</span> + <span class="badge-pill badge-warning">{{watched}}</span> {% endif %} {% endwith %} </td> diff --git a/stats/test_models.py b/stats/test_models.py index 5506a64..7f84330 100644 --- a/stats/test_models.py +++ b/stats/test_models.py @@ -70,7 +70,7 @@ class TrackLessonTestCase(TestCase): def test_get_current_time(self): # Given tracker = self.tracker - expected_time = 'just started' + expected_time = '00:00:00' # When current_time = tracker.get_current_time() @@ -81,7 +81,7 @@ class TrackLessonTestCase(TestCase): def test_get_video_duration(self): # Given tracker = self.tracker - expected_duration = 'will be available after 25% completion' + expected_duration = '00:00:00' # When duration = tracker.get_video_duration() @@ -117,7 +117,7 @@ class TrackLessonTestCase(TestCase): def test_get_percentage_complete(self): # Given tracker = self.tracker - expected_percentage = 'less than 25%' + expected_percentage = 0 # When percentage = tracker.get_percentage_complete() @@ -126,7 +126,7 @@ class TrackLessonTestCase(TestCase): self.assertEqual(percentage, expected_percentage) # Given - expected_percentage = 'approx 75 %' + expected_percentage = 75 # When tracker.set_current_time('00:03:00') diff --git a/stats/tests.py b/stats/tests.py index c256feb..540ff4d 100644 --- a/stats/tests.py +++ b/stats/tests.py @@ -131,8 +131,8 @@ class TestTrackLesson(TestCase): self.assertEqual(response_data.get('total'), 1) expected_tracker = list(TrackLesson.objects.filter( user_id=self.student.id, course_id=self.course.id, - lesson_id=self.lesson.id).values_list("id", flat=True)) + lesson_id=self.lesson.id)) obtained_tracker = list(response_data.get( - 'objects').object_list.values_list("id", flat=True)) + 'objects').object_list) self.assertEqual(obtained_tracker, expected_tracker) 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) diff --git a/yaksh/templates/yaksh/course_added_modules.html b/yaksh/templates/yaksh/course_added_modules.html index 80d87c0..b0662dd 100644 --- a/yaksh/templates/yaksh/course_added_modules.html +++ b/yaksh/templates/yaksh/course_added_modules.html @@ -100,7 +100,7 @@ ---- {% else %} {% get_lesson_views course.id unit.lesson.id as views %} - {{views.0}} views out of {{views.1}} + {{views.0}} completed out of {{views.1}} {% endif %} </td> <td> diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index b98688b..b352654 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -5,7 +5,6 @@ {% endblock title %} {% block content %} <div id="wrapper" class="d-flex"> - {% include "yaksh/sidebar.html" %} <div class="container" id="page-content-wrapper"> <div> <h2><center>{{course.name}}</center></h2> @@ -69,6 +68,8 @@ </div> </div> <br> + {% include "yaksh/sidebar.html" %} + <br> {% with objects as posts %} {% if posts %} <div class="row justify-content-center"> diff --git a/yaksh/templates/yaksh/lessons_forum.html b/yaksh/templates/yaksh/lessons_forum.html index 58fb360..26825b9 100644 --- a/yaksh/templates/yaksh/lessons_forum.html +++ b/yaksh/templates/yaksh/lessons_forum.html @@ -5,8 +5,11 @@ {% endblock title %} {% block content %} <div id="wrapper" class="d-flex"> - {% include "yaksh/sidebar.html" %} <div class="container" id="page-content-wrapper"> + <div> + <h2><center>{{course.name}}</center></h2> + <center>Discussion Forum</center> + </div> <div class="d-flex p-2 bd-highlight"> <div class="col-md-4"> {% if moderator %} @@ -20,11 +23,24 @@ {% endif %} </div> </div> - {% if posts %} + {% if messages %} <div> - <h2><center>{{course.name}}</center></h2> - <center>Discussion Forum</center> - </div> + <center> + {% for message in messages %} + <div class="alert alert-dismissible alert-{{ message.tags }}"> + <button type="button" class="close" data-dismiss="alert"> + <i class="fa fa-close"></i> + </button> + <strong>{{ message }}</strong> + </div> + {% endfor %} + </center> + </div> + {% endif %} + <br> + {% include "yaksh/sidebar.html" %} + <br> + {% if posts %} <table class="table"> <thead class="thread-inverse"> <tr> diff --git a/yaksh/templates/yaksh/show_lesson_statistics.html b/yaksh/templates/yaksh/show_lesson_statistics.html index a7c2ebd..dfce52c 100644 --- a/yaksh/templates/yaksh/show_lesson_statistics.html +++ b/yaksh/templates/yaksh/show_lesson_statistics.html @@ -1,7 +1,7 @@ {% extends "manage.html" %} {% load static %} {% load custom_filters %} -{% block title %} Lesson Statistics {% endblock %} +{% block title %} Lesson Quiz Stats {% endblock %} {% block pagetitle %} Statistics for {{lesson}} {% endblock %} {% block script %} <script type="text/javascript" src="{% static 'yaksh/js/jquery.tablesorter.min.js' %}"> @@ -135,8 +135,8 @@ <div class="progress" style="width: 30%"> {% if percent %} <div class="progress-bar bg-success" role="progressbar" aria-valuenow="{{percent}}" - aria-valuemin="0" aria-valuemax="100" style="width:{{percent}}%"> - <b style="color: white;">{{percent}}%</b> + aria-valuemin="0" aria-valuemax="100" style="width:{{percent|floatformat}}%"> + <b style="color: white;">{{percent|floatformat}}%</b> </div> {% else %} <b style="color: black;">0%</b> diff --git a/yaksh/templates/yaksh/sidebar.html b/yaksh/templates/yaksh/sidebar.html index 7d0ac74..5808608 100644 --- a/yaksh/templates/yaksh/sidebar.html +++ b/yaksh/templates/yaksh/sidebar.html @@ -1,8 +1,16 @@ <!-- Sidebar --> -<div class="bg-light border-right" id="sidebar-wrapper"> - <div class="list-group list-group-flush"> - <a href="{% url 'yaksh:course_forum' course.id %}" class="list-group-item list-group-item-action {% if '/course_forum/' in request.path %}active{% endif %}">Course Forum</a> - <a href="{% url 'yaksh:lessons_forum' course.id %}" class="list-group-item list-group-item-action {% if '/lessons_forum/' in request.path %}active{% endif %}">Lessons Forum</a> - </div> +<div class="bg-light"> + <ul class="nav nav-pills"> + <li class="nav-item"> + <a href="{% url 'yaksh:course_forum' course.id %}" class="nav-link {% if '/course_forum/' in request.path %}active{% endif %}"> + Course Forum + </a> + </li> + <li class="nav-item"> + <a href="{% url 'yaksh:lessons_forum' course.id %}" class="nav-link {% if '/lessons_forum/' in request.path %}active{% endif %}"> + Lessons Forum + </a> + </li> + </ul> </div> <!-- /#sidebar-wrapper --> diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index 91681c2..7eba939 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -209,5 +209,5 @@ def get_tc_percent(tc_id, data): def get_lesson_views(course_id, lesson_id): course = Course.objects.get(id=course_id) return TrackLesson.objects.filter( - course_id=course_id, lesson_id=lesson_id + course_id=course_id, lesson_id=lesson_id, watched=True ).count(), course.students.count() diff --git a/yaksh/views.py b/yaksh/views.py index 95a7218..11a77b8 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3507,6 +3507,7 @@ def course_forum(request, course_id): new_post.target = course new_post.anonymous = request.POST.get('anonymous', '') == 'on' new_post.save() + messages.success(request, "Added post successfully") return redirect('yaksh:post_comments', course_id=course.id, uuid=new_post.uid) else: @@ -3565,6 +3566,7 @@ def post_comments(request, course_id, uuid): new_comment.post_field = post new_comment.anonymous = request.POST.get('anonymous', '') == 'on' new_comment.save() + messages.success(request, "Added comment successfully") return redirect(request.path_info) return render(request, 'yaksh/post_comments.html', { 'post': post, @@ -3589,6 +3591,7 @@ def hide_post(request, course_id, uuid): post.comment.active = False post.active = False post.save() + messages.success(request, "Post deleted successfully") return redirect('yaksh:course_forum', course_id) @@ -3606,6 +3609,7 @@ def hide_comment(request, course_id, uuid): post_uid = comment.post_field.uid comment.active = False comment.save() + messages.success(request, "Post comment deleted successfully") return redirect('yaksh:post_comments', course_id, post_uid) |