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 {