feat: updated /tankstats

This commit is contained in:
TresAbhi committed 2023-05-30 17:24:24 +00:00
1 parent 50369e9225
commit 831300cf69
13 files changed
+300 -272

No files matched your search

+10 -33
View File
@@ -15,8 +15,14 @@ import usernameAutocomplete from '../core/autocomplete/username.js';
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import sumStats from '../core/blitz/sumStats.js';
import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
import getPeriodicStart from '../core/blitzstars/getPeriodStart.js';
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
import cmdName from '../core/interaction/cmdName.js';
import addStatPeriodChoices, {
StatPeriod,
statPeriodNames,
} from '../core/options/addStatPeriodChoices.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import render from '../core/ui/render.js';
@@ -24,36 +30,15 @@ import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo, AllStats } from '../types/accountInfo.js';
import { PlayerClanData } from '../types/playerClanData.js';
export type StatPeriod = 'today' | '30' | '60' | '90' | 'career';
export const statPeriodNames: Record<StatPeriod, string> = {
today: "Today's statistics",
30: '30-day statistics',
60: '60-day statistics',
90: '90-day statistics',
career: 'Career statistics',
};
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
.setName(cmdName('stats'))
.setDescription("Gets the user's in-game statistics")
.addStringOption((option) =>
option
.setName('period')
.setDescription('The last number of days of stats')
.setChoices(
{ name: 'Today', value: 'today' satisfies StatPeriod },
{ name: '30 Days', value: '30' satisfies StatPeriod },
{ name: '60 Days', value: '60' satisfies StatPeriod },
{ name: '90 Days', value: '90' satisfies StatPeriod },
{ name: 'Career', value: 'career' satisfies StatPeriod },
)
.setRequired(true),
)
.addStringOption(addStatPeriodChoices)
.addStringOption(addUsernameOption),
async execute(interaction) {
@@ -72,19 +57,13 @@ export default {
if (period === 'career') {
stats = accountInfo[id].statistics.all;
} else {
const daysAgo = period === 'today' ? 0 : Number(period) - 1;
const periodStart = new Date();
periodStart.setDate(periodStart.getDate() - daysAgo);
periodStart.setHours(5, 0, 0, 0);
stats = sumStats(
Object.entries(
await getTankStatsOverTime(
server,
id,
periodStart.getTime() / 1000,
new Date().getTime() / 1000,
getPeriodicStart(period),
getPeriodNow(),
),
).map(([, stats]) => stats),
);
@@ -115,7 +94,6 @@ export default {
'Winrate',
`${(100 * (stats.wins / stats.battles)).toFixed(2)}%`,
],
// ['WN8', stats.wn8.toFixed(0)],
[
'Survival',
`${(100 * (stats.survived_battles / stats.battles)).toFixed(
@@ -135,7 +113,6 @@ export default {
['Average hits', (stats.hits / stats.battles).toFixed(2)],
['Average kills', (stats.frags / stats.battles).toFixed(2)],
['Average spots', (stats.spotted / stats.battles).toFixed(2)],
// ['Average tier', stats.avg_tier.toFixed(2)],
[
'Damage ratio',
(stats.damage_dealt / stats.damage_received).toFixed(2),