Added first part of duel stats

This commit is contained in:
2025-09-01 14:53:52 +02:00
parent 3c0d577aa6
commit 22eb67d5d1
7 changed files with 254 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
import { DIVISIONS, MODES } from "@/data/hypixel/duels"
import { NonNullStats } from "@/lib/schema/player"
type DuelType = "all_modes"
export function getDivision(duelType: DuelType, stats: NonNullable<NonNullStats["Duels"]>) {
for (const div of DIVISIONS.slice().reverse()) {
const index = `${duelType}_${div.id}_title_prestige` as const
const val = stats[index]
if (val > 0) {
return {
name: div.name,
level: val,
color: div.color
}
}
}
return null
}
export function getMostPlayed(stats: NonNullable<NonNullStats["Duels"]>) {
let mostPlayed: typeof MODES[number] | null = null
let mostPlays = 0
for (const mode of MODES) {
const plays = stats[`${mode.id}_wins`] + stats[`${mode.id}_losses`]
if (plays > mostPlays && mode.id) {
mostPlays = plays
mostPlayed = mode
}
}
return mostPlayed
}

View File

@@ -33,13 +33,40 @@ export function concatStatsArray<T extends Record<string, number>>(keys: (keyof
return base as T
}
export function romanize(num: number): string {
export function romanize(num: number) {
if (!Number.isFinite(num)) return "NaN"
const digits = Math.trunc(num).toString().split("")
const key = [
"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","I","II","III","IV","V","VI","VII","VIII","IX"
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM",
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC",
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX"
] as const
let roman = ""