From ebc0db3dc2231f189437d2ae0be93e6a737b55dc Mon Sep 17 00:00:00 2001 From: fbormann Date: Thu, 9 Mar 2017 15:53:30 -0300 Subject: [PATCH] saving progress on report view --- amadeus/static/css/base/amadeus.css | 6 ++++++ reports/forms.py | 11 ++++++----- reports/templates/reports/_form.html | 15 +++++++++++++++ reports/templates/reports/create.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ reports/templates/reports/report.html | 57 --------------------------------------------------------- reports/templates/reports/view.html | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ reports/urls.py | 1 + reports/views.py | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 299 insertions(+), 63 deletions(-) create mode 100644 reports/templates/reports/create.html delete mode 100644 reports/templates/reports/report.html create mode 100644 reports/templates/reports/view.html diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index efe1d22..6bf406a 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -1209,4 +1209,10 @@ div.dataTables_wrapper div.dataTables_paginate { width: 15%; text-align: center; } + +#report-header li { + display: inline; + margin-right: 10px; + font-size: 16px; +} /* End Reports */ \ No newline at end of file diff --git a/reports/forms.py b/reports/forms.py index 9064ee2..947b54a 100644 --- a/reports/forms.py +++ b/reports/forms.py @@ -5,12 +5,12 @@ import datetime class CreateInteractionReportForm(forms.Form): - topic = forms.ChoiceField(required=True, label= _("topics to select data from")) - init_date = forms.DateField(required=True) - end_date = forms.DateField(required=True) + topic = forms.ChoiceField( label= _("topics to select data from")) + init_date = forms.DateField() + end_date = forms.DateField() - from_mural = forms.BooleanField() - from_messages = forms.BooleanField() + from_mural = forms.BooleanField(required=False) + from_messages = forms.BooleanField(required=False) class Meta: fields = ('topic', 'init_date', 'end_date', 'from_mural' , 'from_messages') @@ -22,3 +22,4 @@ class CreateInteractionReportForm(forms.Form): topics = list(initial['topic']) self.fields['topic'].choices = [(topic.id, topic.name) for topic in topics] + self.fields['topic'].choices.append((_("all"), _("all"))) diff --git a/reports/templates/reports/_form.html b/reports/templates/reports/_form.html index 71615f5..66355c8 100644 --- a/reports/templates/reports/_form.html +++ b/reports/templates/reports/_form.html @@ -11,6 +11,21 @@ {% render_field field class='form-control' %} {% endif %} + {% if field.errors %} +
+
+ +
+ {% endif %} {% endfor %}
diff --git a/reports/templates/reports/create.html b/reports/templates/reports/create.html new file mode 100644 index 0000000..22fdea5 --- /dev/null +++ b/reports/templates/reports/create.html @@ -0,0 +1,44 @@ +{% extends 'base.html' %} + +{% load static i18n pagination %} +{% load django_bootstrap_breadcrumbs %} +{% load widget_tweaks %} + +{% block breadcrumbs %} + {{ block.super }} + + {% breadcrumb 'analytics' '' %} +{% endblock %} + +{% block content %} + +
+
+
+
+

+ {% trans "Analytics" %} +

+
+
+
+
+ +
+
    +
  • + {% trans "Interaction Data" %} +
  • +
  • + {% trans "Report Card" %} +
  • +
  • + {% trans "Participation" %} +
  • +
+
+ + {% include "reports/_form.html" %} + + +{% endblock content %} \ No newline at end of file diff --git a/reports/templates/reports/report.html b/reports/templates/reports/report.html deleted file mode 100644 index 9f7f58c..0000000 --- a/reports/templates/reports/report.html +++ /dev/null @@ -1,57 +0,0 @@ -{% extends 'base.html' %} - -{% load static i18n pagination %} -{% load django_bootstrap_breadcrumbs %} -{% load widget_tweaks %} - -{% block breadcrumbs %} - {{ block.super }} - - {% breadcrumb 'analytics' '' %} -{% endblock %} - -{% block content %} - -
-
-
-
-

- {% trans "Analytics" %} -

-
-
-
-
- -
-
    -
  • - {% trans "Interaction Data" %} -
  • -
  • - {% trans "Report Card" %} -
  • -
  • - {% trans "Participation" %} -
  • -
-
- - {% include "reports/_form.html" %} - - {% for user, datum in data.items %} - - -

-

- -

- {% endfor %} -{% endblock content %} \ No newline at end of file diff --git a/reports/templates/reports/view.html b/reports/templates/reports/view.html new file mode 100644 index 0000000..c51aa06 --- /dev/null +++ b/reports/templates/reports/view.html @@ -0,0 +1,87 @@ +{% extends 'base.html' %} + +{% load static i18n pagination %} +{% load django_bootstrap_breadcrumbs %} +{% load widget_tweaks %} + +{% block breadcrumbs %} + {{ block.super }} + + {% breadcrumb 'analytics' '' %} +{% endblock %} + +{% block content %} + + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} + + +
+
+
+
+

+ {% trans "Analytics" %} +

+
+
+
+
+ +
+
    +
  • + {% trans "Interaction Data" %} +
  • +
  • + {% trans "Report Card" %} +
  • +
  • + {% trans "Participation" %} +
  • +
+
+ +
+
    +
  • {% trans "Subject" %}: {{subject_name}}
  • +
  • {% trans "Topic" %}: {{topic_name}}
  • +
  • {% trans "Initial Date" %}: {{init_date}}
  • +
  • {% trans "End Date" %}: {{end_date}}
  • +
  • + +
+
+ + + + {% for key in data.keys %} + + {% endfor %} + + + + + {% for value_dict in data.values %} + + {% for key, value in value_dict.items %} + + {% endfor %} + + {% endfor %} + + +
{{key}}
{{value}}
+
+
+ + +{% endblock content %} \ No newline at end of file diff --git a/reports/urls.py b/reports/urls.py index 6f6aa95..b3f205f 100644 --- a/reports/urls.py +++ b/reports/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ url(r'^create/interactions/$', views.ReportView.as_view(), name='create_interaction'), + url(r'^view/interactions/$', views.ViewReportView.as_view(), name='view_report'), ] \ No newline at end of file diff --git a/reports/views.py b/reports/views.py index b753c4e..cfbda82 100644 --- a/reports/views.py +++ b/reports/views.py @@ -3,6 +3,9 @@ from django.http import HttpResponse, JsonResponse from django.utils.translation import ugettext_lazy as _ from django import forms +from django.core.urlresolvers import reverse_lazy + +from django.contrib import messages import django.views.generic as generic from mural.models import SubjectPost, Comment, MuralVisualizations @@ -15,7 +18,7 @@ from log.models import Log class ReportView(LoginRequiredMixin, generic.FormView): - template_name = "reports/report.html" + template_name = "reports/create.html" form_class = CreateInteractionReportForm def get_initial(self): @@ -30,3 +33,139 @@ class ReportView(LoginRequiredMixin, generic.FormView): initial['topic'] = topics initial['end_date'] = date.today() return initial + + + def get_success_url(self): + + messages.success(self.request, _("Report created successfully")) + + get_params = "?" + #passing form data through GET + for key, value in self.form_data.items(): + get_params += key + "=" + str(value) + "&" + + + #retrieving subject id for data purposes + for key, value in self.request.GET.items(): + get_params += key + "=" + str(value) + + return reverse_lazy('subjects:reports:view_report', kwargs={}) + get_params + + def post(self, request, *args, **kwargs): + """ + Handles POST requests, instantiating a form instance with the passed + POST variables and then checked for validity. + """ + form = self.get_form() + if form.is_valid(): + + self.form_data = form.cleaned_data + return self.form_valid(form) + else: + return self.form_invalid(form) + + +class ViewReportView(LoginRequiredMixin, generic.TemplateView): + template_name = "reports/view.html" + + + def get_context_data(self, **kwargs): + context = {} + params_data = self.request.GET + subject = Subject.objects.get(id=params_data['subject_id']) + context['subject_name'] = subject.name + context['topic_name'] = params_data['topic'] + context['init_date'] = params_data['init_date'] + context['end_date'] = params_data['end_date'] + + if params_data['from_mural']: + context['data'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date']) + return context + + def get_mural_data(self, subject, init_date, end_date): + data = {} + students = subject.students.all() + formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats + for fmt in formats: + try: + init_date = datetime.strptime(init_date, fmt) + end_date = datetime.strptime(end_date, fmt) + except ValueError: + pass + + + for student in students: + interactions = {} + interactions['username'] = student.social_name + + help_posts_made_by_user = SubjectPost.objects.filter(action="help",space__id=subject.id, user=student, + create_date__range=(init_date, end_date)) + + #number of help posts created by the student + interactions['doubts_count'] = help_posts_made_by_user.count() + + help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), + space__id=subject.id) + + #comments count on help posts created by the student + interactions['comments_count'] = Comment.objects.filter(post__in = help_posts.filter(user=student), + create_date__range=(init_date, end_date)).count() + + + #count the amount of comments made by the student on posts made by one of the professors + interactions['comments_professor_count'] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), + user=student).count() + + #comments made by the user on other users posts + interactions['comments_on_others_count'] = Comment.objects.filter(post__in = help_posts.exclude(user=student), + create_date__range=(init_date, end_date), + user= student).count() + + + + comments_by_teacher = Comment.objects.filter(user__in=subject.professor.all()) + help_posts_ids = [] + for comment in comments_by_teacher: + help_posts_ids.append(comment.post.id) + #number of help posts created by the user that the teacher commented on + interactions['help_posts_commented_by_teacher'] = help_posts.filter(user=student, id__in = help_posts_ids).count() + + + comments_by_others = Comment.objects.filter(user__in=subject.students.exclude(id = student.id)) + help_posts_ids = [] + for comment in comments_by_teacher: + help_posts_ids.append(comment.post.id) + #number of help posts created by the user others students commented on + interactions['help_posts_commented_by_others'] = help_posts.filter(user=student, id__in = help_posts_ids).count() + + #Number of student visualizations on the mural of the subject + interactions['mural_visualizations_count'] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), + user = student).count() + + + #VAR20 - number of access to mural between 6 a.m to 12a.m. + interactions['access_subject_between_6_to_12_am'] = Log.objects.filter(action="access", resource="subject", + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (5, 11)).count() + + #VAR21 - number of access to mural between 6 a.m to 12a.m. + interactions['access_subject_between_0_to_6_pm'] = Log.objects.filter(action="access", resource="subject", + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (11, 17)).count() + #VAR22 + interactions['access_subject_between_6_to_12_pm'] = Log.objects.filter(action="access", resource="subject", + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (17, 23)).count() + + #VAR23 + interactions['access_subject_between_0_to_6_am'] = Log.objects.filter(action="access", resource="subject", + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__hour__range = (23, 5)).count() + + #VAR24 through 30 + day_numbers = [0, 1, 2, 3, 4, 5, 6] + day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] + for day_num in day_numbers: + interactions['access_subject_'+day_names[day_num]] = Log.objects.filter(action="access", resource="subject", + user_id= student.id, context__contains = {'subject_id' : subject.id}, datetime__week_day = day_num).count() + + data[student] = interactions + print(data) + return data + -- libgit2 0.21.2