Commit 7947a71b18eedf868f1af97eae82c1d42f23adba
1 parent
60d308d7
Exists in
master
and in
3 other branches
finished first report based on student
Showing
1 changed file
with
50 additions
and
3 deletions
Show diff stats
api/views.py
... | ... | @@ -3,7 +3,7 @@ from django.http import HttpResponse, JsonResponse |
3 | 3 | |
4 | 4 | |
5 | 5 | import django.views.generic as generic |
6 | -from mural.models import SubjectPost | |
6 | +from mural.models import SubjectPost, Comment, MuralVisualizations | |
7 | 7 | from django.db.models import Q |
8 | 8 | from django.contrib.auth.mixins import LoginRequiredMixin |
9 | 9 | from datetime import datetime, date |
... | ... | @@ -31,9 +31,56 @@ class ReportView(LoginRequiredMixin, generic.TemplateView): |
31 | 31 | |
32 | 32 | for student in students: |
33 | 33 | interactions = {} |
34 | - | |
35 | - interactions['doubts'] = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
34 | + #first columns | |
35 | + interactions['subject_name'] = subject.name | |
36 | + interactions['username'] = student.social_name | |
37 | + interactions['init_date'] = init_date | |
38 | + interactions['end_date'] = end_date | |
39 | + print(datetime.now()) | |
40 | + #number of help posts created by the student | |
41 | + interactions['doubts_count'] = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
36 | 42 | space__id=subject_id, user=student).count() |
43 | + | |
44 | + help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | |
45 | + space__id=subject_id) | |
46 | + | |
47 | + #comments count on help posts created by the student | |
48 | + interactions['comments_count'] = Comment.objects.filter(post__in = help_posts.filter(user=student), | |
49 | + create_date__range=(init_date, end_date)).count() | |
50 | + | |
51 | + | |
52 | + #count the amount of comments made by the student on posts made by one of the professors | |
53 | + interactions['comments_professor_count'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), | |
54 | + user=student).count() | |
55 | + | |
56 | + #comments made by the user on other users posts | |
57 | + interactions['comments_on_others_count'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), | |
58 | + create_date__range=(init_date, end_date), | |
59 | + user= student).count() | |
60 | + | |
61 | + | |
62 | + | |
63 | + comments_by_teacher = Comment.objects.filter(user__in=subject.professor.all()) | |
64 | + help_posts_ids = [] | |
65 | + for comment in comments_by_teacher: | |
66 | + help_posts_ids.append(comment.post.id) | |
67 | + #number of help posts created by the user that the teacher commented on | |
68 | + interactions['help_posts_commented_by_teacher'] = help_posts.filter(user=student, id__in = help_posts_ids) | |
69 | + | |
70 | + | |
71 | + comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) | |
72 | + help_posts_ids = [] | |
73 | + for comment in comments_by_teacher: | |
74 | + help_posts_ids.append(comment.post.id) | |
75 | + #number of help posts created by the user others students commented on | |
76 | + interactions['help_posts_commented_by_others'] = help_posts.filter(user=student, id__in = help_posts_ids).count() | |
77 | + | |
78 | + | |
79 | + #Number of student visualizations on the mural of the subject | |
80 | + interactions['mural_visualizations_count'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), | |
81 | + user = student).count() | |
82 | + print(datetime.now()) | |
83 | + | |
37 | 84 | data[student] = interactions |
38 | 85 | |
39 | 86 | print(data) | ... | ... |