refactor: move results to own page
This commit is contained in:
1 parent
3f62e4e2d2
commit
ea7cef7f3b
4 files changed
+127
-112
No files matched your search
@@ -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():
|
||||
|
||||
Reference in new issue
Block a user