2024-07-07 18:56:49 -05:00
|
|
|
import {
|
2024-10-07 17:31:13 -05:00
|
|
|
AverageDefinitionsEntry,
|
2024-09-07 21:45:00 -05:00
|
|
|
formatCompact,
|
2024-10-07 17:31:13 -05:00
|
|
|
type BlitzkitStats,
|
2024-09-07 21:45:00 -05:00
|
|
|
} from '@blitzkit/core';
|
|
|
|
|
import { Table } from '@radix-ui/themes';
|
2024-10-07 17:31:13 -05:00
|
|
|
import { memo, useCallback } from 'react';
|
2024-11-29 13:20:27 -06:00
|
|
|
import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions';
|
2024-10-07 17:31:13 -05:00
|
|
|
import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio';
|
2025-01-07 12:47:55 -06:00
|
|
|
import { useLocale } from '../../hooks/useLocale';
|
2025-09-01 18:16:41 -05:00
|
|
|
import { Performance } from '../../stores/performance';
|
2024-10-07 17:31:13 -05:00
|
|
|
import { StickyRowHeaderCell } from '../StickyRowHeaderCell';
|
|
|
|
|
|
|
|
|
|
interface AverageDefinitionsEntryWithId extends AverageDefinitionsEntry {
|
|
|
|
|
id: number;
|
|
|
|
|
}
|
2024-07-07 18:56:49 -05:00
|
|
|
|
|
|
|
|
interface TotalProps {
|
|
|
|
|
tanks: AverageDefinitionsEntryWithId[];
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 13:20:27 -06:00
|
|
|
const averageDefinitions = await awaitableAverageDefinitions;
|
2024-10-07 17:31:13 -05:00
|
|
|
|
2024-07-07 18:56:49 -05:00
|
|
|
export const Total = memo<TotalProps>(
|
|
|
|
|
({ tanks }) => {
|
2025-09-01 18:16:41 -05:00
|
|
|
const playerCountPeriod = Performance.use(
|
2024-07-12 13:53:11 -05:00
|
|
|
(state) => state.playerCountPeriod,
|
|
|
|
|
);
|
2025-01-07 12:47:55 -06:00
|
|
|
const { strings, locale } = useLocale();
|
2024-07-07 18:56:49 -05:00
|
|
|
const ratio = useAveragesExclusionRatio();
|
|
|
|
|
const sum = useCallback(
|
2024-08-10 13:29:10 -05:00
|
|
|
(slice: (tank: BlitzkitStats) => number) => {
|
2024-07-07 18:56:49 -05:00
|
|
|
return tanks.reduce(
|
2024-10-21 20:32:47 -05:00
|
|
|
(acc, tank) => acc + tank.samples[playerCountPeriod] * slice(tank.mu),
|
2024-07-07 18:56:49 -05:00
|
|
|
0,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
[tanks],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const battles = sum(({ battles }) => battles);
|
|
|
|
|
const winrate = sum(({ wins }) => wins) / battles;
|
|
|
|
|
const damage = sum(({ damage_dealt }) => damage_dealt) / battles;
|
|
|
|
|
const survival = sum(({ survived_battles }) => survived_battles) / battles;
|
|
|
|
|
const xp = sum(({ xp }) => xp) / battles;
|
|
|
|
|
const kills = sum(({ frags }) => frags) / battles;
|
|
|
|
|
const spots = sum(({ spotted }) => spotted) / battles;
|
|
|
|
|
const hits = sum(({ hits }) => hits) / battles;
|
|
|
|
|
const shots = sum(({ shots }) => shots) / battles;
|
|
|
|
|
const accuracy = hits / shots;
|
|
|
|
|
const damageReceived =
|
|
|
|
|
sum(({ damage_received }) => damage_received) / battles;
|
|
|
|
|
const damageRatio = damage / damageReceived;
|
|
|
|
|
const capturePoints = sum(({ capture_points }) => capture_points) / battles;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Table.Row>
|
2024-07-12 13:53:11 -05:00
|
|
|
<StickyRowHeaderCell style={{ overflow: 'hidden', display: 'flex' }}>
|
2025-01-07 12:47:55 -06:00
|
|
|
{strings.website.tools.performance.table.tanks.total}
|
2024-07-12 13:01:10 -05:00
|
|
|
</StickyRowHeaderCell>
|
2024-07-07 18:56:49 -05:00
|
|
|
<Table.Cell align="center">{(winrate * 100).toFixed(1)}%</Table.Cell>
|
2024-07-12 13:53:11 -05:00
|
|
|
<Table.Cell align="center">
|
2025-01-07 12:47:55 -06:00
|
|
|
{formatCompact(
|
|
|
|
|
locale,
|
|
|
|
|
ratio * averageDefinitions.samples[playerCountPeriod],
|
|
|
|
|
)}
|
2024-07-12 13:53:11 -05:00
|
|
|
</Table.Cell>
|
2024-07-07 18:56:49 -05:00
|
|
|
<Table.Cell align="center">
|
2025-01-07 12:47:55 -06:00
|
|
|
{Math.round(damage).toLocaleString(locale)}
|
2024-07-07 18:56:49 -05:00
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">
|
|
|
|
|
{Math.round(survival * 100).toFixed(1)}%
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">
|
2025-01-07 12:47:55 -06:00
|
|
|
{Math.round(xp).toLocaleString(locale)}
|
2024-07-07 18:56:49 -05:00
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{kills.toFixed(2)}</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{spots.toFixed(2)}</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{(accuracy * 100).toFixed(0)}%</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{shots.toFixed(1)}</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{hits.toFixed(1)}</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{damageRatio.toFixed(2)}</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">
|
2025-01-07 12:47:55 -06:00
|
|
|
{Math.round(damageReceived).toLocaleString(locale)}
|
2024-07-07 18:56:49 -05:00
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell align="center">{capturePoints.toFixed(2)}</Table.Cell>
|
|
|
|
|
</Table.Row>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
(prev, next) => prev.tanks === next.tanks,
|
|
|
|
|
);
|