295 lines
10 KiB
PHP
Executable File
295 lines
10 KiB
PHP
Executable File
<?php
|
|
include('inc/check_login.php');
|
|
require_once('inc/db.php');
|
|
|
|
// Statistik 1: Häufigkeit der gewählten Farben
|
|
$color_stats = [];
|
|
$sql_colors = "
|
|
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
|
|
GROUP BY c.name, c.hex_code
|
|
ORDER BY meeting_count DESC
|
|
";
|
|
$result = mysqli_query($conn, $sql_colors);
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$color_stats[] = $row;
|
|
}
|
|
|
|
// Statistik 2: Teilnahmequote pro Benutzer
|
|
$participation_stats = [];
|
|
$sql_participation = "
|
|
SELECT
|
|
u.username,
|
|
COUNT(mt.user_id) AS total_attendance
|
|
FROM meeting_teilnehmer mt
|
|
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
|
|
";
|
|
$result = mysqli_query($conn, $sql_participation);
|
|
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(mt.user_id) AS attended_count
|
|
FROM meeting_teilnehmer mt
|
|
JOIN meetings m ON mt.meeting_id = m.id
|
|
WHERE mt.attended = 1 AND m.is_completed = 1
|
|
GROUP BY mt.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(mt.user_id) AS wore_color_count
|
|
FROM meeting_teilnehmer mt
|
|
JOIN meetings m ON mt.meeting_id = m.id
|
|
WHERE mt.wore_color = 1 AND m.is_completed = 1
|
|
GROUP BY mt.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
|
|
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
|
|
";
|
|
$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 & Ranking</h2>
|
|
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header bg-secondary bg-opacity-50 text-muted">
|
|
<h4 class="mb-0">Gesamt-Statistiken</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<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>
|
|
</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>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Daten für Farbhäufigkeits-Diagramm
|
|
const colorData = {
|
|
labels: <?= json_encode(array_column($color_stats, 'name')); ?>,
|
|
datasets: [{
|
|
label: 'Anzahl Treffen',
|
|
data: <?= json_encode(array_column($color_stats, 'meeting_count')); ?>,
|
|
backgroundColor: <?= json_encode(array_column($color_stats, 'hex_code')); ?>,
|
|
borderColor: 'rgba(0, 0, 0, 0.1)',
|
|
borderWidth: 1
|
|
}]
|
|
};
|
|
|
|
const colorConfig = {
|
|
type: 'pie',
|
|
data: colorData,
|
|
options: {
|
|
responsive: true,
|
|
plugins: {
|
|
legend: {
|
|
position: 'top',
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'Verteilung der Farbwahl über alle Treffen'
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
new Chart(
|
|
document.getElementById('colorChart'),
|
|
colorConfig
|
|
);
|
|
|
|
// Daten für Teilnahme-Diagramm
|
|
const participationData = {
|
|
labels: <?= json_encode(array_column($participation_stats, 'username')); ?>,
|
|
datasets: [{
|
|
label: 'Anzahl Teilnahmen',
|
|
data: <?= json_encode(array_column($participation_stats, 'total_attendance')); ?>,
|
|
backgroundColor: 'rgba(54, 162, 235, 0.8)',
|
|
borderColor: 'rgb(54, 162, 235)',
|
|
borderWidth: 1
|
|
}]
|
|
};
|
|
|
|
const participationConfig = {
|
|
type: 'bar',
|
|
data: participationData,
|
|
options: {
|
|
indexAxis: 'y',
|
|
responsive: true,
|
|
maintainAspectRatio: false, // Wichtig für die Größenanpassung
|
|
plugins: {
|
|
legend: {
|
|
display: false
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'Anzahl der Teilnahmen pro Benutzer'
|
|
}
|
|
},
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
new Chart(
|
|
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>
|
|
|
|
<?php include('inc/footer.php'); ?>
|