fix opponents tab winrate

This commit is contained in:
2025-04-24 14:11:18 +02:00
parent a20058403f
commit 801421a5ba

View File

@@ -92,14 +92,16 @@ const useColumns = () => {
<span <span
className={cn( className={cn(
'flex items-center justify-end font-medium font-mono', 'flex items-center justify-end font-medium font-mono',
winRate === 50 winRate !== null
? 'text-zink-800 dark:text-zink-200' ? winRate === 50
: winRate > 50 ? 'text-zink-800 dark:text-zink-200'
? 'text-emerald-500' : winRate > 50
: 'text-rose-500' ? 'text-emerald-500'
: 'text-rose-500'
: null
)} )}
> >
{Math.round(winRate)}% {winRate !== null ? `${Math.round(winRate)}%` : 'N/A'}
</span> </span>
) )
}, },
@@ -143,7 +145,7 @@ type Stats = {
opponentName: string opponentName: string
opponentId: string opponentId: string
totalMMRChange: number totalMMRChange: number
winRate: number winRate: number | null
} }
function RawOpponentsTable({ games }: { games: SelectGames[] }) { function RawOpponentsTable({ games }: { games: SelectGames[] }) {
@@ -157,7 +159,9 @@ function RawOpponentsTable({ games }: { games: SelectGames[] }) {
const tableData: Stats[] = useMemo( const tableData: Stats[] = useMemo(
() => () =>
Object.values(grouped).map((gamesAgainstOpponent) => { Object.values(grouped).map((gamesAgainstOpponent) => {
const totalGames = gamesAgainstOpponent.length const totalGames = gamesAgainstOpponent.filter(
(x) => x.result !== 'tie'
).length
let wins = 0 let wins = 0
let losses = 0 let losses = 0
let totalMMRChange = 0 let totalMMRChange = 0
@@ -174,7 +178,7 @@ function RawOpponentsTable({ games }: { games: SelectGames[] }) {
opponentName: gamesAgainstOpponent[0].opponentName, opponentName: gamesAgainstOpponent[0].opponentName,
opponentId: gamesAgainstOpponent[0].opponentId, opponentId: gamesAgainstOpponent[0].opponentId,
totalMMRChange, totalMMRChange,
winRate: (wins / totalGames) * 100, winRate: totalGames ? (wins / totalGames) * 100 : null,
} }
return stats return stats
}), }),