diff --git a/reports/locale/pt_BR/LC_MESSAGES/django.po b/reports/locale/pt_BR/LC_MESSAGES/django.po index 3be981f..0868bf9 100644 --- a/reports/locale/pt_BR/LC_MESSAGES/django.po +++ b/reports/locale/pt_BR/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-03-17 00:26-0300\n" +"POT-Creation-Date: 2017-03-20 18:40-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -66,20 +66,20 @@ msgstr "Esta data deve ser igual ou após" msgid "This date should be right or before " msgstr "Esta data deve ser igual ou anterior à" -#: templates/reports/_form.html:4 +#: templates/reports/_form.html:19 msgid "General Parameters" msgstr "Escolha o Tópico e o Período" -#: templates/reports/_form.html:28 +#: templates/reports/_form.html:37 msgid "Choose the Data Source (is possible to pick more than one)" msgstr "Escolha a fonte de dados (é possível escolher mais de uma)" -#: templates/reports/_form.html:65 +#: templates/reports/_form.html:62 msgid "Interaction with resources" msgstr "Interação com recursos" -#: templates/reports/_form.html:100 -msgid "Search" +#: templates/reports/_form.html:97 +msgid "Search Report" msgstr "Buscar" #: templates/reports/create.html:27 templates/reports/view.html:33 @@ -134,84 +134,83 @@ msgstr "Dados de interação" msgid "Report created successfully" msgstr "Relatório criado com sucesso!" -#: views.py:168 +#: views.py:169 msgid "Number of help posts created by the user." msgstr "Número de postagens de dúvidas criadas no mural da disciplina." -#: views.py:174 +#: views.py:175 msgid "Amount of comments on help posts created by the student." msgstr "" "Número de comentários criados para as próprias postagens de dúvidas no mural " "da disciplina." -#: views.py:179 +#: views.py:180 msgid "Amount of comments made by the student on teachers help posts." msgstr "" "Número de comentários às postagens de dúvidas no mural da disciplina criadas " "pelo professor." -#: views.py:183 +#: views.py:184 msgid "Amount of comments made by the student on other students help posts." msgstr "" "Número de comentários às postagens de dúvidas no mural da disciplina criadas " "por outros estudantes." -#: views.py:194 +#: views.py:195 msgid "Number of help posts created by the user that the teacher commented on." msgstr "" "Número de comentários às postagens de dúvidas no mural da disciplina criadas " "por outros estudantes" -#: views.py:202 +#: views.py:203 msgid "Number of help posts created by the user others students commented on." msgstr "" " Número de postagens de dúvidas criadas no mural da disciplina que foram " "comentadas por outros estudantes." -#: views.py:205 +#: views.py:206 msgid "Number of student visualizations on the mural of the subject." msgstr "Número de visualizações do mural da disciplina." -#: views.py:217 +#: views.py:218 msgid "Number of access to mural between 6 a.m to 12a.m. ." msgstr "" "Número de acessos ao ambiente virtual da disciplina no horário de 06h às 12h." -#: views.py:221 +#: views.py:222 msgid "Number of access to mural between 0 p.m to 6p.m. ." msgstr "" "Número de acessos ao ambiente virtual da disciplina no horário de 12h às 18h." -#: views.py:224 +#: views.py:225 msgid "Number of access to mural between 6 p.m to 12p.m. ." msgstr "" "Número de acessos ao ambiente virtual da disciplina no horário de 18h às 24h." -#: views.py:228 +#: views.py:229 msgid "Number of access to mural between 0 a.m to 6a.m. ." msgstr "" "Número de acessos ao ambiente virtual da disciplina no horário de 24h às 06h." -#: views.py:233 -msgid "sunday" -msgstr "domingo" - -#: views.py:236 views.py:239 +#: views.py:237 views.py:240 msgid "Number of access to the subject on " msgstr "Número de acessos ao assunto na(o) " -#: views.py:242 +#: views.py:243 msgid "Number of distinct days the user access the subject. " msgstr "Número de dias distintos que acessou o ambiente virtual da disciplina." -#: views.py:243 +#: views.py:244 msgid "Class" msgstr "Classe" -#: views.py:244 +#: views.py:245 msgid "Performance" msgstr "Desempenho" +#~ msgid "sunday" +#~ msgstr "domingo" + #~ msgid "Topics to select data from" #~ msgstr "Tópico do qual os dados serão retirados" diff --git a/reports/migrations/0001_initial.py b/reports/migrations/0001_initial.py new file mode 100644 index 0000000..16bd202 --- /dev/null +++ b/reports/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-03-21 00:06 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='ReportCSV', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('csv_data', models.TextField()), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name_plural': 'ReportCSVs', + 'verbose_name': 'ReportCSV', + }, + ), + ] diff --git a/reports/models.py b/reports/models.py index 71a8362..4c5ef15 100644 --- a/reports/models.py +++ b/reports/models.py @@ -1,3 +1,15 @@ from django.db import models - +from users.models import User # Create your models here. +class ReportCSV(models.Model): + + user = models.ForeignKey(User) + csv_data = models.TextField() + + class Meta: + verbose_name = "ReportCSV" + verbose_name_plural = "ReportCSVs" + + def __str__(self): + pass + \ No newline at end of file diff --git a/reports/templates/reports/_form.html b/reports/templates/reports/_form.html index d47672a..77974a6 100644 --- a/reports/templates/reports/_form.html +++ b/reports/templates/reports/_form.html @@ -94,7 +94,7 @@
- +
diff --git a/reports/templates/reports/view.html b/reports/templates/reports/view.html index ee83f7b..1b68506 100644 --- a/reports/templates/reports/view.html +++ b/reports/templates/reports/view.html @@ -65,7 +65,9 @@ diff --git a/reports/urls.py b/reports/urls.py index 0babb5d..3c4ade6 100644 --- a/reports/urls.py +++ b/reports/urls.py @@ -7,4 +7,5 @@ urlpatterns = [ url(r'^view/interactions/$', views.ViewReportView.as_view(), name='view_report'), url(r'^get/resources/$', views.get_resources, name='get_resource_and_tags'), url(r'^get/tags/$', views.get_tags, name='get_tags'), + url(r'^post/download_report/$', views.download_report, name="download_report"), ] \ No newline at end of file diff --git a/reports/views.py b/reports/views.py index 0e2a6fc..a68ddf6 100644 --- a/reports/views.py +++ b/reports/views.py @@ -18,6 +18,8 @@ from log.models import Log from topics.models import Resource, Topic from collections import OrderedDict from django.forms import formset_factory +from .models import ReportCSV +import pandas as pd class ReportView(LoginRequiredMixin, generic.FormView): template_name = "reports/create.html" @@ -133,10 +135,25 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): resources = params_data.getlist('resource') tags = params_data.getlist('tag') - if params_data['from_mural']: - #I used getlist method so it can get more than one tag and one resource class_name - context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], - resources, tags ) + self.from_mural = params_data['from_mural'] + #I used getlist method so it can get more than one tag and one resource class_name + context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], + resources, tags ) + + + #this is to save the csv for further download + df = pd.DataFrame.from_dict(context['data'], orient='index') + + df.columns = context['header'] + #so it does not exist more than one report CSV available for that user to download + if ReportCSV.objects.filter(user= self.request.user).count() > 0: + report = ReportCSV.objects.get(user=self.request.user) + report.delete() + + + report = ReportCSV(user= self.request.user, csv_data = df.to_csv()) + report.save() + return context def get_mural_data(self, subject, init_date, end_date, resources_id, tags_id): @@ -158,52 +175,53 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): data[student].append(student.social_name) - interactions = OrderedDict() + interactions = OrderedDict() + #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)) + if self.from_mural == "True": + 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[_('Number of help posts created by the user.')] = help_posts_made_by_user.count() + #number of help posts created by the student + interactions[_('Number of help posts created by the user.')] = help_posts_made_by_user.count() - help_posts = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), - space__id=subject.id) + 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[_('Amount of comments on help posts created by the student.')] = Comment.objects.filter(post__in = help_posts.filter(user=student), - create_date__range=(init_date, end_date)).count() - + #comments count on help posts created by the student + interactions[_('Amount of comments on help posts created by the student.')] = 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[_('Amount of comments made by the student on teachers help posts.')] = Comment.objects.filter(post__in = help_posts.filter(user__in= subject.professor.all()), create_date__range=(init_date, end_date), - user=student).count() + #count the amount of comments made by the student on posts made by one of the professors + interactions[_('Amount of comments made by the student on teachers help posts.')] = 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[_('Amount of comments made by the student on other students help posts.')] = 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[_('Number of help posts created by the user that the teacher commented on.')] = 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[_('Number of help posts created by the user others students commented on.')] = help_posts.filter(user=student, id__in = help_posts_ids).count() - - #Number of student visualizations on the mural of the subject - interactions[_('Number of student visualizations on the mural of the subject.')] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), - user = student).count() + #comments made by the user on other users posts + interactions[_('Amount of comments made by the student on other students help posts.')] = 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[_('Number of help posts created by the user that the teacher commented on.')] = 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[_('Number of help posts created by the user others students commented on.')] = help_posts.filter(user=student, id__in = help_posts_ids).count() + + #Number of student visualizations on the mural of the subject + interactions[_('Number of student visualizations on the mural of the subject.')] = MuralVisualizations.objects.filter(post__in = SubjectPost.objects.filter(space__id=subject.id), + user = student).count() #VAR08 through VAR_019 of documenttation: @@ -317,3 +335,12 @@ def get_tags(request): data['tags'] = [ {'id':tag.id, 'name':tag.name} for tag in tags] return JsonResponse(data) + + +def download_report(request): + report = ReportCSV.objects.get(user=request.user) + + response = HttpResponse(report.csv_data,content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename="report.csv"' + + return response \ No newline at end of file -- libgit2 0.21.2