Compare commits

...
6 Commits
6 changed files with 156 additions and 111 deletions

No files matched your search

+2 -2
View File
@@ -5,13 +5,13 @@
"id": "002", "id": "002",
"original_name": "-", "original_name": "-",
"original": { "original": {
"filename": "m003", "filename": "m003.mp3",
"sampling_rate": 44.1, "sampling_rate": 44.1,
"bitrate": 256 "bitrate": 256
}, },
"edits": [ "edits": [
{ {
"filename": "m004", "filename": "m004.mp3",
"sampling_rate": 22.1, "sampling_rate": 22.1,
"bitrate": 63 "bitrate": 63
} }
+59 -40
View File
@@ -14,6 +14,7 @@ from functools import wraps
from db import init_db, get_db, close_db, create_participant, now from db import init_db, get_db, close_db, create_participant, now
from datetime import datetime, timezone from datetime import datetime, timezone
import threading import threading
from mutagen import File
bp = Blueprint("main", __name__) bp = Blueprint("main", __name__)
@@ -135,8 +136,8 @@ def api_getRandomSong():
truth = random.choice(["a", "b"]) truth = random.choice(["a", "b"])
session["current"] = {"id": song["id"], "truth": truth} session["current"] = {"id": song["id"], "truth": truth}
truth_path = BASE_MUSIC_FILENAME_DIR + song["original"]["filename"] + ".mp3" truth_path = BASE_MUSIC_FILENAME_DIR + song["original"]["filename"]
random_lie_path = BASE_MUSIC_FILENAME_DIR + random.choice(song["edits"])["filename"] + ".mp3" random_lie_path = BASE_MUSIC_FILENAME_DIR + random.choice(song["edits"])["filename"]
if truth == "a": if truth == "a":
path_a = truth_path path_a = truth_path
@@ -226,42 +227,7 @@ CHOICE_LABELS = {"a": "A", "b": "B", "non": "Kein Unterschied"}
@bp.route("/admin") @bp.route("/admin")
@admin_required @admin_required
def admin(): def admin():
db = get_db() return render_template("admin.html")
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)
def csv_safe(value): def csv_safe(value):
@@ -310,6 +276,52 @@ def debug_reset():
def admin_add(): def admin_add():
return render_template("admin_add.html") 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("/admin/list")
@admin_required
def admin_list():
songs = load_songs_list()
return render_template("admin_tasksList.html", songs=songs)
@bp.route("/api/admin/add", methods=["POST"]) @bp.route("/api/admin/add", methods=["POST"])
@admin_required @admin_required
def api_admin_add(): def api_admin_add():
@@ -330,11 +342,18 @@ def api_admin_add():
BASE_MUSIC_DIR.mkdir(parents=True, exist_ok=True) BASE_MUSIC_DIR.mkdir(parents=True, exist_ok=True)
file.save(BASE_MUSIC_DIR / filename_new) file.save(BASE_MUSIC_DIR / filename_new)
stem = os.path.splitext(filename_new)[0] # read bitrate and sampling rate
audio = File(BASE_MUSIC_DIR / filename_new)
#stem = os.path.splitext(filename_new)[0]
song = add_song({ song = add_song({
"name": title, "name": title,
"artist": artist, "artist": artist,
"original": {"filename": stem}, "original": {
"filename": filename_new,
"sampling_rate": audio.info.sample_rate,
"bitrate": audio.info.bitrate
},
"edits": [], "edits": [],
}) })
+6 -58
View File
@@ -1,73 +1,21 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}Auswertung – HörVergleich{% endblock %}
{% block content %} {% block content %}
<link rel="stylesheet" href="{{ url_for('static', filename='style/admin.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='style/admin.css') }}">
<div class="admin-head"> <div class="admin-head">
<h2>Auswertung</h2> <h2>{% block admin_title %}Admin{% endblock %}</h2>
<div class="admin-actions"> <div class="admin-actions">
<a class="button" href="{{ url_for('main.admin_export') }}">CSV exportieren</a> {% block admin_header %}{% endblock %}
<a class="button" href="{{ url_for('main.admin_add') }}">Unteraufgabe hinzufügen</a>
<form method="post" action="{{ url_for('main.admin_logout') }}"> <form method="post" action="{{ url_for('main.admin_logout') }}">
<button type="submit" class="secondary">Abmelden</button> <button type="submit" class="secondary">Abmelden</button>
</form> </form>
</div> </div>
</div> </div>
<div class="stats"> {% block admin_content %}
<div class="stat"><span class="stat-value">{{ stats.people }}</span><span class="stat-label">Teilnehmer</span></div>
<div class="stat"><span class="stat-value">{{ stats.guesses }}</span><span class="stat-label">Bewertungen</span></div>
<div class="stat">
<span class="stat-value">{{ stats.quote ~ ' %' if stats.quote is not none else '–' }}</span>
<span class="stat-label">Original gewählt</span>
</div>
</div>
{% if not rows %} <a class="button" href="{{ url_for('main.admin_list') }}">Unteraufgaben</a>
<p class="empty">Noch keine Ergebnisse vorhanden.</p> <a class="button" href="{{ url_for('main.admin_results') }}">Auswertung</a>
{% else %}
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Name</th><th>Gestartet</th>
<th class="num">Bewertungen</th><th class="num">Original gewählt</th><th class="num">Quote</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td>{{ r.name }}</td>
<td class="muted">{{ r.started }}</td>
<td class="num">{{ r.total }}</td>
<td class="num">{{ r.right }}</td>
<td class="num">{{ r.quote }} %</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<h3>Einzelergebnisse</h3> {% endblock %}
{% for r in rows %}
<details class="person">
<summary>{{ r.name }} <span class="muted">({{ r.right }}/{{ r.total }}, {{ r.started }})</span></summary>
<div class="table-wrap">
<table>
<thead><tr><th>Song</th><th>Original gewählt</th><th>Wahl</th><th>Bearbeitung</th></tr></thead>
<tbody>
{% for g in r.guesses %}
<tr>
<td>{{ songs.get(g.song_id, g.song_id) }}</td>
<td>{{ 'ja' if g.right else 'nein' }}</td>
<td>{{ g.choice }}</td>
<td>{{ g.edit }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</details>
{% endfor %}
{% endif %}
{% endblock %} {% endblock %}
+11 -11
View File
@@ -1,8 +1,8 @@
{% extends "base.html" %} {% extends "admin.html" %}
{% block content %}
<link rel="stylesheet" href="{{ url_for('static', filename='style/admin.css') }}">
<h2>Unteraufgabe hinzufügen</h2> {% block admin_title %}Unteraufgabe hinzufügen{% endblock %}
{% block admin_content %}
<form class="form" id="form"> <form class="form" id="form">
<label for="titel">Titel</label> <label for="titel">Titel</label>
<input id="title" name="title" type="text" autocomplete="off" required autofocus> <input id="title" name="title" type="text" autocomplete="off" required autofocus>
@@ -21,8 +21,8 @@
</form> </form>
<script> <script>
const form = document.getElementById("form"); const form = document.getElementById("form");
form.addEventListener("submit", async (event) => { form.addEventListener("submit", async (event) => {
event.preventDefault(); event.preventDefault();
const res = await fetch("/api/admin/add", { const res = await fetch("/api/admin/add", {
method: "POST", method: "POST",
@@ -30,15 +30,15 @@ form.addEventListener("submit", async (event) => {
}); });
const result = await res.json(); const result = await res.json();
console.log(result); console.log(result);
}); });
const fileInput = document.getElementById("file"); const fileInput = document.getElementById("file");
const fileName = document.getElementById("file-name"); const fileName = document.getElementById("file-name");
fileInput.addEventListener("change", () => { fileInput.addEventListener("change", () => {
fileName.textContent = fileInput.files.length fileName.textContent = fileInput.files.length
? fileInput.files[0].name ? fileInput.files[0].name
: "Keine Datei ausgewählt"; : "Keine Datei ausgewählt";
}); });
</script> </script>
{% endblock %} {% endblock %}
+65
View File
@@ -0,0 +1,65 @@
{% extends "admin.html" %}
{% block admin_title %}Auswertung{% endblock %}
{% block admin_content %}
<a class="button" href="{{ url_for('main.admin_export') }}">CSV exportieren</a>
<div class="stats">
<div class="stat"><span class="stat-value">{{ stats.people }}</span><span class="stat-label">Teilnehmer</span></div>
<div class="stat"><span class="stat-value">{{ stats.guesses }}</span><span class="stat-label">Bewertungen</span></div>
<div class="stat">
<span class="stat-value">{{ stats.quote ~ ' %' if stats.quote is not none else '–' }}</span>
<span class="stat-label">Original gewählt</span>
</div>
</div>
{% if not rows %}
<p class="empty">Noch keine Ergebnisse vorhanden.</p>
{% else %}
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Name</th><th>Gestartet</th>
<th class="num">Bewertungen</th><th class="num">Original gewählt</th><th class="num">Quote</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td>{{ r.name }}</td>
<td class="muted">{{ r.started }}</td>
<td class="num">{{ r.total }}</td>
<td class="num">{{ r.right }}</td>
<td class="num">{{ r.quote }} %</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<h3>Einzelergebnisse</h3>
{% for r in rows %}
<details class="person">
<summary>{{ r.name }} <span class="muted">({{ r.right }}/{{ r.total }}, {{ r.started }})</span></summary>
<div class="table-wrap">
<table>
<thead><tr><th>Song</th><th>Original gewählt</th><th>Wahl</th><th>Bearbeitung</th></tr></thead>
<tbody>
{% for g in r.guesses %}
<tr>
<td>{{ songs.get(g.song_id, g.song_id) }}</td>
<td>{{ 'ja' if g.right else 'nein' }}</td>
<td>{{ g.choice }}</td>
<td>{{ g.edit }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</details>
{% endfor %}
{% endif %}
{% endblock %}
+13
View File
@@ -0,0 +1,13 @@
{% extends "admin.html" %}
{% block admin_title %}Unteraufgaben{% endblock %}
{% block admin_header %}
<a class="button" href="{{ url_for('main.admin_add') }}">Unteraufgabe hinzufügen</a>
{% endblock %}
{% block admin_content %}
{{ songs }}
{% endblock %}