Added best mode stats

This commit is contained in:
2025-09-14 21:05:12 +02:00
parent 3711b43b4e
commit 0d7c79a310
8 changed files with 113 additions and 10 deletions

View File

@@ -46,6 +46,18 @@ export function getCopsAndCrimsScoreColor(score: number) {
return SCORE.at(0)!.color
}
export function getCopsAndCrimsBestMode(stats: NonNullable<NonNullStats["CopsAndCrims"]>) {
const modeWins = MODES.map(mode => ({
mode: mode.id,
name: mode.name,
wins: mode.id === "" ? stats["game_wins"] : stats[`game_wins_${mode.id}`] || 0
}))
const best = modeWins.reduce((best, current) => current.wins > best.wins ? current : best).mode
return best === "" ? "regular" : best
}
export function getCopsAndCrimsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable<NonNullStats["CopsAndCrims"]>) {
if (modeId === "") {
return [

View File

@@ -32,6 +32,24 @@ export function getMegaWallsClass(classId: typeof CLASSES[number]["id"]) {
return CLASSES.find(c => c.id === classId)!
}
export function getMegaWallsMostPlayedClass(stats: NonNullable<NonNullStats["MegaWalls"]>) {
let mostPlayedClass: typeof CLASSES[number] | null = null
let maxPlays = 0
for (const classObj of CLASSES) {
const wins = stats[`${classObj.id}_wins`] || 0
const losses = stats[`${classObj.id}_losses`] || 0
const totalPlays = wins + losses
if (totalPlays > maxPlays) {
maxPlays = totalPlays
mostPlayedClass = classObj
}
}
return mostPlayedClass
}
export function getAllMegawallsClassStats(stats: NonNullable<NonNullStats["MegaWalls"]>) {
const statsArr: { id: typeof CLASSES[number]["id"], val: number[] }[] = []
@@ -58,6 +76,27 @@ export function getMegaWallsClassStats(classId: typeof CLASSES[number]["id"], st
]
}
export function getMegaWallsMostPlayedMode(stats: NonNullable<NonNullStats["MegaWalls"]>) {
const modes = [
{
id: "standard" as const,
games: (stats.wins_standard || 0) + (stats.losses_standard || 0)
},
{
id: "face_off" as const,
games: (stats.wins_face_off || 0) + (stats.losses_face_off || 0)
},
{
id: "gvg" as const,
games: (stats.wins_gvg || 0) + (stats.losses_gvg || 0)
}
]
const mostPlayed = modes.reduce((max, current) => current.games > max.games ? current : max)
return mostPlayed.id
}
export function getMegaWallsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable<NonNullStats["MegaWalls"]>) {
return [
stats[`kills_${modeId}`],

View File

@@ -11,6 +11,24 @@ export function getUHCStatsCombined(stats: NonNullable<NonNullStats["UHC"]>) {
}
}
export function getUHCBestMode(stats: NonNullable<NonNullStats["UHC"]>) {
let bestMode = MODES[0] as typeof MODES[number]
let maxScore = 0
for (const mode of MODES) {
const modeWins = mode.id === "" ? stats.wins : stats[`wins_${mode.id}`] ?? 0
const modeDeaths = mode.id === "" ? stats.deaths : stats[`deaths_${mode.id}`] ?? 0
const combinedScore = modeWins + modeDeaths
if (combinedScore > maxScore) {
maxScore = combinedScore
bestMode = mode
}
}
return bestMode.id === "" ? "teams" : bestMode.id
}
export function getUHCModeName(modeId: typeof MODES[number]["id"]) {
return MODES.find(m => m.id === modeId)!.name
}

View File

@@ -3,6 +3,25 @@ import { getColorFromCode } from "@/lib/colors"
import { NonNullStats } from "@/lib/schema/player"
import { devide, floorLevel } from "../general"
export function getWoolGamesWoolWarsMostPlayedClass(stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]) {
if (!stats?.stats?.classes) return null
let mostPlayedClass = null
let maxKills = 0
for (const classData of CLASSES) {
const classStats = stats.stats.classes[classData.id]
const kills = classStats?.kills || 0
if (kills > maxKills) {
maxKills = kills
mostPlayedClass = classData
}
}
return mostPlayedClass
}
export function getWoolGamesWoolWarsClassStats(
classId: typeof CLASSES[number]["id"],
stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]