v1.3.1 - Statistik jetzt nach Quoten nicht mehr nach absoluten Zahlen

This commit is contained in:
Borgal
2025-11-18 18:40:04 +01:00
parent cb0f7ea866
commit a4c3644a54

251
stats.php
View File

@@ -2,13 +2,17 @@
include('inc/check_login.php'); include('inc/check_login.php');
require_once('inc/db.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 = []; $color_stats = [];
$sql_colors = " $sql_colors = "
SELECT SELECT c.name, c.hex_code, COUNT(m.id) AS meeting_count
c.name,
c.hex_code,
COUNT(m.id) AS meeting_count
FROM meetings m FROM meetings m
JOIN colors c ON m.color_id = c.id JOIN colors c ON m.color_id = c.id
WHERE m.is_completed = 1 WHERE m.is_completed = 1
@@ -20,25 +24,44 @@ while ($row = mysqli_fetch_assoc($result)) {
$color_stats[] = $row; $color_stats[] = $row;
} }
// Statistik 2: Teilnahmequote pro Benutzer // TEILNAHME: Sortiert nach Prozent, mit Prozentwert
$participation_stats = []; $participation_stats = [];
$participation_percentages = [];
$participation_registered = [];
$participation_attended = [];
$sql_participation = " $sql_participation = "
SELECT SELECT
u.username, 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 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 users u ON mt.user_id = u.id
JOIN meetings m ON mt.meeting_id = m.id GROUP BY u.id, u.username
WHERE mt.attended = 1 AND m.is_completed = 1 ORDER BY percentage DESC, u.username ASC
GROUP BY u.username
ORDER BY total_attendance DESC
"; ";
$result = mysqli_query($conn, $sql_participation); $result = mysqli_query($conn, $sql_participation);
while ($row = mysqli_fetch_assoc($result)) { 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; $avg_attendance = 0;
$sql_avg_attendance = " $sql_avg_attendance = "
SELECT AVG(attended_count) AS avg_attended 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); $avg_attendance = round($row['avg_attended'], 2);
} }
// Durchschnittliche korrekte Farbe
$avg_wore_color = 0; $avg_wore_color = 0;
$sql_avg_wore_color = " $sql_avg_wore_color = "
SELECT AVG(wore_color_count) AS 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); $avg_wore_color = round($row['avg_wore_color'], 2);
} }
// Ranking: Farbe getragen // FARBE GETRAGEN: Sortiert nach Prozent, mit Prozentwert
$wore_color_stats = []; $wore_color_stats = [];
$wore_color_percentages = [];
$wore_color_attended = [];
$wore_color_count = [];
$sql_wore_color = " $sql_wore_color = "
SELECT SELECT
u.username, 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 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 users u ON mt.user_id = u.id
JOIN meetings m ON mt.meeting_id = m.id GROUP BY u.id, u.username
WHERE mt.wore_color = 1 AND m.is_completed = 1 ORDER BY percentage DESC, u.username ASC
GROUP BY u.username
ORDER BY wore_color_count DESC
"; ";
$result_wore = mysqli_query($conn, $sql_wore_color); $result_wore = mysqli_query($conn, $sql_wore_color);
while ($row = mysqli_fetch_assoc($result_wore)) { 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 = []; $reschedule_stats = [];
$sql_reschedule = " $sql_reschedule = "
SELECT SELECT u.username, COUNT(p.id) AS reschedule_count
u.username,
COUNT(p.id) AS reschedule_count
FROM meeting_reschedule_proposals p FROM meeting_reschedule_proposals p
JOIN users u ON p.proposed_by_user_id = u.id JOIN users u ON p.proposed_by_user_id = u.id
GROUP BY u.username GROUP BY u.username
ORDER BY reschedule_count DESC ORDER BY reschedule_count DESC, u.username ASC
"; ";
$result_reschedule = mysqli_query($conn, $sql_reschedule); $result_reschedule = mysqli_query($conn, $sql_reschedule);
while ($row = mysqli_fetch_assoc($result_reschedule)) { while ($row = mysqli_fetch_assoc($result_reschedule)) {
@@ -124,6 +168,7 @@ require_once 'inc/header.php';
<div class="col-lg-6"> <div class="col-lg-6">
<h5 class="card-title text-center">Teilnahme-Ranking</h5> <h5 class="card-title text-center">Teilnahme-Ranking</h5>
<p class="text-center text-muted mt-2 mb-3"> <p class="text-center text-muted mt-2 mb-3">
Insgesamt <?= $total_meetings ?> abgeschlossene Treffen.<br>
Durchschnittliche Anwesenheit je Treffen: <strong><?= htmlspecialchars($avg_attendance) ?></strong> Durchschnittliche Anwesenheit je Treffen: <strong><?= htmlspecialchars($avg_attendance) ?></strong>
</p> </p>
<div style="height: 40vh;"> <div style="height: 40vh;">
@@ -146,7 +191,6 @@ require_once 'inc/header.php';
</div> </div>
</div> </div>
<!-- 🔹 NEUER BLOCK: Verschiebungsvorschläge -->
<hr class="my-4"> <hr class="my-4">
<div class="row justify-content-center"> <div class="row justify-content-center">
@@ -160,29 +204,26 @@ require_once 'inc/header.php';
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// Farbhäufigkeit // Farben (unverändert)
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
}]
};
new Chart(document.getElementById('colorChart'), { new Chart(document.getElementById('colorChart'), {
type: 'pie', type: 'pie',
data: colorData, data: {
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
}]
},
options: { options: {
responsive: true, responsive: true,
plugins: { plugins: {
@@ -191,26 +232,25 @@ require_once 'inc/header.php';
}, },
title: { title: {
display: true, display: true,
text: 'Verteilung der Farbwahl über alle Treffen' text: 'Verteilung der Farbwahl'
} }
} }
} }
}); });
// Teilnahme // Teilnahme: Mit Prozentwerten (0100%), sortiert nach Prozent
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
}]
};
new Chart(document.getElementById('participationChart'), { new Chart(document.getElementById('participationChart'), {
type: 'bar', type: 'bar',
data: participationData, data: {
labels: <?= json_encode(array_column($participation_stats, 'username')) ?>,
datasets: [{
label: 'Teilnahmequote (%)',
data: <?= json_encode($participation_percentages) ?>,
backgroundColor: 'rgba(54,162,235,0.8)',
borderColor: 'rgb(54,162,235)',
borderWidth: 1
}]
},
options: { options: {
indexAxis: 'y', indexAxis: 'y',
responsive: true, responsive: true,
@@ -221,21 +261,37 @@ require_once 'inc/header.php';
}, },
title: { title: {
display: true, display: true,
text: 'Anzahl der Teilnahmen pro Benutzer' text: 'Teilnahmequote (nur abgeschlossene Treffen mit Eintrag)'
},
tooltip: {
callbacks: {
label: function(ctx) {
const pct = ctx.raw;
const attended = <?= json_encode($participation_attended) ?>[ctx.dataIndex] || 0;
const reg = <?= json_encode($participation_registered) ?>[ctx.dataIndex] || 0;
return `${attended} von ${reg} (${pct}%)`;
}
}
} }
}, },
scales: { scales: {
x: { x: {
beginAtZero: true beginAtZero: true,
max: 100,
ticks: {
callback: function(value) {
return value + '%';
}
}
}, },
y: { y: {
ticks: { ticks: {
font: { font: {
size: 10 size: 10
}, },
callback: function(value) { callback: function(v) {
const username = this.getLabelForValue(value); const l = this.getLabelForValue(v);
return username.length > 15 ? username.substring(0, 15) + '...' : username; return l.length > 15 ? l.substring(0, 15) + '...' : l;
} }
} }
} }
@@ -243,20 +299,19 @@ require_once 'inc/header.php';
} }
}); });
// Farbe getragen // Farbe getragen: Mit Prozentwerten (0100%)
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
}]
};
new Chart(document.getElementById('woreColorChart'), { new Chart(document.getElementById('woreColorChart'), {
type: 'bar', type: 'bar',
data: woreColorData, data: {
labels: <?= json_encode(array_column($wore_color_stats, 'username')) ?>,
datasets: [{
label: 'Farbenquote (%)',
data: <?= json_encode($wore_color_percentages) ?>,
backgroundColor: 'rgba(75,192,192,0.8)',
borderColor: 'rgb(75,192,192)',
borderWidth: 1
}]
},
options: { options: {
indexAxis: 'y', indexAxis: 'y',
responsive: true, responsive: true,
@@ -267,14 +322,27 @@ require_once 'inc/header.php';
}, },
title: { title: {
display: true, display: true,
text: 'Anzahl der "Farbe getragen"-Einträge pro Benutzer' text: 'Farbenquote (nur bei Teilnahme)'
},
tooltip: {
callbacks: {
label: function(ctx) {
const pct = ctx.raw;
const wore = <?= json_encode($wore_color_count) ?>[ctx.dataIndex] || 0;
const att = <?= json_encode($wore_color_attended) ?>[ctx.dataIndex] || 0;
return `${wore} von ${att} Teilnahmen (${pct}%)`;
}
}
} }
}, },
scales: { scales: {
x: { x: {
beginAtZero: true, beginAtZero: true,
max: 100,
ticks: { ticks: {
stepSize: 1 callback: function(value) {
return value + '%';
}
} }
}, },
y: { y: {
@@ -282,9 +350,9 @@ require_once 'inc/header.php';
font: { font: {
size: 10 size: 10
}, },
callback: function(value) { callback: function(v) {
const username = this.getLabelForValue(value); const l = this.getLabelForValue(v);
return username.length > 15 ? username.substring(0, 15) + '...' : username; return l.length > 15 ? l.substring(0, 15) + '...' : l;
} }
} }
} }
@@ -292,20 +360,19 @@ require_once 'inc/header.php';
} }
}); });
// 🔹 NEU: Verschiebungsvorschläge // Verschiebungsvorschläge (unverändert ABER mit korrekter Syntax!)
const rescheduleData = {
labels: <?= json_encode(array_column($reschedule_stats, 'username')); ?>,
datasets: [{
label: 'Verschiebungsvorschläge',
data: <?= json_encode(array_column($reschedule_stats, 'reschedule_count')); ?>,
backgroundColor: 'rgba(255, 159, 64, 0.8)',
borderColor: 'rgb(255, 159, 64)',
borderWidth: 1
}]
};
new Chart(document.getElementById('rescheduleChart'), { new Chart(document.getElementById('rescheduleChart'), {
type: 'bar', type: 'bar',
data: rescheduleData, data: {
labels: <?= json_encode(array_column($reschedule_stats, 'username')) ?>,
datasets: [{
label: 'Vorschläge',
data: <?= json_encode(array_column($reschedule_stats, 'reschedule_count')) ?>,
backgroundColor: 'rgba(255,159,64,0.8)',
borderColor: 'rgb(255,159,64)',
borderWidth: 1
}]
},
options: { options: {
indexAxis: 'y', indexAxis: 'y',
responsive: true, responsive: true,
@@ -316,7 +383,7 @@ require_once 'inc/header.php';
}, },
title: { title: {
display: true, display: true,
text: 'Anzahl der Verschiebungsvorschläge pro Benutzer' text: 'Verschiebungsvorschläge'
} }
}, },
scales: { scales: {
@@ -331,9 +398,9 @@ require_once 'inc/header.php';
font: { font: {
size: 10 size: 10
}, },
callback: function(value) { callback: function(v) {
const username = this.getLabelForValue(value); const l = this.getLabelForValue(v);
return username.length > 15 ? username.substring(0, 15) + '...' : username; return l.length > 15 ? l.substring(0, 15) + '...' : l;
} }
} }
} }