feat(tournament): enhance tournament group handling for pools and classes
- Updated TournamentService to manage participant class IDs more effectively in pooled groups, ensuring accurate statistics and match handling. - Refactored TournamentGroupsTab and TournamentPlacementsTab components to utilize a new method for retrieving group rankings based on class ID, improving data organization. - Adjusted getLivePosition method to accommodate group objects, enhancing flexibility in live match updates. - Improved group ranking logic to support multiple entries per group and class, ensuring accurate display of tournament standings.
This commit is contained in:
@@ -1656,12 +1656,30 @@ class TournamentService {
|
||||
}
|
||||
|
||||
classGroups.forEach((g, idx) => {
|
||||
// Berechne Rankings für diese Gruppe
|
||||
// Bei zusammengeführten Klassen (Pool): Teilnehmer-classId pro ID
|
||||
const participantIdToClassId = {};
|
||||
for (const tm of g.tournamentGroupMembers || []) {
|
||||
participantIdToClassId[tm.id] = tm.classId ?? g.classId;
|
||||
}
|
||||
for (const ext of g.externalGroupMembers || []) {
|
||||
participantIdToClassId[ext.id] = ext.classId ?? g.classId;
|
||||
}
|
||||
const classIdsInGroup = [...new Set(Object.values(participantIdToClassId).filter(c => c != null))];
|
||||
const isPool = !!g.poolId || classIdsInGroup.length > 1;
|
||||
const participantClassIds = isPool && classIdsInGroup.length > 0 ? classIdsInGroup : [g.classId];
|
||||
|
||||
participantClassIds.forEach((participantClassId) => {
|
||||
const stats = {};
|
||||
|
||||
const effectiveClassId = isPool ? participantClassId : g.classId;
|
||||
|
||||
if (isDoubles && pairingsByGroup[g.id]) {
|
||||
// Bei Doppel: Verwende Paarungen
|
||||
// Bei Doppel: Verwende Paarungen (bei Pool nur Paarungen dieser Klasse)
|
||||
for (const pairing of pairingsByGroup[g.id]) {
|
||||
if (isPool) {
|
||||
const c1 = pairing.member1?.classId ?? pairing.external1?.classId ?? g.classId;
|
||||
const c2 = pairing.member2?.classId ?? pairing.external2?.classId ?? g.classId;
|
||||
if (c1 !== effectiveClassId || c2 !== effectiveClassId) continue;
|
||||
}
|
||||
const player1Name = pairing.member1?.member
|
||||
? `${pairing.member1.member.firstName} ${pairing.member1.member.lastName}`
|
||||
: pairing.external1
|
||||
@@ -1695,9 +1713,9 @@ class TournamentService {
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Bei Einzel: Verwende einzelne Spieler
|
||||
// Interne Teilnehmer
|
||||
// Bei Einzel: Verwende einzelne Spieler (bei Pool nur Teilnehmer dieser Klasse)
|
||||
for (const tm of g.tournamentGroupMembers || []) {
|
||||
if (isPool && (tm.classId ?? g.classId) !== effectiveClassId) continue;
|
||||
stats[tm.id] = {
|
||||
id: tm.id,
|
||||
name: `${tm.member.firstName} ${tm.member.lastName}`,
|
||||
@@ -1714,9 +1732,8 @@ class TournamentService {
|
||||
matchesLost: 0
|
||||
};
|
||||
}
|
||||
|
||||
// Externe Teilnehmer
|
||||
for (const ext of g.externalGroupMembers || []) {
|
||||
if (isPool && (ext.classId ?? g.classId) !== effectiveClassId) continue;
|
||||
stats[ext.id] = {
|
||||
id: ext.id,
|
||||
name: `${ext.firstName} ${ext.lastName}`,
|
||||
@@ -1735,8 +1752,13 @@ class TournamentService {
|
||||
}
|
||||
}
|
||||
|
||||
// Berechne Statistiken aus Matches
|
||||
// Berechne Statistiken aus Matches (bei Pool nur Spiele innerhalb derselben Klasse)
|
||||
for (const m of groupMatches.filter(m => m.groupId === g.id)) {
|
||||
if (isPool) {
|
||||
const c1 = participantIdToClassId[m.player1Id];
|
||||
const c2 = participantIdToClassId[m.player2Id];
|
||||
if (c1 !== effectiveClassId || c2 !== effectiveClassId) continue;
|
||||
}
|
||||
if (isDoubles) {
|
||||
// Bei Doppel: Finde die Paarungen für player1Id und player2Id
|
||||
const pairing1Key = Object.keys(stats).find(key =>
|
||||
@@ -2020,10 +2042,11 @@ class TournamentService {
|
||||
|
||||
result.push({
|
||||
groupId: g.id,
|
||||
classId: g.classId,
|
||||
classId: effectiveClassId,
|
||||
groupNumber: idx + 1, // Nummer innerhalb der Klasse
|
||||
participants: participantsWithPosition
|
||||
});
|
||||
}); // participantClassIds.forEach
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user