import type { Scope } from "../repositories/scoreboardCacheRepository"; import type { RankSnapshot } from "../types/panit"; export function computePercentile(rank: number, totalCount: number): number { if (totalCount <= 0) return 0; return Math.round((1 - (rank - 1) / totalCount) * 100); } export function deltaFor( snapshot: RankSnapshot | undefined, currentRank: number, scope: Scope ): number | null { if (!snapshot) return null; if (scope.kind === "overall") return snapshot.overall - currentRank; if (snapshot.teamCode !== scope.teamCode || snapshot.team === undefined) { return null; } return snapshot.team - currentRank; }