diff --git a/stats.php b/stats.php index 6313754..0de4d5f 100755 --- a/stats.php +++ b/stats.php @@ -2,13 +2,17 @@ include('inc/check_login.php'); require_once('inc/db.php'); -// Statistik 1: Häufigkeit der gewählten Farben +// Gesamtanzahl abgeschlossener Treffen (nur zur Info) +$total_meetings = 0; +$result_total_meetings = mysqli_query($conn, "SELECT COUNT(*) AS total FROM meetings WHERE is_completed = 1"); +if ($row = mysqli_fetch_assoc($result_total_meetings)) { + $total_meetings = (int)$row['total']; +} + +// Statistik: Farbhäufigkeit $color_stats = []; $sql_colors = " - SELECT - c.name, - c.hex_code, - COUNT(m.id) AS meeting_count + SELECT c.name, c.hex_code, COUNT(m.id) AS meeting_count FROM meetings m JOIN colors c ON m.color_id = c.id WHERE m.is_completed = 1 @@ -20,25 +24,44 @@ while ($row = mysqli_fetch_assoc($result)) { $color_stats[] = $row; } -// Statistik 2: Teilnahmequote pro Benutzer +// TEILNAHME: Sortiert nach Prozent, mit Prozentwert $participation_stats = []; +$participation_percentages = []; +$participation_registered = []; +$participation_attended = []; + $sql_participation = " SELECT u.username, - COUNT(mt.user_id) AS total_attendance + COUNT(*) AS registered_completed, + SUM(CASE WHEN mt.attended = 1 THEN 1 ELSE 0 END) AS total_attendance, + ROUND( + (SUM(CASE WHEN mt.attended = 1 THEN 1 ELSE 0 END) / COUNT(*)) * 100, + 1 + ) AS percentage FROM meeting_teilnehmer mt + JOIN meetings m ON mt.meeting_id = m.id AND m.is_completed = 1 JOIN users u ON mt.user_id = u.id - JOIN meetings m ON mt.meeting_id = m.id - WHERE mt.attended = 1 AND m.is_completed = 1 - GROUP BY u.username - ORDER BY total_attendance DESC + GROUP BY u.id, u.username + ORDER BY percentage DESC, u.username ASC "; $result = mysqli_query($conn, $sql_participation); while ($row = mysqli_fetch_assoc($result)) { - $participation_stats[] = $row; + $registered = (int)$row['registered_completed']; + $attended = (int)$row['total_attendance']; + $percentage = (float)$row['percentage']; + $participation_stats[] = [ + 'username' => $row['username'], + 'total_attendance' => $attended, + 'registered_meetings' => $registered, + 'percentage' => $percentage + ]; + $participation_percentages[] = $percentage; + $participation_registered[] = $registered; + $participation_attended[] = $attended; } -// Durchschnittliche Anwesenheit pro Meeting +// Globale Durchschnitte (unverändert) $avg_attendance = 0; $sql_avg_attendance = " SELECT AVG(attended_count) AS avg_attended @@ -54,7 +77,6 @@ if ($row = mysqli_fetch_assoc($result_avg)) { $avg_attendance = round($row['avg_attended'], 2); } -// Durchschnittliche korrekte Farbe $avg_wore_color = 0; $sql_avg_wore_color = " SELECT AVG(wore_color_count) AS avg_wore_color @@ -70,34 +92,56 @@ if ($row = mysqli_fetch_assoc($result_avg_wore)) { $avg_wore_color = round($row['avg_wore_color'], 2); } -// Ranking: Farbe getragen +// FARBE GETRAGEN: Sortiert nach Prozent, mit Prozentwert $wore_color_stats = []; +$wore_color_percentages = []; +$wore_color_attended = []; +$wore_color_count = []; + $sql_wore_color = " SELECT u.username, - COUNT(mt.user_id) AS wore_color_count + SUM(CASE WHEN mt.attended = 1 THEN 1 ELSE 0 END) AS total_attendance, + SUM(CASE WHEN mt.wore_color = 1 THEN 1 ELSE 0 END) AS wore_color_count, + CASE + WHEN SUM(CASE WHEN mt.attended = 1 THEN 1 ELSE 0 END) > 0 THEN + ROUND( + (SUM(CASE WHEN mt.wore_color = 1 THEN 1 ELSE 0 END) / + SUM(CASE WHEN mt.attended = 1 THEN 1 ELSE 0 END)) * 100, + 1 + ) + ELSE 0.0 + END AS percentage FROM meeting_teilnehmer mt + JOIN meetings m ON mt.meeting_id = m.id AND m.is_completed = 1 JOIN users u ON mt.user_id = u.id - JOIN meetings m ON mt.meeting_id = m.id - WHERE mt.wore_color = 1 AND m.is_completed = 1 - GROUP BY u.username - ORDER BY wore_color_count DESC + GROUP BY u.id, u.username + ORDER BY percentage DESC, u.username ASC "; $result_wore = mysqli_query($conn, $sql_wore_color); while ($row = mysqli_fetch_assoc($result_wore)) { - $wore_color_stats[] = $row; + $attended = (int)$row['total_attendance']; + $wore = (int)$row['wore_color_count']; + $percentage = (float)$row['percentage']; + $wore_color_stats[] = [ + 'username' => $row['username'], + 'wore_color_count' => $wore, + 'total_attendance' => $attended, + 'percentage' => $percentage + ]; + $wore_color_percentages[] = $percentage; + $wore_color_attended[] = $attended; + $wore_color_count[] = $wore; } -// 🔹 NEU: Ranking der Verschiebungsvorschläge +// Verschiebungsvorschläge (unverändert) $reschedule_stats = []; $sql_reschedule = " - SELECT - u.username, - COUNT(p.id) AS reschedule_count + SELECT u.username, COUNT(p.id) AS reschedule_count FROM meeting_reschedule_proposals p JOIN users u ON p.proposed_by_user_id = u.id GROUP BY u.username - ORDER BY reschedule_count DESC + ORDER BY reschedule_count DESC, u.username ASC "; $result_reschedule = mysqli_query($conn, $sql_reschedule); while ($row = mysqli_fetch_assoc($result_reschedule)) { @@ -124,6 +168,7 @@ require_once 'inc/header.php';
+ Insgesamt = $total_meetings ?> abgeschlossene Treffen.
Durchschnittliche Anwesenheit je Treffen: = htmlspecialchars($avg_attendance) ?>