Commit 35a9a0b8e03e4123ee51e527542d39c1074b1f71
1 parent
dd516893
Exists in
master
and in
2 other branches
atualizando grafico e tabelas de relatórios da webpage
Showing
4 changed files
with
182 additions
and
128 deletions
Show diff stats
webpage/templates/webpages/estatisticas.html
... | ... | @@ -1,104 +0,0 @@ |
1 | -{% extends "webpages/view.html" %} | |
2 | - | |
3 | -{% load static i18n pagination permissions_tags subject_counter %} | |
4 | -{% load django_bootstrap_breadcrumbs %} | |
5 | - | |
6 | -{% block javascript%} | |
7 | - {{ block.super }} | |
8 | - <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
9 | - <script type="text/javascript"> | |
10 | - google.charts.load('current', {'packages':['corechart',"table"]}); | |
11 | - google.charts.setOnLoadCallback(drawChart); | |
12 | - google.charts.setOnLoadCallback(drawTable); | |
13 | - | |
14 | - function drawChart() { | |
15 | - var data = google.visualization.arrayToDataTable({{db_data|safe}}); | |
16 | - | |
17 | - var options = { | |
18 | - title: '{{title_chart}}', | |
19 | - vAxis: { | |
20 | - title: '{{title_vAxis}}', | |
21 | - ticks: [0, .20, .40, .60, .80, 1], | |
22 | - viewWindow: { | |
23 | - min: 0, | |
24 | - max: 1 | |
25 | - } | |
26 | - }, | |
27 | - isStacked: "percent", | |
28 | - }; | |
29 | - | |
30 | - function selectHandler() { | |
31 | - var selectedItem = chart.getSelection()[0]; | |
32 | - if (selectedItem) { | |
33 | - var col = data.getColumnLabel(selectedItem.column); | |
34 | - window.location.href = '{% url "webpages:get_chart" webpage.slug %}?col='+col + '' | |
35 | - } | |
36 | - } | |
37 | - | |
38 | - var chart = new google.visualization.SteppedAreaChart(document.getElementById('chart_div')); | |
39 | - google.visualization.events.addListener(chart, 'select', selectHandler); | |
40 | - chart.draw(data, options); | |
41 | - } | |
42 | - | |
43 | - function drawTable() { | |
44 | - var data = new google.visualization.DataTable(); | |
45 | - data.addColumn('string', 'Student'); | |
46 | - data.addColumn('string', 'Email'); | |
47 | - data.addColumn('string', 'Action'); | |
48 | - data.addColumn('date', 'Date/Hour'); | |
49 | - data.addRows(getData()); | |
50 | - | |
51 | - function getData(){ | |
52 | - var array = []; | |
53 | - {%for a in history%} | |
54 | - array.push(['{{a.0}}','{{a.1}}',{% if a.2 is not None %}'{{a.2}}'{% else%}null{% endif %},{% if a.3 is not None %}new Date('{{a.3|date:"D, d M Y H:i:s"}}'){% else%}null{% endif %}]); | |
55 | - {% endfor%} | |
56 | - return array; | |
57 | - } | |
58 | - var formate_date = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'}); | |
59 | - formate_date.format(data, 3); | |
60 | - | |
61 | - | |
62 | - var table = new google.visualization.Table(document.getElementById('table_div')); | |
63 | - | |
64 | - table.draw(data, {showRowNumber: true, width: '100%', height: '100%'}); | |
65 | - } | |
66 | - </script> | |
67 | -{% endblock%} | |
68 | - | |
69 | -{% block breadcrumbs %} | |
70 | - {{ block.super }} | |
71 | - {% trans 'Estatisticas' as bread %} | |
72 | - {% breadcrumb bread webpage%} | |
73 | -{% endblock %} | |
74 | - | |
75 | -{% block content %} | |
76 | - {% if messages %} | |
77 | - {% for message in messages %} | |
78 | - <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
79 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
80 | - <span aria-hidden="true">×</span> | |
81 | - </button> | |
82 | - <p>{{ message }}</p> | |
83 | - </div> | |
84 | - {% endfor %} | |
85 | - {% endif %} | |
86 | - <div class="row"> | |
87 | - <div class="col-md-10"> | |
88 | - <div id="chart_div" style="height: 500px"></div> | |
89 | - </div> | |
90 | - </div> | |
91 | - | |
92 | - <div class="row"> | |
93 | - <div class="col-md-10"> | |
94 | - <div class="text-center"> | |
95 | - | |
96 | - <h3>{{title_table}}</h3> | |
97 | - </div> | |
98 | - <div id="table_div"></div> | |
99 | - </div> | |
100 | - </div> | |
101 | - <div class="row"> | |
102 | - <br><br> | |
103 | - </div> | |
104 | -{% endblock %} |
... | ... | @@ -0,0 +1,129 @@ |
1 | +{% extends "webpages/view.html" %} | |
2 | + | |
3 | +{% load static i18n pagination permissions_tags subject_counter %} | |
4 | +{% load django_bootstrap_breadcrumbs %} | |
5 | + | |
6 | +{% block javascript%} | |
7 | + {{ block.super }} | |
8 | + <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
9 | + <script type="text/javascript"> | |
10 | + google.charts.load('current', {'packages':['corechart',"table"]}); | |
11 | + google.charts.setOnLoadCallback(drawChart); | |
12 | + google.charts.setOnLoadCallback(drawTable); | |
13 | + | |
14 | + function drawChart() { | |
15 | + var data = google.visualization.arrayToDataTable({{db_data|safe}}); | |
16 | + | |
17 | + var options = { | |
18 | + title: '{{title_chart}}', | |
19 | + vAxis: { | |
20 | + title: '{{title_vAxis}}', | |
21 | + ticks: [0, .20, .40, .60, .80, 1], | |
22 | + viewWindow: { | |
23 | + min: 0, | |
24 | + max: 1 | |
25 | + } | |
26 | + }, | |
27 | + isStacked: "percent", | |
28 | + }; | |
29 | + | |
30 | + function selectHandler() { | |
31 | + var selectedItem = chart.getSelection()[0]; | |
32 | + if (selectedItem) { | |
33 | + var col = data.getColumnLabel(selectedItem.column); | |
34 | + window.location.href = '{% url "webpages:get_chart" webpage.slug %}?col='+col + '' | |
35 | + } | |
36 | + } | |
37 | + | |
38 | + var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | |
39 | + google.visualization.events.addListener(chart, 'select', selectHandler); | |
40 | + chart.draw(data, options); | |
41 | + } | |
42 | + | |
43 | + function drawTable() { | |
44 | + var data = new google.visualization.DataTable(); | |
45 | + {%for a in column%} | |
46 | + data.addColumn('{{a.1}}', '{{a.0}}'); | |
47 | + {% endfor%} | |
48 | + data.addRows(getData()); | |
49 | + function getData(){ | |
50 | + var array = []; | |
51 | + {%for a in history%} | |
52 | + {% if title_table == n_did_table %} | |
53 | + array.push(['{{a.0}}','{{a.1}}']); | |
54 | + {% else %} | |
55 | + array.push(['{{a.0}}','{{a.1}}','{{a.2}}',{% if a.3 is not None %}new Date('{{a.3.isoformat}}'){% else%}null{% endif %}]); | |
56 | + // console.log(new Date('{{a.3.isoformat}}')); | |
57 | + {% endif %} | |
58 | + {% endfor%} | |
59 | + return array; | |
60 | + } | |
61 | + var formate_date = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'}); | |
62 | + {% if not title_table == n_did_table %} | |
63 | + formate_date.format(data, 3); | |
64 | + console.log(data); | |
65 | + {% endif %} | |
66 | + | |
67 | + var table = new google.visualization.Table(document.getElementById('table_div')); | |
68 | + | |
69 | + table.draw(data, {showRowNumber: true, width: '100%', height: '100%'}); | |
70 | + } | |
71 | + </script> | |
72 | +{% endblock%} | |
73 | + | |
74 | +{% block breadcrumbs %} | |
75 | + {{ block.super }} | |
76 | + {% trans 'Reports' as bread %} | |
77 | + {% breadcrumb bread webpage%} | |
78 | +{% endblock %} | |
79 | + | |
80 | +{% block content %} | |
81 | + {% if messages %} | |
82 | + {% for message in messages %} | |
83 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
84 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
85 | + <span aria-hidden="true">×</span> | |
86 | + </button> | |
87 | + <p>{{ message }}</p> | |
88 | + </div> | |
89 | + {% endfor %} | |
90 | + {% endif %} | |
91 | + <div class="row"> | |
92 | + <div class="col-md-10"> | |
93 | + <div id="chart_div" style="height: 500px"></div> | |
94 | + </div> | |
95 | + </div> | |
96 | + | |
97 | + <div class="row"> | |
98 | + <div class="col-md-10"> | |
99 | + <div class="text-center"> | |
100 | + | |
101 | + <ul class="list-inline"> | |
102 | + <li> | |
103 | + {% if out_history %} | |
104 | + <a href="{% url 'webpages:get_chart' webpage.slug %}"> <i class="fa fa-arrow-left ta-fw"> </i> {% trans "History" %}</a> | |
105 | + {% endif %} | |
106 | + </li> | |
107 | + <li><h3>{{title_table}}</h3></li> | |
108 | + </ul> | |
109 | + <div class="row"> | |
110 | + <div class="col-md-7"> | |
111 | + <ul id="report-info"> | |
112 | + {# <li> {{data.values|length}} {% trans "register(s)" %} </li>#} | |
113 | + <li> | |
114 | + <a href=""><i class="fa fa-download" aria-hidden="true"></i> {% trans "Interactions Data (.csv)" %}</a> | |
115 | + </li> | |
116 | + <li><a href=""><i class="fa fa-download" aria-hidden="true"></i> {% trans "Interactions Data (.xls)" %}</a></li> | |
117 | + </ul> | |
118 | + </div> | |
119 | + <div class="col-md-3"> | |
120 | + </div> | |
121 | + </div> | |
122 | + </div> | |
123 | + <div id="table_div"></div> | |
124 | + </div> | |
125 | + </div> | |
126 | + <div class="row"> | |
127 | + <br><br> | |
128 | + </div> | |
129 | +{% endblock %} | ... | ... |
webpage/templates/webpages/view.html
... | ... | @@ -54,11 +54,5 @@ |
54 | 54 | {{ webpage.content }} |
55 | 55 | {% endautoescape %} |
56 | 56 | </div> |
57 | - | |
58 | - <div class="row"> | |
59 | - <div class="text-center"> | |
60 | - <a href="{% url 'webpages:get_chart' webpage.slug %}" class="btn btn-raised btn-success">{% trans "Statistics" %}</a> | |
61 | - </div> | |
62 | - </div> | |
63 | 57 | </div> |
64 | 58 | {% endblock %} | ... | ... |
webpage/views.py
... | ... | @@ -426,7 +426,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
426 | 426 | login_url = reverse_lazy("users:login") |
427 | 427 | redirect_field_name = 'next' |
428 | 428 | model = Webpage |
429 | - template_name = 'webpages/estatisticas.html' | |
429 | + template_name = 'webpages/relatorios.html' | |
430 | 430 | |
431 | 431 | def dispatch(self, request, *args, **kwargs): |
432 | 432 | slug = self.kwargs.get('slug', '') |
... | ... | @@ -456,7 +456,7 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
456 | 456 | super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
457 | 457 | |
458 | 458 | |
459 | - context['title'] = _('Webpage Statistics') | |
459 | + context['title'] = _('Webpage Reports') | |
460 | 460 | |
461 | 461 | slug = self.kwargs.get('slug') |
462 | 462 | webpage = get_object_or_404(Webpage, slug = slug) |
... | ... | @@ -464,31 +464,66 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
464 | 464 | parameter = self.request.GET.get('col','') |
465 | 465 | |
466 | 466 | alunos = webpage.students.all() |
467 | - visualizou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos)).distinct("user_email") | |
467 | + vis_ou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos)) | |
468 | + did,n_did,history = str(_("Users who viewed")),str(_("Users who did not viewed")),str(_("History")) | |
468 | 469 | re = [] |
469 | - c_visualizou = visualizou.count() | |
470 | - did,n_did = str(_("Did")),str(_("Did not")) | |
471 | - re.append(['Webpage',did,n_did]) | |
472 | - re.append(['View',c_visualizou, alunos.count() - c_visualizou]) | |
470 | + data = [] | |
471 | + column = [] | |
472 | + column.append([str(_("User")),"string"]) | |
473 | + column.append([str(_("Group")),"string"]) | |
474 | + | |
475 | + if parameter == did: | |
476 | + from django.db.models import Count, Max | |
477 | + views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | |
478 | + date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | |
479 | + column.append([str(_("Number of views")),"string"]) | |
480 | + column.append([str(_("Date of last view")),"date"]) | |
481 | + for i in range(0,len(views_user)): | |
482 | + data.append([str(alunos.get(email=views_user[i].get("user_email"))), | |
483 | + ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=views_user[i].get("user_email"))]), | |
484 | + views_user[i].get("views"),date_last.get(user_email=views_user[i].get("user_email")).get("last")]) | |
485 | + elif parameter == n_did: | |
486 | + not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | |
487 | + for alun in not_view: | |
488 | + data.append([str(alun),", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=alun.email)])]) | |
489 | + | |
490 | + else: | |
491 | + column.append([str(_("Action")),"string"]) | |
492 | + column.append([str(_("Date of action")),"date"]) | |
493 | + for log_al in vis_ou.order_by("datetime"): | |
494 | + data.append([str(alunos.get(email=log_al.user_email)), | |
495 | + ", ".join([str(x) for x in webpage.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | |
496 | + log_al.action,log_al.datetime]) | |
497 | + | |
498 | + | |
499 | + c_visualizou = vis_ou.distinct("user_email").count() | |
500 | + re.append([str(_('Webpage')),did,n_did]) | |
501 | + re.append([str(_('View')),c_visualizou, alunos.count() - c_visualizou]) | |
473 | 502 | context['topic'] = webpage.topic |
474 | 503 | context['subject'] = webpage.topic.subject |
475 | 504 | context['db_data'] = re |
476 | 505 | context['title_chart'] = _('Students viewing the web conference') |
477 | 506 | context['title_vAxis'] = _('Quantity') |
478 | - data = [] | |
479 | - if not parameter == n_did: | |
480 | - for a in visualizou: | |
481 | - data.append([str(alunos.get(email=a.user_email)),a.user_email,a.action,a.datetime]) | |
482 | - | |
483 | - if not parameter == did: | |
484 | - alunos = alunos.exclude(email__in=(log.user_email for log in visualizou)) | |
485 | - for a in alunos: | |
486 | - data.append([str(a),a.email,None,None]) | |
487 | - | |
507 | + # data = [] | |
508 | + # if not parameter == n_did: | |
509 | + # for a in vis_ou.distinct("user_email"): | |
510 | + # data.append([str(alunos.get(email=a.user_email)),a.user_email,a.action,a.datetime]) | |
511 | + # | |
512 | + # if not parameter == did: | |
513 | + # alunos = alunos.exclude(email__in=(log.user_email for log in vis_ou.distinct("user_email"))) | |
514 | + # for a in alunos: | |
515 | + # data.append([str(a),a.email,None,None]) | |
516 | + print (column, "column\n\n") | |
517 | + context["column"] = column | |
518 | + print (data, "data\n\n") | |
488 | 519 | context["history"] = data |
489 | - context["title_table"] = _("History") | |
520 | + context["title_table"] = history | |
521 | + context["n_did_table"] = n_did | |
522 | + context["out_history"] = False | |
490 | 523 | if parameter == did: |
491 | 524 | context["title_table"] = did |
525 | + context["out_history"] = True | |
492 | 526 | elif parameter == n_did: |
493 | 527 | context["title_table"] = n_did |
528 | + context["out_history"] = True | |
494 | 529 | return context | ... | ... |