Added projected year count and weekly average in home screen

This commit is contained in:
Claudio Maggioni 2019-08-09 14:27:13 +02:00
parent 2680e485cd
commit 81d3376d7c
3 changed files with 32 additions and 13 deletions

View File

@ -16,6 +16,10 @@
<div class="card-panel grey lighten-2">
<h5 class="center">{% trans "Arrows shot this year:" %}</h5>
<p class="center"><strong style="font-size: 2.7rem">{{ yearArrows }}</strong></p>
<h6 class="center">{% trans "Projected number of arrows at the end of the year:" %}</h6>
<p class="center"><strong style="font-size: 2rem">{{ projectedYearArrows }}</strong></p>
<h6 class="center">{% trans "Weekly average:" %}</h6>
<p class="center"><strong style="font-size: 2rem">{{ weeklyAverage }}</strong></p>
</div>
{% if diffTarget is not False %}
<div class="card-panel lighten-2 {% if diffTarget < 0 %}red{% elif diffTarget is 0 %}yellow

View File

@ -36,11 +36,15 @@ def index(request):
.aggregate(s=Sum('count'))
yearArrows = yearArrows['s'] if yearArrows['s'] is not None else 0
day_number = now.timetuple().tm_yday
week_number = now.isocalendar()[1]
days_this_year = (date(now.year + 1, 1, 1) - \
date(now.year, 1, 1)).days
diff_target = False
try:
target = Target.objects.get(user=request.user).target
days_this_year = (date(now.year + 1, 1, 1) - date(now.year, 1, 1)).days
diff_target = round(yearArrows - (now.timetuple().tm_yday / days_this_year) * \
diff_target = round(yearArrows - (day_number / days_this_year) * \
target)
except Target.DoesNotExist:
pass
@ -59,7 +63,10 @@ def index(request):
'yearArrows': yearArrows,
'monthArrows': 0 if monthArrows['s'] is None else monthArrows['s'],
'weekArrows': 0 if weekArrows['s'] is None else weekArrows['s'],
'diffTarget': diff_target
'diffTarget': diff_target,
'weeklyAverage': round(yearArrows / week_number, 2),
'projectedYearArrows': math.floor(yearArrows * days_this_year /
day_number)
}
return render(request, 'index.html', context)
else:

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Arrowcounter\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-06 14:44+0200\n"
"POT-Creation-Date: 2019-08-09 14:25+0200\n"
"PO-Revision-Date: 2019-07-27 13:00+0200\n"
"Last-Translator: Claudio Maggioni <maggicl@kolabnow.ch>\n"
"Language-Team: Claudio Maggioni <maggicl@kolabnow.ch>\n"
@ -130,15 +130,23 @@ msgstr "Home"
msgid "Arrows shot this year:"
msgstr "Frecce tirate quest'anno:"
#: counter/templates/index.html:23
#: counter/templates/index.html:19
msgid "Projected number of arrows at the end of the year:"
msgstr "Totale frecce proiettato alla fine dell'anno:"
#: counter/templates/index.html:21
msgid "Weekly average:"
msgstr "Media settimanale:"
#: counter/templates/index.html:27
msgid "Difference with target:"
msgstr "Differenza rispetto all'obiettivo:"
#: counter/templates/index.html:28
#: counter/templates/index.html:32
msgid "Arrows shot this month:"
msgstr "Frecce tirate questo mese:"
#: counter/templates/index.html:32
#: counter/templates/index.html:36
msgid "Arrows shot this week:"
msgstr "Frecce tirate questa settimana:"
@ -185,27 +193,27 @@ msgstr "Frecce tirate quest'anno"
msgid "Remove"
msgstr "Rimuovi"
#: counter/views.py:127
#: counter/views.py:134
msgid "page is negative or 0"
msgstr "pagina negativa o uguale a 0"
#: counter/views.py:221
#: counter/views.py:228
msgid "ArrowCount instance not found or from different user"
msgstr "istanza ArrowCount non trovata o appartenente ad altro utente"
#: counter/views.py:233
#: counter/views.py:240
msgid "mode not valid"
msgstr "campo 'mode' non valido"
#: counter/views.py:242
#: counter/views.py:249
msgid "value field is not a number"
msgstr "il campo 'value' non è un numero"
#: counter/views.py:258
#: counter/views.py:265
msgid "count is negative or 0"
msgstr "count è negativo o uguale a 0"
#: counter/views.py:266
#: counter/views.py:273
msgid "count too big"
msgstr "conteggio troppo alto"