feat: stat generalzation

This commit is contained in:
TrèsAbhi committed 2024-05-01 17:55:13 -05:00
1 parent aafba7b6c8
commit 8bc3e2c6b9
4 files changed
+59 -9

No files matched your search

+2
View File
@@ -11,6 +11,7 @@
"applypatches", "applypatches",
"artefacts", "artefacts",
"atgm", "atgm",
"Avearges",
"AYUV", "AYUV",
"battleresults", "battleresults",
"bbox", "bbox",
@@ -82,6 +83,7 @@
"loadouts", "loadouts",
"loddist", "loddist",
"lods", "lods",
"lossrate",
"mantlets", "mantlets",
"metallicness", "metallicness",
"minitelrose", "minitelrose",
+23 -8
View File
@@ -21,6 +21,11 @@ import { use, useEffect, useMemo, useRef, useState } from 'react';
import PageWrapper from '../../../components/PageWrapper'; import PageWrapper from '../../../components/PageWrapper';
import { UNLOCALIZED_REGION_NAMES_SHORT } from '../../../constants/regions'; import { UNLOCALIZED_REGION_NAMES_SHORT } from '../../../constants/regions';
import { authURL } from '../../../core/blitz/authURL'; import { authURL } from '../../../core/blitz/authURL';
import {
generateStats,
prettifyStats,
STAT_NAMES,
} from '../../../core/blitz/generateStats';
import { import {
getAccountInfo, getAccountInfo,
IndividualAccountInfo, IndividualAccountInfo,
@@ -32,6 +37,7 @@ import searchPlayersAcrossRegions, {
} from '../../../core/blitz/searchPlayersAcrossRegions'; } from '../../../core/blitz/searchPlayersAcrossRegions';
import { tankDefinitions } from '../../../core/blitzkit/tankDefinitions'; import { tankDefinitions } from '../../../core/blitzkit/tankDefinitions';
import { tankIcon } from '../../../core/blitzkit/tankIcon'; import { tankIcon } from '../../../core/blitzkit/tankIcon';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import { theme } from '../../../stitches.config'; import { theme } from '../../../stitches.config';
import { useApp } from '../../../stores/app'; import { useApp } from '../../../stores/app';
import mutateSession, { import mutateSession, {
@@ -42,6 +48,7 @@ import { IndividualTankStats } from '../../../types/tanksStats';
export default function Page() { export default function Page() {
const awaitedTankDefinitions = use(tankDefinitions); const awaitedTankDefinitions = use(tankDefinitions);
const awaitedTankAvearges = use(tankAverages);
const [showSearch, setShowSearch] = useState(false); const [showSearch, setShowSearch] = useState(false);
const [searching, setSearching] = useState(false); const [searching, setSearching] = useState(false);
const [searchResults, setSearchResults] = useState<AccountListWithServer>([]); const [searchResults, setSearchResults] = useState<AccountListWithServer>([]);
@@ -306,8 +313,11 @@ export default function Page() {
<Table.Header> <Table.Header>
<Table.Row> <Table.Row>
<Table.ColumnHeaderCell>Tank</Table.ColumnHeaderCell> <Table.ColumnHeaderCell>Tank</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell width="0">Battles</Table.ColumnHeaderCell> {session.columns.map((column) => (
<Table.ColumnHeaderCell width="0">Winrate</Table.ColumnHeaderCell> <Table.ColumnHeaderCell width="0" key={column} align="right">
{STAT_NAMES[column]}
</Table.ColumnHeaderCell>
))}
</Table.Row> </Table.Row>
</Table.Header> </Table.Header>
@@ -315,8 +325,12 @@ export default function Page() {
{tankStatsB {tankStatsB
.filter((stat) => stat.all.battles > 0) .filter((stat) => stat.all.battles > 0)
.sort((a, b) => b.last_battle_time - a.last_battle_time) .sort((a, b) => b.last_battle_time - a.last_battle_time)
.map((stat) => { .map((entry) => {
const tank = awaitedTankDefinitions[stat.tank_id]; const tank = awaitedTankDefinitions[entry.tank_id];
const average = awaitedTankAvearges[tank.id];
const stats = prettifyStats(
generateStats(entry.all, average?.all),
);
return ( return (
<Table.Row <Table.Row
@@ -373,10 +387,11 @@ export default function Page() {
</Text> </Text>
</Link> </Link>
</Table.RowHeaderCell> </Table.RowHeaderCell>
<Table.Cell align="right">{stat.all.battles}</Table.Cell> {session.columns.map((column) => (
<Table.Cell align="right"> <Table.Cell key={column} align="right">
{((100 * stat.all.wins) / stat.all.battles).toFixed(0)}% {stats[column]}
</Table.Cell> </Table.Cell>
))}
</Table.Row> </Table.Row>
); );
})} })}
+29
View File
@@ -0,0 +1,29 @@
import calculateWN8 from '../statistics/calculateWN8';
import { AllStats } from './getAccountInfo';
export type Stat = keyof ReturnType<typeof generateStats>;
export const STAT_NAMES: Record<Stat, string> = {
battles: 'Battles',
winrate: 'Winrate',
wn8: 'WN8',
damage: 'Damage',
};
export function generateStats(s: AllStats, e?: AllStats) {
return {
battles: s.battles,
winrate: s.wins / s.battles,
wn8: e ? calculateWN8(e, s) : null,
damage: s.damage_dealt / s.battles,
};
}
export function prettifyStats(s: ReturnType<typeof generateStats>) {
return {
battles: `${s.battles}`,
winrate: `${(s.winrate * 100).toFixed(0)}%`,
wn8: s.wn8 ? s.wn8.toFixed(0) : '--',
damage: s.damage.toFixed(0),
} satisfies Record<Stat, string>;
}
+5 -1
View File
@@ -3,8 +3,11 @@ import { merge } from 'lodash';
import { create } from 'zustand'; import { create } from 'zustand';
import { persist } from 'zustand/middleware'; import { persist } from 'zustand/middleware';
import { Region } from '../constants/regions'; import { Region } from '../constants/regions';
import { Stat } from '../core/blitz/generateStats';
interface SessionBase {} interface SessionBase {
columns: Stat[];
}
export interface SessionTracking extends SessionBase { export interface SessionTracking extends SessionBase {
tracking: true; tracking: true;
@@ -24,6 +27,7 @@ type Session = SessionTracking | SessionNotTracking;
export const useSession = create<Session>()( export const useSession = create<Session>()(
persist( persist(
(set) => ({ (set) => ({
columns: ['battles', 'winrate', 'wn8', 'damage'],
tracking: false, tracking: false,
}), }),
{ name: 'session-2', merge: (a, b) => merge(b, a) }, { name: 'session-2', merge: (a, b) => merge(b, a) },