From 9dbbd3d48e6e27366d12fdbc1510b4e0bf50e074 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 28 Dec 2023 15:46:52 +0100 Subject: [PATCH] Add monthly year chart --- .../locale/fr_FR/LC_MESSAGES/django.mo | Bin 454 -> 490 bytes .../locale/fr_FR/LC_MESSAGES/django.po | 6 ++- nummi/history/templates/history/plot.html | 39 ++++++++++++++++++ nummi/history/utils.py | 29 +++++++++++-- nummi/main/static/main/css/plot.css | 25 +++++++++++ 5 files changed, 95 insertions(+), 4 deletions(-) diff --git a/nummi/history/locale/fr_FR/LC_MESSAGES/django.mo b/nummi/history/locale/fr_FR/LC_MESSAGES/django.mo index c369f8dc5a4f3023676a06c1e9925a36ca66799f..cdfe26fffdcf15c1ca75914eaed79c8fc4615fe2 100644 GIT binary patch delta 159 zcmX@c{EE5$o)F7a1|VPsVi_QI0b+I_&H-W&=m264AnpWWHXxn^#2~dZftUq|=L4}i zBLl+{Ak7KHXMk*w{%b%QB!3S`gY-QH(m(_T%s>)k1`|jMq=;c+t`tjTYGTpGHU~y_ L$Gp75D^nQ&ROS-} delta 144 zcmaFGe2lsNo)F7a1|VPoVi_Q|0b*7ljsap2C;(y(AT9)AHXyD7Vvu|z5UVpXFth_{ zP9R\n" "Language-Team: \n" @@ -28,3 +28,7 @@ msgstr "Dépenses" #: .\history\templates\history\plot.html:17 msgid "Income" msgstr "Revenus" + +#: .\history\templates\history\plot.html:68 +msgid "Year" +msgstr "Année" diff --git a/nummi/history/templates/history/plot.html b/nummi/history/templates/history/plot.html index 43d94ef..cba9e18 100644 --- a/nummi/history/templates/history/plot.html +++ b/nummi/history/templates/history/plot.html @@ -61,3 +61,42 @@ +
+ + + + + + + + + + + + + + + + + + + + {% spaceless %} + {% for year in history.years %} + + + {% for m in year.d %} + {% if m %} + + {% else %} + + {% endif %} + {% endfor %} + + {% endfor %} + {% endspaceless %} + +
{% translate "Year" %}010203040506070809101112
{{ year.y }} +
+
diff --git a/nummi/history/utils.py b/nummi/history/utils.py index ef0a353..adf1c35 100644 --- a/nummi/history/utils.py +++ b/nummi/history/utils.py @@ -1,6 +1,8 @@ +import datetime + from django.db import models from django.db.models import Func, Max, Min, Q, Sum, Value -from django.db.models.functions import Now, TruncMonth +from django.db.models.functions import Abs, Now, TruncMonth class GenerateMonth(Func): @@ -22,11 +24,17 @@ def history(transaction_set): ) ) .annotate( - sum_m=Value(0), sum_p=Value(0), sum=Value(0), has_transactions=Value(0) + sum_m=Value(0), + sum_p=Value(0), + sum=Value(0), + has_transactions=Value(0), ) .difference( _transaction_month.annotate( - sum_m=Value(0), sum_p=Value(0), sum=Value(0), has_transactions=Value(0) + sum_m=Value(0), + sum_p=Value(0), + sum=Value(0), + has_transactions=Value(0), ) ) ) @@ -39,10 +47,25 @@ def history(transaction_set): return { "data": _history.union(_months).order_by("-month"), + "years": [ + { + "y": y, + "d": [ + _history.filter(month=datetime.date(y, m + 1, 1)).first() + for m in range(12) + ], + } + for y in range( + _transaction_month.first()["month"].year, + _transaction_month.last()["month"].year - 1, + -1, + ) + ], "max": max( _history.aggregate( max=Max("sum_p", default=0), min=-Min("sum_m", default=0), ).values(), ), + "years_max": _history.aggregate(max=Max(Abs("sum")))["max"], } diff --git a/nummi/main/static/main/css/plot.css b/nummi/main/static/main/css/plot.css index 15fc7ab..a55a06f 100644 --- a/nummi/main/static/main/css/plot.css +++ b/nummi/main/static/main/css/plot.css @@ -74,3 +74,28 @@ table.full-width col.bar { .plot tfoot { background: var(--bg-01); } + +.calendar { + margin-top: var(--gap); +} +.calendar .p { + background: var(--green); +} +.calendar .o-0 { + opacity: 0.1; +} +.calendar .o-1 { + opacity: 0.5; +} +.calendar .o-2 { + opacity: 0.75; +} +.calendar .o-3 { + opacity: 0.9; +} +.calendar .o-4 { + opacity: 1; +} +.calendar .m { + background: var(--red); +}