From 648b60803602892d3d8c09d56e0e49517a87375a Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 1 Oct 2025 13:01:54 +0200 Subject: [PATCH] =?UTF-8?q?Erweitert=20die=20Trainingsstatistik-Funktional?= =?UTF-8?q?it=C3=A4t=20im=20TrainingStatsController,=20um=20die=20Anzahl?= =?UTF-8?q?=20der=20Trainings=20in=20den=20letzten=2012=20und=203=20Monate?= =?UTF-8?q?n=20zu=20berechnen=20und=20zur=C3=BCckzugeben.=20Aktualisiert?= =?UTF-8?q?=20die=20Benutzeroberfl=C3=A4che=20in=20TrainingStatsView.vue?= =?UTF-8?q?=20zur=20Anzeige=20dieser=20neuen=20Daten.=20=C3=84ndert=20die?= =?UTF-8?q?=20Navigation=20in=20App.vue,=20um=20direkt=20zu=20den=20Traini?= =?UTF-8?q?ngsstatistiken=20zu=20f=C3=BChren.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/trainingStatsController.js | 26 ++++++++++++++++++- frontend/src/App.vue | 4 +-- frontend/src/views/TrainingStatsView.vue | 14 ++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/backend/controllers/trainingStatsController.js b/backend/controllers/trainingStatsController.js index 4f26782..136faa5 100644 --- a/backend/controllers/trainingStatsController.js +++ b/backend/controllers/trainingStatsController.js @@ -19,6 +19,25 @@ class TrainingStatsController { } }); + // Anzahl der Trainings im jeweiligen Zeitraum berechnen + const trainingsCount12Months = await DiaryDate.count({ + where: { + clubId: parseInt(clubId), + date: { + [Op.gte]: twelveMonthsAgo + } + } + }); + + const trainingsCount3Months = await DiaryDate.count({ + where: { + clubId: parseInt(clubId), + date: { + [Op.gte]: threeMonthsAgo + } + } + }); + const stats = []; for (const member of members) { @@ -116,7 +135,12 @@ class TrainingStatsController { // Nach Gesamtteilnahme absteigend sortieren stats.sort((a, b) => b.participationTotal - a.participationTotal); - res.json(stats); + // Zusätzliche Metadaten mit Trainingsanzahl zurückgeben + res.json({ + members: stats, + trainingsCount12Months, + trainingsCount3Months + }); } catch (error) { console.error('Fehler beim Laden der Trainings-Statistik:', error); diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 2baee48..b661e2e 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -133,7 +133,7 @@ export default { if (newVal === 'new') { this.$router.push('/createclub'); } else if (newVal) { - this.$router.push(`/showclub/${newVal}`); + this.$router.push('/training-stats'); } }, isAuthenticated(newVal) { @@ -171,7 +171,7 @@ export default { loadClub() { this.setCurrentClub(this.currentClub); - this.$router.push(`/showclub/${this.currentClub}`); + this.$router.push('/training-stats'); }, async checkSession() { diff --git a/frontend/src/views/TrainingStatsView.vue b/frontend/src/views/TrainingStatsView.vue index 8f1dec2..8c049b0 100644 --- a/frontend/src/views/TrainingStatsView.vue +++ b/frontend/src/views/TrainingStatsView.vue @@ -126,15 +126,15 @@ export default { ...mapGetters(['isAuthenticated', 'currentClub']), averageParticipation12Months() { - if (this.activeMembers.length === 0) return 0; + if (this.trainingsCount12Months === 0) return 0; const total = this.activeMembers.reduce((sum, member) => sum + member.participation12Months, 0); - return total / this.activeMembers.length; + return total / this.trainingsCount12Months; }, averageParticipation3Months() { - if (this.activeMembers.length === 0) return 0; + if (this.trainingsCount3Months === 0) return 0; const total = this.activeMembers.reduce((sum, member) => sum + member.participation3Months, 0); - return total / this.activeMembers.length; + return total / this.trainingsCount3Months; }, sortedMembers() { @@ -167,6 +167,8 @@ export default { data() { return { activeMembers: [], + trainingsCount12Months: 0, + trainingsCount3Months: 0, showDetailsModal: false, selectedMember: {}, loading: false, @@ -199,7 +201,9 @@ export default { this.loading = true; try { const response = await apiClient.get(`/training-stats/${this.currentClub}`); - this.activeMembers = response.data; + this.activeMembers = response.data.members || []; + this.trainingsCount12Months = response.data.trainingsCount12Months || 0; + this.trainingsCount3Months = response.data.trainingsCount3Months || 0; } catch (error) { // Kein Alert - es ist normal, dass nicht alle Daten verfügbar sind } finally {