Release 19 (devel -> main) #42

Merged
ChaoticByte merged 5 commits from devel into main 2023-11-01 18:23:56 +00:00
5 changed files with 62 additions and 39 deletions
Showing only changes of commit 31ae251164 - Show all commits

View file

@ -3,6 +3,7 @@
from django.conf import settings from django.conf import settings
from django.db import connection from django.db import connection
from django.utils.translation import gettext from django.utils.translation import gettext
from calendar import day_name
COMBINE_ALPHABET = "abcdefghijklmnopqrstuvwxyz" COMBINE_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
@ -102,29 +103,34 @@ def orders_per_month(user) -> list:
group by "month" group by "month"
order by "month" desc; order by "month" desc;
""") """)
return _combine_results([result_user, result_all]) return _combine_results([result_all, result_user])
def orders_per_weekday(user) -> list: def orders_per_weekday(user) -> list:
# number of orders per weekday (all time) # number of orders per weekday (all time)
result_user = _db_select(f""" result = _db_select(f"""
select with q_all as (
to_char(datetime, 'Day') as "day", select
sum(amount) as "count" extract(isodow from datetime) as "d",
from app_order sum(amount) as "c"
where user_id = {user.pk} from app_order
group by "day" group by d
order by "count" desc; ), 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""" for i in range(len(result)):
select day_, all_, user_ = result[i]
to_char(datetime, 'Day') as "day", result[i] = (day_name[int(day_)-1], all_, user_)
sum(amount) as "count" return result
from app_order
group by "day"
order by "count" desc;
""")
return _combine_results([result_user, result_all])
def orders_per_drink(user) -> list: def orders_per_drink(user) -> list:
@ -148,4 +154,4 @@ def orders_per_drink(user) -> list:
group by d.product_name group by d.product_name
order by "data" desc; order by "data" desc;
""") """)
return _combine_results([result_user, result_all]) return _combine_results([result_all, result_user])

Binary file not shown.

View file

@ -170,8 +170,8 @@ msgid "Statistics"
msgstr "Statistiken" msgstr "Statistiken"
#: app/templates/statistics.html:13 #: app/templates/statistics.html:13
msgid "Orders per drink" msgid "orders / drink"
msgstr "Bestellungen pro Getränk" msgstr "Bestellungen / Getränk"
#: app/templates/statistics.html:16 #: app/templates/statistics.html:16
msgid "drink" msgid "drink"
@ -188,16 +188,16 @@ msgid "all"
msgstr "Alle" msgstr "Alle"
#: app/templates/statistics.html:30 #: app/templates/statistics.html:30
msgid "Orders per month (last 12 months)" msgid "orders / month"
msgstr "Bestellungen pro Monat (letzte 12 Monate)" msgstr "Bestellungen / Monat"
#: app/templates/statistics.html:33 #: app/templates/statistics.html:33
msgid "month" msgid "month"
msgstr "Monat" msgstr "Monat"
#: app/templates/statistics.html:47 #: app/templates/statistics.html:47
msgid "Orders per weekday" msgid "orders / weekday"
msgstr "Bestellungen pro Wochentag" msgstr "Bestellungen / Wochentag"
#: app/templates/statistics.html:50 #: app/templates/statistics.html:50
msgid "day" msgid "day"

View file

@ -507,6 +507,23 @@ main {
padding: .8rem 1.1rem; 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 */ /* Responsive */
@media only screen and (max-width: 1200px) { @media only screen and (max-width: 1200px) {

View file

@ -8,14 +8,14 @@
{% block content %} {% block content %}
<h1>{% translate "Statistics" %}</h1> <h1>{% translate "Statistics" %}</h1>
<div> <div class="statistics-container">
<div class="flex flex-column flex-center"> <div class="flex flex-column">
<h3>{% translate "Orders per drink" %}</h3> <h3>{% translate "orders / drink" %}</h3>
<table> <table>
<tr> <tr>
<th>{% translate "drink" %}</th> <th>{% translate "drink" %}</th>
<th>{% translate "you" %}</th>
<th>{% translate "all" %}</th> <th>{% translate "all" %}</th>
<th>{% translate "you" %}</th>
</tr> </tr>
{% for key, values in orders_per_drink.items %} {% for key, values in orders_per_drink.items %}
<tr> <tr>
@ -26,13 +26,13 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
<div class="flex flex-column flex-center"> <div class="flex flex-column">
<h3>{% translate "Orders per month (last 12 months)" %}</h3> <h3>{% translate "orders / month" %}</h3>
<table> <table>
<tr> <tr>
<th>{% translate "month" %}</th> <th>{% translate "month" %}</th>
<th>{% translate "you" %}</th>
<th>{% translate "all" %}</th> <th>{% translate "all" %}</th>
<th>{% translate "you" %}</th>
</tr> </tr>
{% for key, values in orders_per_month.items %} {% for key, values in orders_per_month.items %}
<tr> <tr>
@ -43,19 +43,19 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
<div class="flex flex-column flex-center"> <div class="flex flex-column">
<h3>{% translate "Orders per weekday" %}</h3> <h3>{% translate "orders / weekday" %}</h3>
<table> <table>
<tr> <tr>
<th>{% translate "day" %}</th> <th>{% translate "day" %}</th>
<th>{% translate "you" %}</th>
<th>{% translate "all" %}</th> <th>{% translate "all" %}</th>
<th>{% translate "you" %}</th>
</tr> </tr>
{% for key, values in orders_per_weekday.items %} {% for values in orders_per_weekday %}
<tr> <tr>
<td>{{ key }}</td> <td>{{ values.0 }}</td>
<td>{{ values.a|default:"0" }}</td> <td>{{ values.1|default:"0" }}</td>
<td>{{ values.b|default:"0" }}</td> <td>{{ values.2|default:"0" }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>