Commit 5b858ddebff6e23959bb019c9945c991fbce3feb
1 parent
431b542e
Exists in
master
and in
3 other branches
finished variable 24 to 31
Showing
1 changed file
with
30 additions
and
3 deletions
Show diff stats
api/views.py
... | ... | @@ -9,6 +9,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin |
9 | 9 | from datetime import datetime, date |
10 | 10 | from subjects.models import Subject |
11 | 11 | |
12 | +from log.models import Log | |
13 | + | |
12 | 14 | class ReportView(LoginRequiredMixin, generic.TemplateView): |
13 | 15 | template_name = "api/report.html" |
14 | 16 | |
... | ... | @@ -37,9 +39,11 @@ class ReportView(LoginRequiredMixin, generic.TemplateView): |
37 | 39 | interactions['init_date'] = init_date |
38 | 40 | interactions['end_date'] = end_date |
39 | 41 | |
42 | + help_posts_made_by_user = SubjectPost.objects.filter(action="help",space__id=subject.id, user=student, | |
43 | + create_date__range=(init_date, end_date)) | |
44 | + | |
40 | 45 | #number of help posts created by the student |
41 | - interactions['doubts_count'] = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
42 | - space__id=subject_id, user=student).count() | |
46 | + interactions['doubts_count'] = help_posts_made_by_user.count() | |
43 | 47 | |
44 | 48 | help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), |
45 | 49 | space__id=subject_id) |
... | ... | @@ -75,15 +79,38 @@ class ReportView(LoginRequiredMixin, generic.TemplateView): |
75 | 79 | #number of help posts created by the user others students commented on |
76 | 80 | interactions['help_posts_commented_by_others'] = help_posts.filter(user=student, id__in = help_posts_ids).count() |
77 | 81 | |
78 | - | |
79 | 82 | #Number of student visualizations on the mural of the subject |
80 | 83 | interactions['mural_visualizations_count'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), |
81 | 84 | user = student).count() |
82 | 85 | |
83 | 86 | |
87 | + #VAR20 - number of access to mural between 6 a.m to 12a.m. | |
88 | + interactions['access_subject_between_6_to_12_am'] = Log.objects.filter(action="access", resource="subject", | |
89 | + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() | |
90 | + | |
91 | + #VAR21 - number of access to mural between 6 a.m to 12a.m. | |
92 | + interactions['access_subject_between_0_to_6_pm'] = Log.objects.filter(action="access", resource="subject", | |
93 | + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (11, 17)).count() | |
94 | + #VAR22 | |
95 | + interactions['access_subject_between_6_to_12_pm'] = Log.objects.filter(action="access", resource="subject", | |
96 | + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (17, 23)).count() | |
97 | + | |
98 | + #VAR23 | |
99 | + interactions['access_subject_between_0_to_6_am'] = Log.objects.filter(action="access", resource="subject", | |
100 | + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (23, 5)).count() | |
101 | + | |
102 | + #VAR24 through 30 | |
103 | + day_numbers = [0, 1, 2, 3, 4, 5, 6] | |
104 | + day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] | |
105 | + for day_num in day_numbers: | |
106 | + interactions['access_subject_'+day_names[day_num]] = Log.objects.filter(action="access", resource="subject", | |
107 | + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() | |
108 | + | |
84 | 109 | data[student] = interactions |
85 | 110 | |
86 | 111 | context["data"] = data |
87 | 112 | |
88 | 113 | |
89 | 114 | return context |
115 | + | |
116 | + | ... | ... |