Statistik überarbeitet
This commit is contained in:
246
stats.php
246
stats.php
@@ -1,50 +1,7 @@
|
||||
<?php
|
||||
// PHP-Logik für die Datenabfrage
|
||||
include('inc/check_login.php');
|
||||
include('inc/check_admin.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
|
||||
$color_stats = [];
|
||||
$sql_colors = "
|
||||
@@ -79,66 +36,102 @@ while ($row = mysqli_fetch_assoc($result)) {
|
||||
$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
|
||||
require_once 'inc/header.php';
|
||||
?>
|
||||
|
||||
<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-header bg-danger-subtle text-danger">
|
||||
<h4 class="mb-0">Aktuelle Strafen (seit <?= date('d.m.Y', strtotime($last_reset_date)); ?>)</h4>
|
||||
<div class="card-header bg-secondary bg-opacity-50 text-muted">
|
||||
<h4 class="mb-0">Gesamt-Statistiken</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="fs-5 fw-bold text-center">
|
||||
Gesamtzahl der Strafen: <span class="badge bg-danger"><?= $total_penalties ?></span><br>
|
||||
Fälliger Gesamtbetrag: <span class="text-danger fw-bold"><?= number_format($total_due, 2, ',', '.'); ?> €</span>
|
||||
</p>
|
||||
|
||||
<?php if (empty($penalties_data)): ?>
|
||||
<div class="alert alert-info text-center" role="alert">
|
||||
Bisher wurden keine Strafen verzeichnet.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Benutzer</th>
|
||||
<th>Anzahl Strafen</th>
|
||||
<th>Fälliger Betrag</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?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>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
<div class="card shadow mb-4">
|
||||
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
||||
<h4 class="mb-0">Gesamt-Statistiken (Alle Zeiten)</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Häufigkeit der gewählten Farben</h5>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<h5 class="card-title text-center">Häufigkeit der gewählten Farben</h5>
|
||||
<canvas id="colorChart" class="mb-4"></canvas>
|
||||
|
||||
<h5 class="card-title">Teilnahme-Ranking</h5>
|
||||
</div>
|
||||
<!-- Trennlinie, die nur auf Mobilgeräten sichtbar ist -->
|
||||
<hr class="d-lg-none my-4">
|
||||
<div class="col-lg-6">
|
||||
<h5 class="card-title text-center">Teilnahme-Ranking</h5>
|
||||
<p class="text-center text-muted mt-2 mb-3">
|
||||
Durchschnittliche Anwesenheit je Treffen: <strong><?= htmlspecialchars($avg_attendance) ?></strong>
|
||||
</p>
|
||||
<!-- Neuer Container mit fester Höhe, um das unendliche Wachstum zu stoppen -->
|
||||
<div style="height: 40vh;">
|
||||
<canvas id="participationChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Trennlinie für die neue Statistik -->
|
||||
<hr class="my-4">
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<h5 class="card-title text-center">Ranking - Farbe getragen</h5>
|
||||
<p class="text-center text-muted mt-2 mb-3">
|
||||
Durchschnittliche korrekte Farbe je Treffen: <strong><?= htmlspecialchars($avg_wore_color) ?></strong>
|
||||
</p>
|
||||
<!-- Container für das neue Diagramm -->
|
||||
<div style="height: 40vh;">
|
||||
<canvas id="woreColorChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
@@ -197,6 +190,7 @@ require_once 'inc/header.php';
|
||||
options: {
|
||||
indexAxis: 'y',
|
||||
responsive: true,
|
||||
maintainAspectRatio: false, // Wichtig für die Größenanpassung
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
@@ -209,6 +203,22 @@ require_once 'inc/header.php';
|
||||
scales: {
|
||||
x: {
|
||||
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'),
|
||||
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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user