Erweitert die Trainingsstatistik-Funktionalität im TrainingStatsController, um die Anzahl der Trainings in den letzten 12 und 3 Monaten zu berechnen und zurückzugeben. Aktualisiert die Benutzeroberfläche in TrainingStatsView.vue zur Anzeige dieser neuen Daten. Ändert die Navigation in App.vue, um direkt zu den Trainingsstatistiken zu führen.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user