tiebreakers

This commit is contained in:
yohlo
2026-03-01 19:43:29 -06:00
parent c7487e37f2
commit f6da7be404

View File

@@ -137,9 +137,9 @@ const GroupStageView: React.FC<GroupStageViewProps> = ({
}); });
}); });
groupMatches const completedMatches = groupMatches.filter((match) => match.status === "ended");
.filter((match) => match.status === "ended")
.forEach((match) => { completedMatches.forEach((match) => {
const homeId = match.home?.id; const homeId = match.home?.id;
const awayId = match.away?.id; const awayId = match.away?.id;
@@ -170,10 +170,70 @@ const GroupStageView: React.FC<GroupStageViewProps> = ({
} }
}); });
const h2hRecords = new Map<string, Map<string, { wins: number; cupDiff: number }>>();
completedMatches.forEach((match) => {
const homeId = match.home?.id;
const awayId = match.away?.id;
if (!homeId || !awayId) return;
if (!h2hRecords.has(homeId)) {
h2hRecords.set(homeId, new Map());
}
if (!h2hRecords.has(awayId)) {
h2hRecords.set(awayId, new Map());
}
const homeH2H = h2hRecords.get(homeId)!;
const awayH2H = h2hRecords.get(awayId)!;
if (!homeH2H.has(awayId)) {
homeH2H.set(awayId, { wins: 0, cupDiff: 0 });
}
if (!awayH2H.has(homeId)) {
awayH2H.set(homeId, { wins: 0, cupDiff: 0 });
}
const homeRecord = homeH2H.get(awayId)!;
const awayRecord = awayH2H.get(homeId)!;
const homeCups = match.home_cups || 0;
const awayCups = match.away_cups || 0;
const cupDiff = homeCups - awayCups;
homeRecord.cupDiff += cupDiff;
awayRecord.cupDiff -= cupDiff;
if (homeCups > awayCups) {
homeRecord.wins++;
} else if (awayCups > homeCups) {
awayRecord.wins++;
}
});
return Array.from(standings.values()).sort((a, b) => { return Array.from(standings.values()).sort((a, b) => {
if (b.wins !== a.wins) return b.wins - a.wins; if (b.wins !== a.wins) return b.wins - a.wins;
if (b.cupDifference !== a.cupDifference) return b.cupDifference - a.cupDifference; if (b.cupDifference !== a.cupDifference) return b.cupDifference - a.cupDifference;
return b.cupsFor - a.cupsFor;
if (b.cupsFor !== a.cupsFor) return b.cupsFor - a.cupsFor;
const aH2H = h2hRecords.get(a.teamId);
const bH2H = h2hRecords.get(b.teamId);
if (aH2H && bH2H) {
const aVsB = aH2H.get(b.teamId);
const bVsA = bH2H.get(a.teamId);
if (aVsB && bVsA) {
if (aVsB.wins !== bVsA.wins) return bVsA.wins - aVsB.wins;
if (aVsB.cupDiff !== -bVsA.cupDiff) return aVsB.cupDiff - (-bVsA.cupDiff);
}
}
return a.teamId.localeCompare(b.teamId);
}); });
}; };