13 lines
542 B
TypeScript
13 lines
542 B
TypeScript
const LEVEL_THRESHOLDS = [0, 10, 30, 70, 150, 300, 600, 1000] as const;
|
|
|
|
export function computeLevel(totalPredictions: number): { level: number; progress: number } {
|
|
let level = 1;
|
|
for (let i = 0; i < LEVEL_THRESHOLDS.length; i++) {
|
|
if (totalPredictions >= LEVEL_THRESHOLDS[i]) level = i + 1;
|
|
}
|
|
const min = LEVEL_THRESHOLDS[level - 1];
|
|
const next = LEVEL_THRESHOLDS[level];
|
|
const progress = next === undefined ? 1 : (totalPredictions - min) / (next - min);
|
|
return { level, progress: Math.max(0, Math.min(1, progress)) };
|
|
}
|