From 62f3e349b205fe61811df0647e76bd762b3ef4e3 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Sun, 8 Mar 2026 00:22:47 +1100 Subject: [PATCH] Round before rating comparisons for consistency with frontmatter --- src/utils/FrontmatterStats.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/FrontmatterStats.ts b/src/utils/FrontmatterStats.ts index c842b90..b3f3758 100644 --- a/src/utils/FrontmatterStats.ts +++ b/src/utils/FrontmatterStats.ts @@ -26,7 +26,7 @@ function anyEnabled(fm: FrontmatterPropertiesSettings): boolean { // Standard competition ranking ("1224" style) export function computeRanksForAll(cohort: CohortData): Map { const entries = Object.entries(cohort.players); - entries.sort((a, b) => b[1].rating - a[1].rating); + entries.sort((a, b) => Math.round(b[1].rating) - Math.round(a[1].rating)); const map = new Map(); let lastRating: number | undefined = undefined; @@ -35,9 +35,10 @@ export function computeRanksForAll(cohort: CohortData): Map { for (let i = 0; i < entries.length; i++) { const [id, player] = entries[i]; - if (lastRating === undefined || player.rating !== lastRating) { + const rounded = Math.round(player.rating); + if (lastRating === undefined || rounded !== lastRating) { rank = nextRank; - lastRating = player.rating; + lastRating = rounded; } map.set(id, rank); nextRank = i + 2; @@ -49,7 +50,10 @@ export function computeRanksForAll(cohort: CohortData): Map { // have a strictly higher rating (standard competition ranking) function computeRanksForSubset(cohort: CohortData, playerIds: string[]): Map { const targets = playerIds - .map((id) => ({ id, rating: cohort.players[id]?.rating })) + .map((id) => { + const r = cohort.players[id]?.rating; + return { id, rating: r !== undefined ? Math.round(r) : undefined }; + }) .filter((t): t is { id: string; rating: number } => t.rating !== undefined); if (targets.length === 0) return new Map(); @@ -58,8 +62,9 @@ function computeRanksForSubset(cohort: CohortData, playerIds: string[]): Map(targets.map((t) => [t.id, 0])); for (const player of Object.values(cohort.players)) { + const rounded = Math.round(player.rating); for (const t of targets) { - if (player.rating > t.rating) { + if (rounded > t.rating) { higherCounts.set(t.id, higherCounts.get(t.id)! + 1); } }