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.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])

Binary file not shown.

View file

@ -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"

View file

@ -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) {

View file

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