From 2680e485cd6a39cca1e57b54fc703db1066e7f6e Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Tue, 6 Aug 2019 14:51:29 +0200 Subject: [PATCH] Added better stats page and tweaked css --- counter/static/css/main.css | 19 ++++ counter/static/js/weeklystats.js | 153 +++++++++++++++++++++++++------ counter/templates/base.html | 2 +- counter/templates/menu.html | 2 +- counter/templates/stats.html | 32 +++++-- counter/views.py | 15 ++- locale/it/LC_MESSAGES/django.po | 31 +++++-- 7 files changed, 206 insertions(+), 48 deletions(-) diff --git a/counter/static/css/main.css b/counter/static/css/main.css index 4ce5cd1..d20b991 100644 --- a/counter/static/css/main.css +++ b/counter/static/css/main.css @@ -140,3 +140,22 @@ form .card-action button { .inline-block { display: inline-block; } + +.chart.scrollable.wrapper { + overflow-x: scroll; +} + +.chart.wrapper { + position: relative; + max-width: 100%; + height: 25em; +} + +.chart.area-wrapper { + height: 100%; +} + +.chart-title { + margin-top: 0; + margin-bottom: 2rem; +} diff --git a/counter/static/js/weeklystats.js b/counter/static/js/weeklystats.js index 3f1d3b8..481d8f9 100644 --- a/counter/static/js/weeklystats.js +++ b/counter/static/js/weeklystats.js @@ -1,43 +1,144 @@ 'use strict'; // vim: set ts=2 sw=2 tw=80 et: -$(document).ready(function() { - var data = JSON.parse($('#data').text()), - format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT')); - var chart = $('#chart'); - var labels = [], dataset = []; +/** + * Given an id of a ` + - - - + + + {% endblock %} {% block content %} -

{% trans "Weekly stats" %}

- +

{% trans "Stats" %}

+
+

{% trans "Arrows shot by week" %}

+
+
+ +
+
+
+
+

{% trans "Arrows shot this year" %}

+
+ +
+
{% endblock %} diff --git a/counter/views.py b/counter/views.py index de5e743..fdd5b70 100644 --- a/counter/views.py +++ b/counter/views.py @@ -12,7 +12,7 @@ from django.conf import settings from django.core.exceptions import SuspiciousOperation from django.utils.translation import gettext as _ from django.db.models.functions import Extract, ExtractWeek -from django.db.models import Sum +from django.db.models import Sum, Func from datetime import datetime, timedelta, date import json from django.core.serializers.json import DjangoJSONEncoder @@ -76,12 +76,23 @@ def count_stats(request): .annotate(sum_count=Sum('count')) \ .order_by('-isoyear', '-week') + incArrows = ArrowCount.objects \ + .filter(user = request.user) \ + .filter(date__gte = date(datetime.today().year, 1, 1)) \ + .annotate(count_inc=Func( + Sum('count'), + template='%(expressions)s OVER (ORDER BY %(order_by)s)', + order_by="date" + )).values('date', 'count_inc') \ + .order_by('date') + for w in weeklyArrows: w['weekStarts'] = tofirstdayinisoweek(w['isoyear'], w['week']) w['weekEnds'] = w['weekStarts'] + timedelta(days=6) return render(request, 'stats.html', { - 'weeklyArrows': json.dumps(list(weeklyArrows), cls=DjangoJSONEncoder) + 'data_weekly': json.dumps(list(weeklyArrows), cls=DjangoJSONEncoder), + 'data_cumulative': json.dumps(list(incArrows), cls=DjangoJSONEncoder) }) @login_required diff --git a/locale/it/LC_MESSAGES/django.po b/locale/it/LC_MESSAGES/django.po index b8f0810..c2c5c56 100644 --- a/locale/it/LC_MESSAGES/django.po +++ b/locale/it/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Arrowcounter\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 15:54+0200\n" +"POT-Creation-Date: 2019-08-06 14:44+0200\n" "PO-Revision-Date: 2019-07-27 13:00+0200\n" "Last-Translator: Claudio Maggioni \n" "Language-Team: Claudio Maggioni \n" @@ -148,9 +148,9 @@ msgid "Set yearly target" msgstr "Imposta obiettivo annuale" #: counter/templates/menu.html:21 counter/templates/stats.html:7 -#: counter/templates/stats.html:20 -msgid "Weekly stats" -msgstr "Statistiche settimanali" +#: counter/templates/stats.html:23 +msgid "Stats" +msgstr "Statistiche" #: counter/templates/menu.html:24 msgid "Admin" @@ -173,30 +173,41 @@ msgstr "Accedi" msgid "Register" msgstr "Registrati" +#: counter/templates/stats.html:25 +msgid "Arrows shot by week" +msgstr "Frecce tirate questa settimana" + +#: counter/templates/stats.html:33 +msgid "Arrows shot this year" +msgstr "Frecce tirate quest'anno" + #: counter/templates/target/edit.html:22 msgid "Remove" msgstr "Rimuovi" -#: counter/views.py:116 +#: counter/views.py:127 msgid "page is negative or 0" msgstr "pagina negativa o uguale a 0" -#: counter/views.py:210 +#: counter/views.py:221 msgid "ArrowCount instance not found or from different user" msgstr "istanza ArrowCount non trovata o appartenente ad altro utente" -#: counter/views.py:222 +#: counter/views.py:233 msgid "mode not valid" msgstr "campo 'mode' non valido" -#: counter/views.py:231 +#: counter/views.py:242 msgid "value field is not a number" msgstr "il campo 'value' non è un numero" -#: counter/views.py:247 +#: counter/views.py:258 msgid "count is negative or 0" msgstr "count è negativo o uguale a 0" -#: counter/views.py:255 +#: counter/views.py:266 msgid "count too big" msgstr "conteggio troppo alto" + +#~ msgid "Weekly stats" +#~ msgstr "Statistiche settimanali"