Added best mode stats
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { getCopsAndCrimsModeName, getCopsAndCrimsModeStats } from "@/lib/hypixel/copsandcrims/general"
|
||||
import { getCopsAndCrimsBestMode, getCopsAndCrimsModeName, getCopsAndCrimsModeStats } from "@/lib/hypixel/copsandcrims/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export default function CopsAndCrimsStatTable({ stats }: { stats: NonNullable<NonNullStats["CopsAndCrims"]> }) {
|
||||
return (
|
||||
@@ -44,10 +45,12 @@ function CopsAndCrimsTableStat(
|
||||
stats: NonNullable<NonNullStats["CopsAndCrims"]>
|
||||
}
|
||||
) {
|
||||
const modeStats = getCopsAndCrimsModeStats(modeId === "regular" ? "" : modeId, stats)
|
||||
const name = getCopsAndCrimsModeName(modeId === "regular" ? "" : modeId)
|
||||
const modeStats = getCopsAndCrimsModeStats(modeId === "regular" ? "" : modeId, stats)
|
||||
const isBest = getCopsAndCrimsBestMode(stats) === modeId
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableRow className={cn(isBest && "text-mc-light-purple")}>
|
||||
<TableCell>{name}</TableCell>
|
||||
{modeStats.map((v, i) => {
|
||||
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
||||
|
||||
@@ -6,9 +6,12 @@ import {
|
||||
getMegaWallsClass,
|
||||
getMegaWallsDifficultyColor,
|
||||
getMegaWallsModeName,
|
||||
getMegaWallsModeStats
|
||||
getMegaWallsModeStats,
|
||||
getMegaWallsMostPlayedClass,
|
||||
getMegaWallsMostPlayedMode
|
||||
} from "@/lib/hypixel/megawalls/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export function MegaWallsModesTable({ stats }: { stats: NonNullable<NonNullStats["MegaWalls"]> }) {
|
||||
return (
|
||||
@@ -90,8 +93,9 @@ function MegaWallsClassStats({ stats }: { stats: NonNullable<NonNullStats["MegaW
|
||||
const { id, val } = c
|
||||
const klass = getMegaWallsClass(id)
|
||||
const difColor = getMegaWallsDifficultyColor(klass.difficulty)
|
||||
const isBest = getMegaWallsMostPlayedClass(stats)?.id === id
|
||||
return (
|
||||
<TableRow key={i}>
|
||||
<TableRow key={i} className={cn(isBest && "text-mc-light-purple")}>
|
||||
<TableCell className={`text-mc-${difColor}`}>{klass.name}</TableCell>
|
||||
{val.map((v, j) => {
|
||||
if (j === val.length - 2) {
|
||||
@@ -111,9 +115,10 @@ function MegaWallsModeStat(
|
||||
) {
|
||||
const modeName = getMegaWallsModeName(modeId)
|
||||
const modeStat = getMegaWallsModeStats(modeId, stats)
|
||||
const mostPlayed = getMegaWallsMostPlayedMode(stats) === modeId
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableRow className={cn(mostPlayed && "text-mc-light-purple")}>
|
||||
<TableCell>{modeName}</TableCell>
|
||||
{modeStat.map((s, i) => {
|
||||
return <TableCell key={i}>{formatNumber(s)}</TableCell>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { getUHCModeName, getUHCModeStats } from "@/lib/hypixel/uhc/general"
|
||||
import { getUHCBestMode, getUHCModeName, getUHCModeStats } from "@/lib/hypixel/uhc/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
@@ -49,9 +49,10 @@ function TableStat(
|
||||
) {
|
||||
const modeStats = getUHCModeStats(modeId === "teams" ? "" : modeId, stats)
|
||||
const modeName = getUHCModeName(modeId === "teams" || modeId === "all_modes" ? "" : modeId)
|
||||
const isBest = getUHCBestMode(stats) === modeId
|
||||
|
||||
return (
|
||||
<TableRow className={cn(modeId === "all_modes" && "font-bold")}>
|
||||
<TableRow className={cn(modeId === "all_modes" && "font-bold", isBest && "text-mc-light-purple")}>
|
||||
<TableCell>{modeId === "all_modes" ? "Overall" : modeName}</TableCell>
|
||||
{modeStats.map((v, i) => {
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { getWoolGamesWoolWarsClass, getWoolGamesWoolWarsClassColor, getWoolGamesWoolWarsClassStats } from "@/lib/hypixel/woolgames/general"
|
||||
import {
|
||||
getWoolGamesWoolWarsClass,
|
||||
getWoolGamesWoolWarsClassColor,
|
||||
getWoolGamesWoolWarsClassStats,
|
||||
getWoolGamesWoolWarsMostPlayedClass
|
||||
} from "@/lib/hypixel/woolgames/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
@@ -52,9 +57,10 @@ function StatRow(
|
||||
const classStats = getWoolGamesWoolWarsClassStats(classId, stats)
|
||||
const klass = getWoolGamesWoolWarsClass(classId)
|
||||
const classColor = getWoolGamesWoolWarsClassColor(klass?.difficulty)
|
||||
const isMostPlayed = getWoolGamesWoolWarsMostPlayedClass(stats)?.id === classId
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableRow className={cn(isMostPlayed && "text-mc-light-purple")}>
|
||||
<TableCell className={cn(classColor && `text-mc-${classColor}`)}>{klass !== null ? klass.name : "Unknown"}</TableCell>
|
||||
{classStats.map((v, i) => {
|
||||
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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}`],
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user