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 { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||||
import { formatNumber } from "@/lib/formatters"
|
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 { NonNullStats } from "@/lib/schema/player"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
export default function CopsAndCrimsStatTable({ stats }: { stats: NonNullable<NonNullStats["CopsAndCrims"]> }) {
|
export default function CopsAndCrimsStatTable({ stats }: { stats: NonNullable<NonNullStats["CopsAndCrims"]> }) {
|
||||||
return (
|
return (
|
||||||
@@ -44,10 +45,12 @@ function CopsAndCrimsTableStat(
|
|||||||
stats: NonNullable<NonNullStats["CopsAndCrims"]>
|
stats: NonNullable<NonNullStats["CopsAndCrims"]>
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const modeStats = getCopsAndCrimsModeStats(modeId === "regular" ? "" : modeId, stats)
|
|
||||||
const name = getCopsAndCrimsModeName(modeId === "regular" ? "" : modeId)
|
const name = getCopsAndCrimsModeName(modeId === "regular" ? "" : modeId)
|
||||||
|
const modeStats = getCopsAndCrimsModeStats(modeId === "regular" ? "" : modeId, stats)
|
||||||
|
const isBest = getCopsAndCrimsBestMode(stats) === modeId
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow className={cn(isBest && "text-mc-light-purple")}>
|
||||||
<TableCell>{name}</TableCell>
|
<TableCell>{name}</TableCell>
|
||||||
{modeStats.map((v, i) => {
|
{modeStats.map((v, i) => {
|
||||||
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import {
|
|||||||
getMegaWallsClass,
|
getMegaWallsClass,
|
||||||
getMegaWallsDifficultyColor,
|
getMegaWallsDifficultyColor,
|
||||||
getMegaWallsModeName,
|
getMegaWallsModeName,
|
||||||
getMegaWallsModeStats
|
getMegaWallsModeStats,
|
||||||
|
getMegaWallsMostPlayedClass,
|
||||||
|
getMegaWallsMostPlayedMode
|
||||||
} from "@/lib/hypixel/megawalls/general"
|
} from "@/lib/hypixel/megawalls/general"
|
||||||
import { NonNullStats } from "@/lib/schema/player"
|
import { NonNullStats } from "@/lib/schema/player"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
export function MegaWallsModesTable({ stats }: { stats: NonNullable<NonNullStats["MegaWalls"]> }) {
|
export function MegaWallsModesTable({ stats }: { stats: NonNullable<NonNullStats["MegaWalls"]> }) {
|
||||||
return (
|
return (
|
||||||
@@ -90,8 +93,9 @@ function MegaWallsClassStats({ stats }: { stats: NonNullable<NonNullStats["MegaW
|
|||||||
const { id, val } = c
|
const { id, val } = c
|
||||||
const klass = getMegaWallsClass(id)
|
const klass = getMegaWallsClass(id)
|
||||||
const difColor = getMegaWallsDifficultyColor(klass.difficulty)
|
const difColor = getMegaWallsDifficultyColor(klass.difficulty)
|
||||||
|
const isBest = getMegaWallsMostPlayedClass(stats)?.id === id
|
||||||
return (
|
return (
|
||||||
<TableRow key={i}>
|
<TableRow key={i} className={cn(isBest && "text-mc-light-purple")}>
|
||||||
<TableCell className={`text-mc-${difColor}`}>{klass.name}</TableCell>
|
<TableCell className={`text-mc-${difColor}`}>{klass.name}</TableCell>
|
||||||
{val.map((v, j) => {
|
{val.map((v, j) => {
|
||||||
if (j === val.length - 2) {
|
if (j === val.length - 2) {
|
||||||
@@ -111,9 +115,10 @@ function MegaWallsModeStat(
|
|||||||
) {
|
) {
|
||||||
const modeName = getMegaWallsModeName(modeId)
|
const modeName = getMegaWallsModeName(modeId)
|
||||||
const modeStat = getMegaWallsModeStats(modeId, stats)
|
const modeStat = getMegaWallsModeStats(modeId, stats)
|
||||||
|
const mostPlayed = getMegaWallsMostPlayedMode(stats) === modeId
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow className={cn(mostPlayed && "text-mc-light-purple")}>
|
||||||
<TableCell>{modeName}</TableCell>
|
<TableCell>{modeName}</TableCell>
|
||||||
{modeStat.map((s, i) => {
|
{modeStat.map((s, i) => {
|
||||||
return <TableCell key={i}>{formatNumber(s)}</TableCell>
|
return <TableCell key={i}>{formatNumber(s)}</TableCell>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||||
import { formatNumber } from "@/lib/formatters"
|
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 { NonNullStats } from "@/lib/schema/player"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -49,9 +49,10 @@ function TableStat(
|
|||||||
) {
|
) {
|
||||||
const modeStats = getUHCModeStats(modeId === "teams" ? "" : modeId, stats)
|
const modeStats = getUHCModeStats(modeId === "teams" ? "" : modeId, stats)
|
||||||
const modeName = getUHCModeName(modeId === "teams" || modeId === "all_modes" ? "" : modeId)
|
const modeName = getUHCModeName(modeId === "teams" || modeId === "all_modes" ? "" : modeId)
|
||||||
|
const isBest = getUHCBestMode(stats) === modeId
|
||||||
|
|
||||||
return (
|
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>
|
<TableCell>{modeId === "all_modes" ? "Overall" : modeName}</TableCell>
|
||||||
{modeStats.map((v, i) => {
|
{modeStats.map((v, i) => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||||
import { formatNumber } from "@/lib/formatters"
|
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 { NonNullStats } from "@/lib/schema/player"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -52,9 +57,10 @@ function StatRow(
|
|||||||
const classStats = getWoolGamesWoolWarsClassStats(classId, stats)
|
const classStats = getWoolGamesWoolWarsClassStats(classId, stats)
|
||||||
const klass = getWoolGamesWoolWarsClass(classId)
|
const klass = getWoolGamesWoolWarsClass(classId)
|
||||||
const classColor = getWoolGamesWoolWarsClassColor(klass?.difficulty)
|
const classColor = getWoolGamesWoolWarsClassColor(klass?.difficulty)
|
||||||
|
const isMostPlayed = getWoolGamesWoolWarsMostPlayedClass(stats)?.id === classId
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow className={cn(isMostPlayed && "text-mc-light-purple")}>
|
||||||
<TableCell className={cn(classColor && `text-mc-${classColor}`)}>{klass !== null ? klass.name : "Unknown"}</TableCell>
|
<TableCell className={cn(classColor && `text-mc-${classColor}`)}>{klass !== null ? klass.name : "Unknown"}</TableCell>
|
||||||
{classStats.map((v, i) => {
|
{classStats.map((v, i) => {
|
||||||
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ export function getCopsAndCrimsScoreColor(score: number) {
|
|||||||
return SCORE.at(0)!.color
|
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"]>) {
|
export function getCopsAndCrimsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable<NonNullStats["CopsAndCrims"]>) {
|
||||||
if (modeId === "") {
|
if (modeId === "") {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -32,6 +32,24 @@ export function getMegaWallsClass(classId: typeof CLASSES[number]["id"]) {
|
|||||||
return CLASSES.find(c => c.id === classId)!
|
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"]>) {
|
export function getAllMegawallsClassStats(stats: NonNullable<NonNullStats["MegaWalls"]>) {
|
||||||
const statsArr: { id: typeof CLASSES[number]["id"], val: number[] }[] = []
|
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"]>) {
|
export function getMegaWallsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable<NonNullStats["MegaWalls"]>) {
|
||||||
return [
|
return [
|
||||||
stats[`kills_${modeId}`],
|
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"]) {
|
export function getUHCModeName(modeId: typeof MODES[number]["id"]) {
|
||||||
return MODES.find(m => m.id === modeId)!.name
|
return MODES.find(m => m.id === modeId)!.name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,25 @@ import { getColorFromCode } from "@/lib/colors"
|
|||||||
import { NonNullStats } from "@/lib/schema/player"
|
import { NonNullStats } from "@/lib/schema/player"
|
||||||
import { devide, floorLevel } from "../general"
|
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(
|
export function getWoolGamesWoolWarsClassStats(
|
||||||
classId: typeof CLASSES[number]["id"],
|
classId: typeof CLASSES[number]["id"],
|
||||||
stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]
|
stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]
|
||||||
|
|||||||
Reference in New Issue
Block a user