Release 19 (devel -> main)
See merge request ChaoticByte/drinks-manager!18
This commit is contained in:
commit
4ad23c5db0
8 changed files with 175 additions and 75 deletions
|
@ -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"
|
||||||
|
@ -15,7 +16,6 @@ def _db_select(sql_select:str):
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _combine_results(results:list) -> dict:
|
def _combine_results(results:list) -> dict:
|
||||||
'''
|
'''
|
||||||
e.g.
|
e.g.
|
||||||
|
@ -80,8 +80,7 @@ def select_history(user, language_code="en") -> list:
|
||||||
result = [list(row) for row in result]
|
result = [list(row) for row in result]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def select_orders_per_month(user) -> dict:
|
||||||
def orders_per_month(user) -> list:
|
|
||||||
# number of orders per month (last 12 months)
|
# number of orders per month (last 12 months)
|
||||||
result_user = _db_select(f"""
|
result_user = _db_select(f"""
|
||||||
select
|
select
|
||||||
|
@ -102,32 +101,35 @@ 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 select_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 select_orders_per_drink(user) -> dict:
|
||||||
def orders_per_drink(user) -> list:
|
|
||||||
# number of orders per drink (all time)
|
# number of orders per drink (all time)
|
||||||
result_user = _db_select(f"""
|
result_user = _db_select(f"""
|
||||||
select
|
select
|
||||||
|
@ -148,4 +150,31 @@ 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])
|
||||||
|
|
||||||
|
def select_order_sum_per_user_all_users() -> list:
|
||||||
|
# sum of all orders per user, for all users
|
||||||
|
result = _db_select(f"""
|
||||||
|
select
|
||||||
|
app_user.username as user,
|
||||||
|
sum(app_order.price_sum) as sum
|
||||||
|
from app_user
|
||||||
|
left outer join app_order on (app_user.id = app_order.user_id)
|
||||||
|
group by app_user.id
|
||||||
|
order by app_user asc;
|
||||||
|
""")
|
||||||
|
return result
|
||||||
|
|
||||||
|
def select_deposit_sum_per_user_all_users() -> list:
|
||||||
|
# sum of all orders per user, for all users
|
||||||
|
result = _db_select(f"""
|
||||||
|
select
|
||||||
|
app_user.username as user,
|
||||||
|
sum(rt.transaction_sum) as sum
|
||||||
|
from app_user
|
||||||
|
left outer join app_registertransaction rt on (app_user.id = rt.user_id)
|
||||||
|
where rt.is_user_deposit is true or rt.is_user_deposit is null
|
||||||
|
group by app_user.id
|
||||||
|
order by app_user asc;
|
||||||
|
""")
|
||||||
|
return result
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2023-04-14 23:37+0200\n"
|
"POT-Creation-Date: 2023-11-01 18:52+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: Julian Müller (ChaoticByte)\n"
|
"Last-Translator: Julian Müller (ChaoticByte)\n"
|
||||||
"Language: DE\n"
|
"Language: DE\n"
|
||||||
|
@ -55,7 +55,7 @@ msgstr "Bestätigen"
|
||||||
msgid "Drinks - History"
|
msgid "Drinks - History"
|
||||||
msgstr "Getränke - Verlauf"
|
msgstr "Getränke - Verlauf"
|
||||||
|
|
||||||
#: app/templates/history.html:10 app/templates/userpanel.html:25
|
#: app/templates/history.html:10 app/templates/userpanel.html:23
|
||||||
msgid "History"
|
msgid "History"
|
||||||
msgstr "Verlauf"
|
msgstr "Verlauf"
|
||||||
|
|
||||||
|
@ -165,49 +165,57 @@ msgstr "Wähle deinen Account"
|
||||||
msgid "Drinks - Statistics"
|
msgid "Drinks - Statistics"
|
||||||
msgstr "Getränke - Statistiken"
|
msgstr "Getränke - Statistiken"
|
||||||
|
|
||||||
#: app/templates/statistics.html:10 app/templates/userpanel.html:26
|
#: app/templates/statistics.html:10 app/templates/userpanel.html:24
|
||||||
msgid "Statistics"
|
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"
|
||||||
msgstr "Getränk"
|
msgstr "Getränk"
|
||||||
|
|
||||||
#: app/templates/statistics.html:17 app/templates/statistics.html:34
|
#: app/templates/statistics.html:17 app/templates/statistics.html:36
|
||||||
#: app/templates/statistics.html:51
|
#: app/templates/statistics.html:53
|
||||||
msgid "you"
|
|
||||||
msgstr "Du"
|
|
||||||
|
|
||||||
#: app/templates/statistics.html:18 app/templates/statistics.html:35
|
|
||||||
#: app/templates/statistics.html:52
|
|
||||||
msgid "all"
|
msgid "all"
|
||||||
msgstr "Alle"
|
msgstr "Alle"
|
||||||
|
|
||||||
#: app/templates/statistics.html:30
|
#: app/templates/statistics.html:18 app/templates/statistics.html:37
|
||||||
msgid "Orders per month (last 12 months)"
|
#: app/templates/statistics.html:54
|
||||||
msgstr "Bestellungen pro Monat (letzte 12 Monate)"
|
msgid "you"
|
||||||
|
msgstr "Du"
|
||||||
|
|
||||||
#: app/templates/statistics.html:33
|
#: app/templates/statistics.html:32
|
||||||
|
msgid "orders / month"
|
||||||
|
msgstr "Bestellungen / Monat"
|
||||||
|
|
||||||
|
#: app/templates/statistics.html:35
|
||||||
msgid "month"
|
msgid "month"
|
||||||
msgstr "Monat"
|
msgstr "Monat"
|
||||||
|
|
||||||
#: app/templates/statistics.html:47
|
#: app/templates/statistics.html:49
|
||||||
msgid "Orders per weekday"
|
msgid "orders / weekday"
|
||||||
msgstr "Bestellungen pro Wochentag"
|
msgstr "Bestellungen / Wochentag"
|
||||||
|
|
||||||
#: app/templates/statistics.html:50
|
#: app/templates/statistics.html:52
|
||||||
msgid "day"
|
msgid "day"
|
||||||
msgstr "Tag"
|
msgstr "Tag"
|
||||||
|
|
||||||
|
#: app/templates/statistics.html:69
|
||||||
|
msgid "order sum"
|
||||||
|
msgstr "Bestellungen"
|
||||||
|
|
||||||
|
#: app/templates/statistics.html:86
|
||||||
|
msgid "deposit sum"
|
||||||
|
msgstr "Einzahlungen"
|
||||||
|
|
||||||
#: app/templates/supply.html:7
|
#: app/templates/supply.html:7
|
||||||
msgid "Drinks - Supply"
|
msgid "Drinks - Supply"
|
||||||
msgstr "Getränke - Beschaffung"
|
msgstr "Getränke - Beschaffung"
|
||||||
|
|
||||||
#: app/templates/supply.html:14 app/templates/userpanel.html:32
|
#: app/templates/supply.html:14 app/templates/userpanel.html:30
|
||||||
msgid "Supply"
|
msgid "Supply"
|
||||||
msgstr "Beschaffung"
|
msgstr "Beschaffung"
|
||||||
|
|
||||||
|
@ -228,7 +236,6 @@ msgid "You are not allowed to view this site."
|
||||||
msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen."
|
msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen."
|
||||||
|
|
||||||
#: app/templates/transfer.html:6
|
#: app/templates/transfer.html:6
|
||||||
#| msgid "Drinks - Order"
|
|
||||||
msgid "Drinks - Transfer"
|
msgid "Drinks - Transfer"
|
||||||
msgstr "Getränke - Geld senden"
|
msgstr "Getränke - Geld senden"
|
||||||
|
|
||||||
|
@ -248,11 +255,11 @@ msgstr "Saldo"
|
||||||
msgid "Logout"
|
msgid "Logout"
|
||||||
msgstr "Abmelden"
|
msgstr "Abmelden"
|
||||||
|
|
||||||
#: app/templates/userpanel.html:30
|
#: app/templates/userpanel.html:28
|
||||||
msgid "Transfer"
|
msgid "Transfer"
|
||||||
msgstr "Geld senden"
|
msgstr "Geld senden"
|
||||||
|
|
||||||
#: app/templates/userpanel.html:34
|
#: app/templates/userpanel.html:32
|
||||||
msgid "Change Password"
|
msgid "Change Password"
|
||||||
msgstr "Passwort ändern"
|
msgstr "Passwort ändern"
|
||||||
|
|
||||||
|
|
|
@ -97,11 +97,12 @@ table {
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
tr {
|
tr > th,
|
||||||
|
tr > td {
|
||||||
background: var(--bg-color);
|
background: var(--bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:nth-child(2n+2) {
|
tr:nth-child(2n+2) > td {
|
||||||
background: var(--bg-color2);
|
background: var(--bg-color2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,6 +508,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) {
|
||||||
|
|
|
@ -8,57 +8,96 @@
|
||||||
|
|
||||||
{% 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>
|
||||||
<td>{{ key }}</td>
|
<td>{{ key }}</td>
|
||||||
<td>{{ values.a|default:"0" }}</td>
|
<td>{{ values.a|default:0 }}</td>
|
||||||
<td>{{ values.b|default:"0" }}</td>
|
<td>{{ values.b|default:0 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-column flex-center">
|
</div>
|
||||||
<h3>{% translate "Orders per month (last 12 months)" %}</h3>
|
<div class="statistics-container">
|
||||||
|
<div class="flex flex-column">
|
||||||
|
<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>
|
||||||
<td>{{ key }}</td>
|
<td>{{ key }}</td>
|
||||||
<td>{{ values.a|default:"0" }}</td>
|
<td>{{ values.a|default:0 }}</td>
|
||||||
<td>{{ values.b|default:"0" }}</td>
|
<td>{{ values.b|default:0 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% 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>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="statistics-container">
|
||||||
|
{% if user.is_superuser or perms.app.view_order %}
|
||||||
|
<div class="flex flex-column">
|
||||||
|
<h3>{% translate "order sum" %}</h3>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>{% translate "user" %}</th>
|
||||||
|
<th>{% translate "sum" %}</th>
|
||||||
|
</tr>
|
||||||
|
{% for values in order_sum_per_user %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ values.0 }}</td>
|
||||||
|
<td>{{ values.1|default:0.0 }} {{ currency_suffix }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if user.is_superuser or perms.app.view_registertransaction %}
|
||||||
|
<div class="flex flex-column">
|
||||||
|
<h3>{% translate "deposit sum" %}</h3>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>{% translate "user" %}</th>
|
||||||
|
<th>{% translate "sum" %}</th>
|
||||||
|
</tr>
|
||||||
|
{% for values in deposit_sum_per_user %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ values.0 }}</td>
|
||||||
|
<td>{{ values.1|default:0.0 }} {{ currency_suffix }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
<script src="/static/js/autoreload.js"></script>
|
<script src="/static/js/autoreload.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
12
app/views.py
12
app/views.py
|
@ -80,11 +80,17 @@ def deposit(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def statistics(request):
|
def statistics(request):
|
||||||
|
user = request.user
|
||||||
context = {
|
context = {
|
||||||
"orders_per_month": db_queries.orders_per_month(request.user),
|
"orders_per_month": db_queries.select_orders_per_month(user),
|
||||||
"orders_per_weekday": db_queries.orders_per_weekday(request.user),
|
"orders_per_weekday": db_queries.select_orders_per_weekday(user),
|
||||||
"orders_per_drink": db_queries.orders_per_drink(request.user),
|
"orders_per_drink": db_queries.select_orders_per_drink(user),
|
||||||
}
|
}
|
||||||
|
# Advanced statistics
|
||||||
|
if user.has_perm("app.view_order") or user.is_superuser:
|
||||||
|
context["order_sum_per_user"] = db_queries.select_order_sum_per_user_all_users()
|
||||||
|
if user.has_perm("app.view_registertransaction") or user.is_superuser:
|
||||||
|
context["deposit_sum_per_user"] = db_queries.select_deposit_sum_per_user_all_users()
|
||||||
return render(request, "statistics.html", context)
|
return render(request, "statistics.html", context)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -32,6 +32,7 @@ configuration_file = data_directory / "config.yml"
|
||||||
caddyfile = data_directory / "Caddyfile"
|
caddyfile = data_directory / "Caddyfile"
|
||||||
logfile_caddy = logfile_directory / "caddy.log"
|
logfile_caddy = logfile_directory / "caddy.log"
|
||||||
logfile_app = logfile_directory / "app.log"
|
logfile_app = logfile_directory / "app.log"
|
||||||
|
logfile_sessioncleanup = logfile_directory / "session-cleanup.log"
|
||||||
|
|
||||||
|
|
||||||
class MonitoredSubprocess:
|
class MonitoredSubprocess:
|
||||||
|
@ -183,6 +184,6 @@ if __name__ == "__main__":
|
||||||
MonitoredSubprocess(
|
MonitoredSubprocess(
|
||||||
"Session Autocleaner",
|
"Session Autocleaner",
|
||||||
["./scripts/_session-autocleaner.py", str(config["app"]["session_clear_interval"])],
|
["./scripts/_session-autocleaner.py", str(config["app"]["session_clear_interval"])],
|
||||||
logfile_app)
|
logfile_sessioncleanup)
|
||||||
]
|
]
|
||||||
start_and_monitor(procs)
|
start_and_monitor(procs)
|
||||||
|
|
2
start.sh
2
start.sh
|
@ -11,6 +11,6 @@ chmod -c -R g-w,o-rwx .gitignore
|
||||||
|
|
||||||
export PYTHONPATH="$basedir"
|
export PYTHONPATH="$basedir"
|
||||||
export DJANGO_SETTINGS_MODULE="project.settings"
|
export DJANGO_SETTINGS_MODULE="project.settings"
|
||||||
export APP_VERSION="17"
|
export APP_VERSION="19"
|
||||||
|
|
||||||
exec ./scripts/_bootstrap.py "$@"
|
exec ./scripts/_bootstrap.py "$@"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue