Files
blitzkit/packages/bot/src/components/GenericAllStats/index.tsx
T

149 lines
4.7 KiB
TypeScript
Raw Normal View History

2024-09-08 10:17:40 -05:00
import {
BlitzStats,
getWN8Percentile,
isNumber,
SupplementaryStats,
} from '@blitzkit/core';
2024-03-06 17:41:05 -06:00
import { Locale } from 'discord.js';
import { translator } from '../../core/localization/translator';
2023-07-11 19:54:57 +00:00
import { Card } from './components/Card';
import { Root } from './components/Root';
import { Row } from './components/Row';
2023-07-11 19:43:22 +00:00
2024-03-12 23:36:56 -05:00
interface GenericAllStatsProps {
2024-08-10 13:29:10 -05:00
stats: BlitzStats;
2023-07-11 19:43:22 +00:00
supplementaryStats?: SupplementaryStats;
2024-03-06 17:41:05 -06:00
locale: Locale;
2023-07-11 19:43:22 +00:00
}
2024-09-08 10:11:24 -05:00
export function GenericAllStats({
2023-07-11 19:43:22 +00:00
stats,
supplementaryStats,
2024-03-06 17:41:05 -06:00
locale,
2023-07-11 19:43:22 +00:00
}: GenericAllStatsProps) {
2025-01-16 13:53:29 -06:00
const { strings } = translator(locale);
2023-07-11 19:43:22 +00:00
const damageRatio = stats.damage_dealt / stats.damage_received;
const killsToDeathRatio =
stats.frags / (stats.battles - stats.survived_battles);
return (
<Root>
<Row>
<Card
2025-01-16 13:53:29 -06:00
title={strings.bot.commands.full_stats.body.cards.games.$}
2023-07-11 19:43:22 +00:00
items={[
{
2025-01-16 13:53:29 -06:00
label: strings.bot.commands.full_stats.body.cards.games.winrate,
2023-07-11 19:43:22 +00:00
value: `${(100 * (stats.wins / stats.battles)).toFixed(2)}%`,
},
{
2025-01-16 13:53:29 -06:00
label: strings.bot.commands.full_stats.body.cards.games.battles,
2023-07-11 19:43:22 +00:00
value: stats.battles,
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.games.wins_losses,
2023-07-11 19:43:22 +00:00
value: `${stats.wins} / ${stats.losses}`,
},
]}
/>
<Card
2025-01-16 13:53:29 -06:00
title={strings.bot.commands.full_stats.body.cards.efficiency.$}
2023-07-11 19:43:22 +00:00
items={[
{
2025-01-16 13:53:29 -06:00
label: strings.bot.commands.full_stats.body.cards.efficiency.wn8,
2023-07-11 19:43:22 +00:00
value:
supplementaryStats && isNumber(supplementaryStats.WN8)
? supplementaryStats.WN8!.toFixed(0)
: undefined,
percentile: isNumber(supplementaryStats?.WN8)
? getWN8Percentile(supplementaryStats!.WN8!)
: undefined,
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.efficiency.survival,
2023-07-11 19:43:22 +00:00
value: `${(
100 *
(stats.survived_battles / stats.battles)
).toFixed(2)}%`,
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.efficiency.accuracy,
2023-07-11 19:43:22 +00:00
value: `${((stats.hits / stats.shots) * 100).toFixed(2)}%`,
},
]}
/>
</Row>
<Row>
<Card
2025-01-16 13:53:29 -06:00
title={strings.bot.commands.full_stats.body.cards.lethality.$}
2023-07-11 19:43:22 +00:00
items={[
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.lethality
.average_damage,
2023-07-11 19:43:22 +00:00
value: (stats.damage_dealt / stats.battles).toFixed(0),
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.lethality
.damage_per_tier,
2023-07-11 19:43:22 +00:00
value: supplementaryStats?.tier
? (
stats.damage_dealt /
stats.battles /
supplementaryStats.tier
).toFixed(0)
: undefined,
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.lethality
.damage_ratio,
2023-07-11 19:43:22 +00:00
value: isFinite(damageRatio) ? damageRatio.toFixed(2) : undefined,
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.lethality
.average_kills,
2023-07-11 19:43:22 +00:00
value: (stats.frags / stats.battles).toFixed(0),
},
]}
/>
<Card
2025-01-16 13:53:29 -06:00
title={strings.bot.commands.full_stats.body.cards.miscellaneous.$}
2023-07-11 19:43:22 +00:00
items={[
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.miscellaneous
.average_tier,
2023-07-11 19:43:22 +00:00
value: supplementaryStats?.tier?.toFixed(2),
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.miscellaneous
.average_spots,
2023-07-11 19:43:22 +00:00
value: (stats.spotted / stats.battles).toFixed(2),
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.miscellaneous
.average_xp,
2023-07-11 19:43:22 +00:00
value: (stats.xp / stats.battles).toFixed(0),
},
{
2025-01-16 13:53:29 -06:00
label:
strings.bot.commands.full_stats.body.cards.miscellaneous
.kills_to_death_ratio,
2023-07-11 19:43:22 +00:00
value: isFinite(killsToDeathRatio)
? killsToDeathRatio.toFixed(2)
: undefined,
},
]}
/>
</Row>
</Root>
);
}