From ea7cef7f3b9265ebade13007fd3a0f6b9cd33ff7 Mon Sep 17 00:00:00 2001 From: Robin Schanbacher Date: Fri, 13 Nov 2026 12:29:10 +0100 Subject: [PATCH] refactor: move results to own page --- routes.py | 77 +++++++++++++++++++----------------- templates/admin.html | 63 +++-------------------------- templates/admin_add.html | 37 ++++++++--------- templates/admin_results.html | 62 +++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 112 deletions(-) create mode 100644 templates/admin_results.html diff --git a/routes.py b/routes.py index 551671a..b6584e0 100644 --- a/routes.py +++ b/routes.py @@ -226,42 +226,7 @@ CHOICE_LABELS = {"a": "A", "b": "B", "non": "Kein Unterschied"} @bp.route("/admin") @admin_required def admin(): - db = get_db() - songs = {s["id"]: s["name"] for s in load_songs_list()} - - by_person = {} - for r in db.execute("SELECT * FROM ratings ORDER BY id"): - by_person.setdefault(r["participant_id"], []).append({ - "song_id": r["song_id"], - "right": bool(r["original_chosen"]), - "choice": CHOICE_LABELS.get(r["choice"], r["choice"]), - "edit": r["edit"] or "–", - }) - - rows = [] - for p in db.execute("SELECT id, name, created FROM participants ORDER BY created DESC"): - guesses = by_person.get(p["id"], []) - if not guesses: - continue # nur Teilnehmer mit mindestens einer Bewertung - total = len(guesses) - right = sum(g["right"] for g in guesses) - rows.append({ - "name": p["name"], - "started": p["created"], - "total": total, - "right": right, - "quote": round(100 * right / total), - "guesses": guesses, - }) - - total_all = sum(r["total"] for r in rows) - right_all = sum(r["right"] for r in rows) - stats = { - "people": len(rows), - "guesses": total_all, - "quote": round(100 * right_all / total_all) if total_all else None, - } - return render_template("admin.html", rows=rows, stats=stats, songs=songs) + return render_template("admin.html") def csv_safe(value): @@ -310,6 +275,46 @@ def debug_reset(): def admin_add(): return render_template("admin_add.html") +@bp.route("/admin/results") +@admin_required +def admin_results(): + db = get_db() + songs = {s["id"]: s["name"] for s in load_songs_list()} + + by_person = {} + for r in db.execute("SELECT * FROM ratings ORDER BY id"): + by_person.setdefault(r["participant_id"], []).append({ + "song_id": r["song_id"], + "right": bool(r["original_chosen"]), + "choice": CHOICE_LABELS.get(r["choice"], r["choice"]), + "edit": r["edit"] or "–", + }) + + rows = [] + for p in db.execute("SELECT id, name, created FROM participants ORDER BY created DESC"): + guesses = by_person.get(p["id"], []) + if not guesses: + continue # nur Teilnehmer mit mindestens einer Bewertung + total = len(guesses) + right = sum(g["right"] for g in guesses) + rows.append({ + "name": p["name"], + "started": p["created"], + "total": total, + "right": right, + "quote": round(100 * right / total), + "guesses": guesses, + }) + + total_all = sum(r["total"] for r in rows) + right_all = sum(r["right"] for r in rows) + stats = { + "people": len(rows), + "guesses": total_all, + "quote": round(100 * right_all / total_all) if total_all else None, + } + return render_template("admin_results.html", rows=rows, stats=stats, songs=songs) + @bp.route("/api/admin/add", methods=["POST"]) @admin_required def api_admin_add(): diff --git a/templates/admin.html b/templates/admin.html index 9c01534..5b0efc0 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -1,73 +1,20 @@ {% extends "base.html" %} -{% block title %}Auswertung – HörVergleich{% endblock %} {% block content %}
-

Auswertung

+

Admin

-
-
{{ stats.people }}Teilnehmer
-
{{ stats.guesses }}Bewertungen
-
- {{ stats.quote ~ ' %' if stats.quote is not none else '–' }} - Original gewählt -
-
+{% block admin_content %} -{% if not rows %} -

Noch keine Ergebnisse vorhanden.

-{% else %} -
- - - - - - - - - {% for r in rows %} - - - - - - - - {% endfor %} - -
NameGestartetBewertungenOriginal gewähltQuote
{{ r.name }}{{ r.started }}{{ r.total }}{{ r.right }}{{ r.quote }} %
-
+Unteraufgabe hinzufügen +Auswertung -

Einzelergebnisse

- {% for r in rows %} -
- {{ r.name }} ({{ r.right }}/{{ r.total }}, {{ r.started }}) -
- - - - {% for g in r.guesses %} - - - - - - - {% endfor %} - -
SongOriginal gewähltWahlBearbeitung
{{ songs.get(g.song_id, g.song_id) }}{{ 'ja' if g.right else 'nein' }}{{ g.choice }}{{ g.edit }}
-
-
- {% endfor %} -{% endif %} +{% endblock %} {% endblock %} \ No newline at end of file diff --git a/templates/admin_add.html b/templates/admin_add.html index a084a42..ae9750e 100644 --- a/templates/admin_add.html +++ b/templates/admin_add.html @@ -1,5 +1,6 @@ -{% extends "base.html" %} -{% block content %} +{% extends "admin.html" %} +{% block admin_content %} +

Unteraufgabe hinzufügen

@@ -21,24 +22,24 @@ {% endblock %} \ No newline at end of file diff --git a/templates/admin_results.html b/templates/admin_results.html new file mode 100644 index 0000000..8e0f590 --- /dev/null +++ b/templates/admin_results.html @@ -0,0 +1,62 @@ +{% extends "admin.html" %} +{% block admin_content %} + +CSV exportieren + +
+
{{ stats.people }}Teilnehmer
+
{{ stats.guesses }}Bewertungen
+
+ {{ stats.quote ~ ' %' if stats.quote is not none else '–' }} + Original gewählt +
+
+ +{% if not rows %} +

Noch keine Ergebnisse vorhanden.

+{% else %} +
+ + + + + + + + + {% for r in rows %} + + + + + + + + {% endfor %} + +
NameGestartetBewertungenOriginal gewähltQuote
{{ r.name }}{{ r.started }}{{ r.total }}{{ r.right }}{{ r.quote }} %
+
+ +

Einzelergebnisse

+ {% for r in rows %} +
+ {{ r.name }} ({{ r.right }}/{{ r.total }}, {{ r.started }}) +
+ + + + {% for g in r.guesses %} + + + + + + + {% endfor %} + +
SongOriginal gewähltWahlBearbeitung
{{ songs.get(g.song_id, g.song_id) }}{{ 'ja' if g.right else 'nein' }}{{ g.choice }}{{ g.edit }}
+
+
+ {% endfor %} +{% endif %} +{% endblock %} \ No newline at end of file