diff --git a/app/db_queries.py b/app/db_queries.py index 656bbda..0363896 100644 --- a/app/db_queries.py +++ b/app/db_queries.py @@ -3,6 +3,7 @@ from django.conf import settings from django.db import connection from django.utils.translation import gettext +from calendar import day_name COMBINE_ALPHABET = "abcdefghijklmnopqrstuvwxyz" @@ -102,29 +103,34 @@ def orders_per_month(user) -> list: group by "month" order by "month" desc; """) - return _combine_results([result_user, result_all]) + return _combine_results([result_all, result_user]) def orders_per_weekday(user) -> list: # number of orders per weekday (all time) - result_user = _db_select(f""" - select - to_char(datetime, 'Day') as "day", - sum(amount) as "count" - from app_order - where user_id = {user.pk} - group by "day" - order by "count" desc; + result = _db_select(f""" + with q_all as ( + select + extract(isodow from datetime) as "d", + sum(amount) as "c" + from app_order + group by d + ), q_user as ( + select + extract(isodow from datetime) as "d", + sum(amount) as "c" + from app_order + where user_id = {user.pk} + group by d + ) + select q_all.d as "day", q_all.c, q_user.c from q_all full join q_user on q_all.d = q_user.d + group by day, q_all.c, q_user.c + order by day asc; """) - result_all = _db_select(f""" - select - to_char(datetime, 'Day') as "day", - sum(amount) as "count" - from app_order - group by "day" - order by "count" desc; - """) - return _combine_results([result_user, result_all]) + for i in range(len(result)): + day_, all_, user_ = result[i] + result[i] = (day_name[int(day_)-1], all_, user_) + return result def orders_per_drink(user) -> list: @@ -148,4 +154,4 @@ def orders_per_drink(user) -> list: group by d.product_name order by "data" desc; """) - return _combine_results([result_user, result_all]) + return _combine_results([result_all, result_user]) diff --git a/app/locales/de/LC_MESSAGES/django.mo b/app/locales/de/LC_MESSAGES/django.mo index d7435cb..73d1c71 100644 Binary files a/app/locales/de/LC_MESSAGES/django.mo and b/app/locales/de/LC_MESSAGES/django.mo differ diff --git a/app/locales/de/LC_MESSAGES/django.po b/app/locales/de/LC_MESSAGES/django.po index fe0dc95..3bfbdb5 100644 --- a/app/locales/de/LC_MESSAGES/django.po +++ b/app/locales/de/LC_MESSAGES/django.po @@ -170,8 +170,8 @@ msgid "Statistics" msgstr "Statistiken" #: app/templates/statistics.html:13 -msgid "Orders per drink" -msgstr "Bestellungen pro Getränk" +msgid "orders / drink" +msgstr "Bestellungen / Getränk" #: app/templates/statistics.html:16 msgid "drink" @@ -188,16 +188,16 @@ msgid "all" msgstr "Alle" #: app/templates/statistics.html:30 -msgid "Orders per month (last 12 months)" -msgstr "Bestellungen pro Monat (letzte 12 Monate)" +msgid "orders / month" +msgstr "Bestellungen / Monat" #: app/templates/statistics.html:33 msgid "month" msgstr "Monat" #: app/templates/statistics.html:47 -msgid "Orders per weekday" -msgstr "Bestellungen pro Wochentag" +msgid "orders / weekday" +msgstr "Bestellungen / Wochentag" #: app/templates/statistics.html:50 msgid "day" diff --git a/app/static/css/main.css b/app/static/css/main.css index ab3f24a..0387a51 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -507,6 +507,23 @@ main { padding: .8rem 1.1rem; } +/* Statistics */ + +.statistics-container { + display: flex; + flex-direction: row; + align-items: flex-start; + justify-content: center; + flex-wrap: wrap; + max-width: 90vw; + gap: 1rem; +} + +.statistics-container > div { + height: 100%; + width: 16rem; +} + /* Responsive */ @media only screen and (max-width: 1200px) { diff --git a/app/templates/statistics.html b/app/templates/statistics.html index 4f938b9..0c1e6e7 100644 --- a/app/templates/statistics.html +++ b/app/templates/statistics.html @@ -8,14 +8,14 @@ {% block content %}

{% translate "Statistics" %}

-
-
-

{% translate "Orders per drink" %}

+
+
+

{% translate "orders / drink" %}

- + {% for key, values in orders_per_drink.items %} @@ -26,13 +26,13 @@ {% endfor %}
{% translate "drink" %}{% translate "you" %} {% translate "all" %}{% translate "you" %}
-
-

{% translate "Orders per month (last 12 months)" %}

+
+

{% translate "orders / month" %}

- + {% for key, values in orders_per_month.items %} @@ -43,19 +43,19 @@ {% endfor %}
{% translate "month" %}{% translate "you" %} {% translate "all" %}{% translate "you" %}
-
-

{% translate "Orders per weekday" %}

+
+

{% translate "orders / weekday" %}

- + - {% for key, values in orders_per_weekday.items %} + {% for values in orders_per_weekday %} - - - + + + {% endfor %}
{% translate "day" %}{% translate "you" %} {% translate "all" %}{% translate "you" %}
{{ key }}{{ values.a|default:"0" }}{{ values.b|default:"0" }}{{ values.0 }}{{ values.1|default:"0" }}{{ values.2|default:"0" }}