tiebreakers
This commit is contained in:
@@ -137,43 +137,103 @@ const GroupStageView: React.FC<GroupStageViewProps> = ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
groupMatches
|
const completedMatches = groupMatches.filter((match) => match.status === "ended");
|
||||||
.filter((match) => match.status === "ended")
|
|
||||||
.forEach((match) => {
|
|
||||||
const homeId = match.home?.id;
|
|
||||||
const awayId = match.away?.id;
|
|
||||||
|
|
||||||
if (!homeId || !awayId) return;
|
completedMatches.forEach((match) => {
|
||||||
|
const homeId = match.home?.id;
|
||||||
|
const awayId = match.away?.id;
|
||||||
|
|
||||||
const homeStanding = standings.get(homeId);
|
if (!homeId || !awayId) return;
|
||||||
const awayStanding = standings.get(awayId);
|
|
||||||
|
|
||||||
if (!homeStanding || !awayStanding) return;
|
const homeStanding = standings.get(homeId);
|
||||||
|
const awayStanding = standings.get(awayId);
|
||||||
|
|
||||||
const homeCups = match.home_cups || 0;
|
if (!homeStanding || !awayStanding) return;
|
||||||
const awayCups = match.away_cups || 0;
|
|
||||||
|
|
||||||
homeStanding.cupsFor += homeCups;
|
const homeCups = match.home_cups || 0;
|
||||||
homeStanding.cupsAgainst += awayCups;
|
const awayCups = match.away_cups || 0;
|
||||||
awayStanding.cupsFor += awayCups;
|
|
||||||
awayStanding.cupsAgainst += homeCups;
|
|
||||||
|
|
||||||
homeStanding.cupDifference += homeCups - awayCups;
|
homeStanding.cupsFor += homeCups;
|
||||||
awayStanding.cupDifference += awayCups - homeCups;
|
homeStanding.cupsAgainst += awayCups;
|
||||||
|
awayStanding.cupsFor += awayCups;
|
||||||
|
awayStanding.cupsAgainst += homeCups;
|
||||||
|
|
||||||
if (homeCups > awayCups) {
|
homeStanding.cupDifference += homeCups - awayCups;
|
||||||
homeStanding.wins++;
|
awayStanding.cupDifference += awayCups - homeCups;
|
||||||
awayStanding.losses++;
|
|
||||||
} else if (awayCups > homeCups) {
|
if (homeCups > awayCups) {
|
||||||
awayStanding.wins++;
|
homeStanding.wins++;
|
||||||
homeStanding.losses++;
|
awayStanding.losses++;
|
||||||
}
|
} else if (awayCups > homeCups) {
|
||||||
});
|
awayStanding.wins++;
|
||||||
|
homeStanding.losses++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user