Statistik überarbeitet
This commit is contained in:
240
stats.php
240
stats.php
@@ -1,50 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
// PHP-Logik für die Datenabfrage
|
|
||||||
include('inc/check_login.php');
|
include('inc/check_login.php');
|
||||||
include('inc/check_admin.php');
|
|
||||||
require_once('inc/db.php');
|
require_once('inc/db.php');
|
||||||
|
|
||||||
// --- 1. Jährliche Strafen-Statistik ---
|
|
||||||
// Passen Sie hier das Datum der Abschlussveranstaltung an.
|
|
||||||
$last_reset_date = '2024-01-01';
|
|
||||||
|
|
||||||
$penalties_data = [];
|
|
||||||
$total_penalties = 0;
|
|
||||||
$total_due = 0;
|
|
||||||
// Passen Sie hier die Höhe der Strafe in Euro an.
|
|
||||||
$penalty_amount = 1;
|
|
||||||
|
|
||||||
// SQL-Abfrage, um Strafen pro Benutzer seit dem letzten Reset-Datum zu zählen
|
|
||||||
// Strafe = anwesend (attended=1) aber Farbe nicht getragen (wore_color=0)
|
|
||||||
$sql_penalties = "
|
|
||||||
SELECT
|
|
||||||
u.username,
|
|
||||||
COUNT(mt.user_id) AS penalty_count
|
|
||||||
FROM meeting_teilnehmer mt
|
|
||||||
JOIN meetings m ON mt.meeting_id = m.id
|
|
||||||
JOIN users u ON mt.user_id = u.id
|
|
||||||
WHERE m.meeting_date >= ? AND mt.attended = 1 AND mt.wore_color = 0
|
|
||||||
GROUP BY u.username
|
|
||||||
ORDER BY penalty_count DESC
|
|
||||||
";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql_penalties);
|
|
||||||
// Überprüfen, ob das Statement erfolgreich vorbereitet wurde
|
|
||||||
if ($stmt === false) {
|
|
||||||
die("Fehler bei der SQL-Abfrage: " . mysqli_error($conn));
|
|
||||||
}
|
|
||||||
mysqli_stmt_bind_param($stmt, "s", $last_reset_date);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
|
||||||
$penalties_data[] = $row;
|
|
||||||
$total_penalties += $row['penalty_count'];
|
|
||||||
$total_due += $row['penalty_count'] * $penalty_amount;
|
|
||||||
}
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
|
|
||||||
// --- 2. Gesamt-Statistiken ---
|
|
||||||
|
|
||||||
// Statistik 1: Häufigkeit der gewählten Farben
|
// Statistik 1: Häufigkeit der gewählten Farben
|
||||||
$color_stats = [];
|
$color_stats = [];
|
||||||
$sql_colors = "
|
$sql_colors = "
|
||||||
@@ -79,64 +36,100 @@ while ($row = mysqli_fetch_assoc($result)) {
|
|||||||
$participation_stats[] = $row;
|
$participation_stats[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Neue Statistik: Durchschnittliche Anwesenheit pro Meeting
|
||||||
|
$avg_attendance = 0;
|
||||||
|
$sql_avg_attendance = "
|
||||||
|
SELECT AVG(attended_count) AS avg_attended
|
||||||
|
FROM (
|
||||||
|
SELECT COUNT(user_id) AS attended_count
|
||||||
|
FROM meeting_teilnehmer
|
||||||
|
WHERE attended = 1
|
||||||
|
GROUP BY meeting_id
|
||||||
|
) AS subquery";
|
||||||
|
$result_avg = mysqli_query($conn, $sql_avg_attendance);
|
||||||
|
if ($row = mysqli_fetch_assoc($result_avg)) {
|
||||||
|
$avg_attendance = round($row['avg_attended'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neue Statistik: Durchschnittliche Anzahl derer, die die korrekte Farbe getragen haben
|
||||||
|
$avg_wore_color = 0;
|
||||||
|
$sql_avg_wore_color = "
|
||||||
|
SELECT AVG(wore_color_count) AS avg_wore_color
|
||||||
|
FROM (
|
||||||
|
SELECT COUNT(user_id) AS wore_color_count
|
||||||
|
FROM meeting_teilnehmer
|
||||||
|
WHERE wore_color = 1
|
||||||
|
GROUP BY meeting_id
|
||||||
|
) AS subquery";
|
||||||
|
$result_avg_wore = mysqli_query($conn, $sql_avg_wore_color);
|
||||||
|
if ($row = mysqli_fetch_assoc($result_avg_wore)) {
|
||||||
|
$avg_wore_color = round($row['avg_wore_color'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neue Statistik: Ranking nach dem Tragen der Farbe
|
||||||
|
$wore_color_stats = [];
|
||||||
|
$sql_wore_color = "
|
||||||
|
SELECT
|
||||||
|
u.username,
|
||||||
|
COUNT(mt.user_id) AS wore_color_count
|
||||||
|
FROM meeting_teilnehmer mt
|
||||||
|
JOIN users u ON mt.user_id = u.id
|
||||||
|
WHERE mt.wore_color = 1
|
||||||
|
GROUP BY u.username
|
||||||
|
ORDER BY wore_color_count DESC
|
||||||
|
";
|
||||||
|
$result_wore = mysqli_query($conn, $sql_wore_color);
|
||||||
|
while ($row = mysqli_fetch_assoc($result_wore)) {
|
||||||
|
$wore_color_stats[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
// Header einbinden
|
// Header einbinden
|
||||||
require_once 'inc/header.php';
|
require_once 'inc/header.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h2 class="mb-4">Statistiken & Auswertung</h2>
|
<h2 class="mb-4">Statistiken & Ranking</h2>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header bg-danger-subtle text-danger">
|
<div class="card-header bg-secondary bg-opacity-50 text-muted">
|
||||||
<h4 class="mb-0">Aktuelle Strafen (seit <?= date('d.m.Y', strtotime($last_reset_date)); ?>)</h4>
|
<h4 class="mb-0">Gesamt-Statistiken</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="fs-5 fw-bold text-center">
|
<div class="row justify-content-center">
|
||||||
Gesamtzahl der Strafen: <span class="badge bg-danger"><?= $total_penalties ?></span><br>
|
<div class="col-lg-6">
|
||||||
Fälliger Gesamtbetrag: <span class="text-danger fw-bold"><?= number_format($total_due, 2, ',', '.'); ?> €</span>
|
<h5 class="card-title text-center">Häufigkeit der gewählten Farben</h5>
|
||||||
</p>
|
<canvas id="colorChart" class="mb-4"></canvas>
|
||||||
|
|
||||||
<?php if (empty($penalties_data)): ?>
|
|
||||||
<div class="alert alert-info text-center" role="alert">
|
|
||||||
Bisher wurden keine Strafen verzeichnet.
|
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<!-- Trennlinie, die nur auf Mobilgeräten sichtbar ist -->
|
||||||
<div class="table-responsive">
|
<hr class="d-lg-none my-4">
|
||||||
<table class="table table-striped table-hover">
|
<div class="col-lg-6">
|
||||||
<thead>
|
<h5 class="card-title text-center">Teilnahme-Ranking</h5>
|
||||||
<tr>
|
<p class="text-center text-muted mt-2 mb-3">
|
||||||
<th>Benutzer</th>
|
Durchschnittliche Anwesenheit je Treffen: <strong><?= htmlspecialchars($avg_attendance) ?></strong>
|
||||||
<th>Anzahl Strafen</th>
|
</p>
|
||||||
<th>Fälliger Betrag</th>
|
<!-- Neuer Container mit fester Höhe, um das unendliche Wachstum zu stoppen -->
|
||||||
</tr>
|
<div style="height: 40vh;">
|
||||||
</thead>
|
<canvas id="participationChart"></canvas>
|
||||||
<tbody>
|
</div>
|
||||||
<?php foreach ($penalties_data as $penalty): ?>
|
|
||||||
<tr>
|
|
||||||
<td><?= htmlspecialchars($penalty['username']); ?></td>
|
|
||||||
<td><?= htmlspecialchars($penalty['penalty_count']); ?></td>
|
|
||||||
<td><?= number_format($penalty['penalty_count'] * $penalty_amount, 2, ',', '.'); ?> €</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
---
|
<!-- Trennlinie für die neue Statistik -->
|
||||||
|
<hr class="my-4">
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="row justify-content-center">
|
||||||
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
<div class="col-lg-6">
|
||||||
<h4 class="mb-0">Gesamt-Statistiken (Alle Zeiten)</h4>
|
<h5 class="card-title text-center">Ranking - Farbe getragen</h5>
|
||||||
</div>
|
<p class="text-center text-muted mt-2 mb-3">
|
||||||
<div class="card-body">
|
Durchschnittliche korrekte Farbe je Treffen: <strong><?= htmlspecialchars($avg_wore_color) ?></strong>
|
||||||
<h5 class="card-title">Häufigkeit der gewählten Farben</h5>
|
</p>
|
||||||
<canvas id="colorChart" class="mb-4"></canvas>
|
<!-- Container für das neue Diagramm -->
|
||||||
|
<div style="height: 40vh;">
|
||||||
|
<canvas id="woreColorChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h5 class="card-title">Teilnahme-Ranking</h5>
|
|
||||||
<canvas id="participationChart"></canvas>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -197,6 +190,7 @@ require_once 'inc/header.php';
|
|||||||
options: {
|
options: {
|
||||||
indexAxis: 'y',
|
indexAxis: 'y',
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
maintainAspectRatio: false, // Wichtig für die Größenanpassung
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
display: false
|
display: false
|
||||||
@@ -209,6 +203,22 @@ require_once 'inc/header.php';
|
|||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
beginAtZero: true
|
beginAtZero: true
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
ticks: {
|
||||||
|
font: {
|
||||||
|
size: 10 // Kleinere Schriftgröße für bessere Lesbarkeit auf mobilen Geräten
|
||||||
|
},
|
||||||
|
// Callback, um lange Namen zu kürzen und Überlappungen zu vermeiden
|
||||||
|
callback: function(value, index, ticks) {
|
||||||
|
const username = this.getLabelForValue(value);
|
||||||
|
const maxChars = 15; // Maximale Zeichen auf Mobilgeräten
|
||||||
|
if (username.length > maxChars) {
|
||||||
|
return username.substring(0, maxChars) + '...';
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,6 +228,62 @@ require_once 'inc/header.php';
|
|||||||
document.getElementById('participationChart'),
|
document.getElementById('participationChart'),
|
||||||
participationConfig
|
participationConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Daten für "Farbe getragen"-Diagramm
|
||||||
|
const woreColorData = {
|
||||||
|
labels: <?= json_encode(array_column($wore_color_stats, 'username')); ?>,
|
||||||
|
datasets: [{
|
||||||
|
label: 'Farbe getragen',
|
||||||
|
data: <?= json_encode(array_column($wore_color_stats, 'wore_color_count')); ?>,
|
||||||
|
backgroundColor: 'rgba(75, 192, 192, 0.8)',
|
||||||
|
borderColor: 'rgb(75, 192, 192)',
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const woreColorConfig = {
|
||||||
|
type: 'bar',
|
||||||
|
data: woreColorData,
|
||||||
|
options: {
|
||||||
|
indexAxis: 'y',
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Anzahl der "Farbe getragen"-Einträge pro Benutzer'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
beginAtZero: true
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
ticks: {
|
||||||
|
font: {
|
||||||
|
size: 10
|
||||||
|
},
|
||||||
|
callback: function(value, index, ticks) {
|
||||||
|
const username = this.getLabelForValue(value);
|
||||||
|
const maxChars = 15;
|
||||||
|
if (username.length > maxChars) {
|
||||||
|
return username.substring(0, maxChars) + '...';
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Chart(
|
||||||
|
document.getElementById('woreColorChart'),
|
||||||
|
woreColorConfig
|
||||||
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user