diff --git a/app/features/tournament/core/Standings.ts b/app/features/tournament/core/Standings.ts index a255af285..c95e14501 100644 --- a/app/features/tournament/core/Standings.ts +++ b/app/features/tournament/core/Standings.ts @@ -114,7 +114,7 @@ export function tournamentStandings(tournament: Tournament): Standing[] { const standings = standingsToMergeable({ alreadyIncludedTeamIds, standings: bracket.standings, - teamsAboveCount: alreadyIncludedTeamIds.size, + teamsAboveFromAnotherBracketsCount: alreadyIncludedTeamIds.size, }); result.push(...standings); @@ -134,11 +134,11 @@ function standingsToMergeable< >({ alreadyIncludedTeamIds, standings, - teamsAboveCount, + teamsAboveFromAnotherBracketsCount, }: { alreadyIncludedTeamIds: Set; standings: T[]; - teamsAboveCount: number; + teamsAboveFromAnotherBracketsCount: number; }) { const result: T[] = []; @@ -146,17 +146,24 @@ function standingsToMergeable< (standing) => !alreadyIncludedTeamIds.has(standing.team.id), ); - let placement = teamsAboveCount + 1; + // e.g. if standings start at 3rd place, this must mean there is 2 teams left to finish _this_ bracket + const unfinishedTeamsCount = (standings.at(0)?.placement ?? 1) - 1; + + let placement = 1; for (const [i, standing] of filtered.entries()) { const placementChanged = i !== 0 && standing.placement !== filtered[i - 1].placement; if (placementChanged) { - placement = teamsAboveCount + i + 1; + placement = i + 1; } - result.push({ ...standing, placement }); + result.push({ + ...standing, + placement: + placement + teamsAboveFromAnotherBracketsCount + unfinishedTeamsCount, + }); } return result;