Commit f88db7da53c71516561bcc5053b9479aa81e50aa
1 parent
ade5a5e2
Exists in
master
and in
3 other branches
removed links and queries from api app and moved everything to reports app
Showing
12 changed files
with
168 additions
and
146 deletions
Show diff stats
api/templates/api/report.html
... | ... | @@ -1,31 +0,0 @@ |
1 | -{% extends 'base.html' %} | |
2 | - | |
3 | -{% load static i18n pagination %} | |
4 | -{% load django_bootstrap_breadcrumbs %} | |
5 | - | |
6 | -{% block breadcrumbs %} | |
7 | - {{ block.super }} | |
8 | - | |
9 | - {% trans 'Mural: General' as general %} | |
10 | - | |
11 | - {% breadcrumb general 'mural:manage_general' %} | |
12 | -{% endblock %} | |
13 | - | |
14 | -{% block content %} | |
15 | - | |
16 | - | |
17 | - {% for user, datum in data.items %} | |
18 | - | |
19 | - | |
20 | - <p> | |
21 | - <ul> | |
22 | - | |
23 | - {{user}} : | |
24 | - {% for key, value in datum.items %} | |
25 | - <li>{{key}}: {{value}}</li> | |
26 | - {% endfor %} | |
27 | - </ul> | |
28 | - | |
29 | - </p> | |
30 | - {% endfor %} | |
31 | -{% endblock content %} | |
32 | 0 | \ No newline at end of file |
api/urls.py
api/views.py
1 | 1 | from django.shortcuts import render |
2 | -from django.http import HttpResponse, JsonResponse | |
3 | - | |
4 | - | |
5 | -import django.views.generic as generic | |
6 | -from mural.models import SubjectPost, Comment, MuralVisualizations | |
7 | -from django.db.models import Q | |
8 | -from django.contrib.auth.mixins import LoginRequiredMixin | |
9 | -from datetime import datetime, date | |
10 | -from subjects.models import Subject | |
11 | - | |
12 | -from log.models import Log | |
13 | - | |
14 | -class ReportView(LoginRequiredMixin, generic.TemplateView): | |
15 | - template_name = "api/report.html" | |
16 | - | |
17 | - def get_context_data(self, **kwargs): | |
18 | - context = {} | |
19 | - params = self.request.GET | |
20 | - | |
21 | - if params['subject_id'] and params['init_date'] and params['end_date']: | |
22 | - subject_id = params['subject_id'] | |
23 | - subject = Subject.objects.get(id=subject_id) | |
24 | - data = {} | |
25 | - students = subject.students.all() | |
26 | - formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats | |
27 | - for fmt in formats: | |
28 | - try: | |
29 | - init_date = datetime.strptime(params['init_date'], fmt) | |
30 | - end_date = datetime.strptime(params['end_date'], fmt) | |
31 | - except ValueError: | |
32 | - pass | |
33 | - | |
34 | - for student in students: | |
35 | - interactions = {} | |
36 | - #first columns | |
37 | - interactions['subject_name'] = subject.name | |
38 | - interactions['username'] = student.social_name | |
39 | - interactions['init_date'] = init_date | |
40 | - interactions['end_date'] = end_date | |
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 | - | |
45 | - #number of help posts created by the student | |
46 | - interactions['doubts_count'] = help_posts_made_by_user.count() | |
47 | - | |
48 | - help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
49 | - space__id=subject_id) | |
50 | - | |
51 | - #comments count on help posts created by the student | |
52 | - interactions['comments_count'] = Comment.objects.filter(post__in = help_posts.filter(user=student), | |
53 | - create_date__range=(init_date, end_date)).count() | |
54 | - | |
55 | - | |
56 | - #count the amount of comments made by the student on posts made by one of the professors | |
57 | - interactions['comments_professor_count'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), | |
58 | - user=student).count() | |
59 | - | |
60 | - #comments made by the user on other users posts | |
61 | - interactions['comments_on_others_count'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), | |
62 | - create_date__range=(init_date, end_date), | |
63 | - user= student).count() | |
64 | - | |
65 | - | |
66 | - | |
67 | - comments_by_teacher = Comment.objects.filter(user__in=subject.professor.all()) | |
68 | - help_posts_ids = [] | |
69 | - for comment in comments_by_teacher: | |
70 | - help_posts_ids.append(comment.post.id) | |
71 | - #number of help posts created by the user that the teacher commented on | |
72 | - interactions['help_posts_commented_by_teacher'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
73 | - | |
74 | - | |
75 | - comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) | |
76 | - help_posts_ids = [] | |
77 | - for comment in comments_by_teacher: | |
78 | - help_posts_ids.append(comment.post.id) | |
79 | - #number of help posts created by the user others students commented on | |
80 | - interactions['help_posts_commented_by_others'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
81 | - | |
82 | - #Number of student visualizations on the mural of the subject | |
83 | - interactions['mural_visualizations_count'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), | |
84 | - user = student).count() | |
85 | - | |
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 | - | |
109 | - data[student] = interactions | |
110 | - | |
111 | - context["data"] = data | |
112 | - | |
113 | - | |
114 | - return context | |
115 | - | |
116 | 2 | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +{% extends 'base.html' %} | |
2 | + | |
3 | +{% load static i18n pagination %} | |
4 | +{% load django_bootstrap_breadcrumbs %} | |
5 | + | |
6 | +{% block breadcrumbs %} | |
7 | + {{ block.super }} | |
8 | + | |
9 | + {% trans 'Mural: General' as general %} | |
10 | + | |
11 | + {% breadcrumb general 'mural:manage_general' %} | |
12 | +{% endblock %} | |
13 | + | |
14 | +{% block content %} | |
15 | + | |
16 | + | |
17 | + {% for user, datum in data.items %} | |
18 | + | |
19 | + | |
20 | + <p> | |
21 | + <ul> | |
22 | + | |
23 | + {{user}} : | |
24 | + {% for key, value in datum.items %} | |
25 | + <li>{{key}}: {{value}}</li> | |
26 | + {% endfor %} | |
27 | + </ul> | |
28 | + | |
29 | + </p> | |
30 | + {% endfor %} | |
31 | +{% endblock content %} | |
0 | 32 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,116 @@ |
1 | +from django.shortcuts import render | |
2 | +from django.http import HttpResponse, JsonResponse | |
3 | + | |
4 | + | |
5 | +import django.views.generic as generic | |
6 | +from mural.models import SubjectPost, Comment, MuralVisualizations | |
7 | +from django.db.models import Q | |
8 | +from django.contrib.auth.mixins import LoginRequiredMixin | |
9 | +from datetime import datetime, date | |
10 | +from subjects.models import Subject | |
11 | + | |
12 | +from log.models import Log | |
13 | + | |
14 | +class ReportView(LoginRequiredMixin, generic.TemplateView): | |
15 | + template_name = "api/report.html" | |
16 | + | |
17 | + def get_context_data(self, **kwargs): | |
18 | + context = {} | |
19 | + params = self.request.GET | |
20 | + | |
21 | + if params['subject_id'] and params['init_date'] and params['end_date']: | |
22 | + subject_id = params['subject_id'] | |
23 | + subject = Subject.objects.get(id=subject_id) | |
24 | + data = {} | |
25 | + students = subject.students.all() | |
26 | + formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats | |
27 | + for fmt in formats: | |
28 | + try: | |
29 | + init_date = datetime.strptime(params['init_date'], fmt) | |
30 | + end_date = datetime.strptime(params['end_date'], fmt) | |
31 | + except ValueError: | |
32 | + pass | |
33 | + | |
34 | + for student in students: | |
35 | + interactions = {} | |
36 | + #first columns | |
37 | + interactions['subject_name'] = subject.name | |
38 | + interactions['username'] = student.social_name | |
39 | + interactions['init_date'] = init_date | |
40 | + interactions['end_date'] = end_date | |
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 | + | |
45 | + #number of help posts created by the student | |
46 | + interactions['doubts_count'] = help_posts_made_by_user.count() | |
47 | + | |
48 | + help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
49 | + space__id=subject_id) | |
50 | + | |
51 | + #comments count on help posts created by the student | |
52 | + interactions['comments_count'] = Comment.objects.filter(post__in = help_posts.filter(user=student), | |
53 | + create_date__range=(init_date, end_date)).count() | |
54 | + | |
55 | + | |
56 | + #count the amount of comments made by the student on posts made by one of the professors | |
57 | + interactions['comments_professor_count'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), | |
58 | + user=student).count() | |
59 | + | |
60 | + #comments made by the user on other users posts | |
61 | + interactions['comments_on_others_count'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), | |
62 | + create_date__range=(init_date, end_date), | |
63 | + user= student).count() | |
64 | + | |
65 | + | |
66 | + | |
67 | + comments_by_teacher = Comment.objects.filter(user__in=subject.professor.all()) | |
68 | + help_posts_ids = [] | |
69 | + for comment in comments_by_teacher: | |
70 | + help_posts_ids.append(comment.post.id) | |
71 | + #number of help posts created by the user that the teacher commented on | |
72 | + interactions['help_posts_commented_by_teacher'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
73 | + | |
74 | + | |
75 | + comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) | |
76 | + help_posts_ids = [] | |
77 | + for comment in comments_by_teacher: | |
78 | + help_posts_ids.append(comment.post.id) | |
79 | + #number of help posts created by the user others students commented on | |
80 | + interactions['help_posts_commented_by_others'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
81 | + | |
82 | + #Number of student visualizations on the mural of the subject | |
83 | + interactions['mural_visualizations_count'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), | |
84 | + user = student).count() | |
85 | + | |
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 | + | |
109 | + data[student] = interactions | |
110 | + | |
111 | + context["data"] = data | |
112 | + | |
113 | + | |
114 | + return context | |
115 | + | |
116 | + | ... | ... |