Commit 495dbd8aeb9a447e704092ffec62e98ecdbb0888
1 parent
81da7085
Exists in
master
and in
3 other branches
added report app and removed query of reports from api app, modified css for rep…
…ort page and added link to subject cards
Showing
7 changed files
with
75 additions
and
105 deletions
Show diff stats
amadeus/settings.py
amadeus/static/css/base/amadeus.css
| ... | ... | @@ -1196,4 +1196,13 @@ li.item .notify_badge { |
| 1196 | 1196 | font-weight: 700; |
| 1197 | 1197 | font-size: 20px; |
| 1198 | 1198 | } |
| 1199 | -/* End Goals */ | |
| 1200 | 1199 | \ No newline at end of file |
| 1200 | +/* End Goals */ | |
| 1201 | + | |
| 1202 | + | |
| 1203 | +/* Reports */ | |
| 1204 | + | |
| 1205 | +.report-menu-choice li{ | |
| 1206 | + width: 15%; | |
| 1207 | + text-align: center; | |
| 1208 | +} | |
| 1209 | +/* End Reports */ | |
| 1201 | 1210 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +from django import forms | |
| 2 | +from django.utils.translation import ugettext_lazy as _ | |
| 3 | +import datetime | |
| 4 | + | |
| 5 | +class CreateInteractionReportForm(forms.Form): | |
| 6 | + topics = forms.ChoiceField(required=True) | |
| 7 | + init_date = forms.DateField(required=True) | |
| 8 | + end_date = forms.DateField(required=True) | |
| 9 | + | |
| 10 | + from_mural = forms.BooleanField() | |
| 11 | + from_messages = forms.BooleanField() | |
| 12 | + | ... | ... |
reports/templates/reports/report.html
| ... | ... | @@ -2,17 +2,49 @@ |
| 2 | 2 | |
| 3 | 3 | {% load static i18n pagination %} |
| 4 | 4 | {% load django_bootstrap_breadcrumbs %} |
| 5 | +{% load widget_tweaks %} | |
| 5 | 6 | |
| 6 | 7 | {% block breadcrumbs %} |
| 7 | 8 | {{ block.super }} |
| 8 | 9 | |
| 9 | - {% trans 'Mural: General' as general %} | |
| 10 | - | |
| 11 | - {% breadcrumb general 'mural:manage_general' %} | |
| 10 | + {% breadcrumb 'analytics' '' %} | |
| 12 | 11 | {% endblock %} |
| 13 | 12 | |
| 14 | 13 | {% block content %} |
| 15 | 14 | |
| 15 | + <div class="panel panel-info topic-panel"> | |
| 16 | + <div class="panel-heading"> | |
| 17 | + <div class="row"> | |
| 18 | + <div class="col-md-12 category-header"> | |
| 19 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | |
| 20 | + <span>{% trans "Analytics" %}</span> | |
| 21 | + </h4> | |
| 22 | + </div> | |
| 23 | + </div> | |
| 24 | + </div> | |
| 25 | + </div> | |
| 26 | + | |
| 27 | + <div id="core-subjects-options-div"> | |
| 28 | + <ul class="core-subjects-options report-menu-choice"> | |
| 29 | + <li class="active"> | |
| 30 | + {% trans "Interaction Data" %} | |
| 31 | + </li> | |
| 32 | + <li> | |
| 33 | + {% trans "Report Card" %} | |
| 34 | + </li> | |
| 35 | + <li> | |
| 36 | + {% trans "Participation" %} | |
| 37 | + </li> | |
| 38 | + </ul> | |
| 39 | + </div> | |
| 40 | + | |
| 41 | +<form action="" method="post">{% csrf_token %} | |
| 42 | + {% for field in form %} | |
| 43 | + <label> {{field.label}} </label> | |
| 44 | + {% render_field field class='form-control' %} | |
| 45 | + {% endfor %} | |
| 46 | + <input type="submit" value="Send message" /> | |
| 47 | +</form> | |
| 16 | 48 | |
| 17 | 49 | {% for user, datum in data.items %} |
| 18 | 50 | ... | ... |
reports/urls.py
reports/views.py
| ... | ... | @@ -8,109 +8,26 @@ from django.db.models import Q |
| 8 | 8 | from django.contrib.auth.mixins import LoginRequiredMixin |
| 9 | 9 | from datetime import datetime, date |
| 10 | 10 | from subjects.models import Subject |
| 11 | - | |
| 11 | +from .forms import CreateInteractionReportForm | |
| 12 | 12 | from log.models import Log |
| 13 | 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 | 14 | |
| 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() | |
| 15 | +class ReportView(LoginRequiredMixin, generic.FormView): | |
| 16 | + template_name = "reports/report.html" | |
| 17 | + form_class = CreateInteractionReportForm | |
| 18 | + success_url = "/teste" | |
| 19 | + def get_initial(self): | |
| 20 | + """ | |
| 21 | + Returns the initial data to use for forms on this view. | |
| 22 | + """ | |
| 73 | 23 | |
| 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 | |
| 24 | + initial = super(ReportView, self).get_initial() | |
| 25 | + params = self.request.GET | |
| 26 | + subject = Subject.objects.get(id=params['subject_id']) | |
| 112 | 27 | |
| 28 | + initial['topics'] = subject.topic_subject.all() | |
| 113 | 29 | |
| 114 | - return context | |
| 30 | + return initial | |
| 31 | + | |
| 115 | 32 | |
| 116 | 33 | ... | ... |
subjects/templates/subjects/subject_card.html
| ... | ... | @@ -34,7 +34,7 @@ |
| 34 | 34 | </ul> |
| 35 | 35 | {% endif %} |
| 36 | 36 | |
| 37 | - <a href="" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | |
| 37 | + <a href="{% url 'subjects:reports:create_interaction' %}?subject_id={{subject.id}}" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | |
| 38 | 38 | <a href="{% url 'notifications:view' subject.slug %}" class="pull-right action_icon"> |
| 39 | 39 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
| 40 | 40 | {% notifies_number subject request.user %} | ... | ... |