From 8b9f665d47a2f086bf693f5f6fa4c5fd65b544f1 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Fri, 23 Jun 2023 16:58:17 +0000 Subject: [PATCH] fix: average tiers not showing up in /stats --- src/commands/debug.ts | 2 +- src/commands/eligible.ts | 2 +- src/commands/help.ts | 2 +- src/commands/inactive.tsx | 2 +- src/commands/ownedtanks.tsx | 2 +- src/commands/ping.ts | 2 +- src/commands/playerachievements.ts | 2 +- src/commands/playerinfo.ts | 2 +- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 2 +- src/commands/searchtanks.ts | 2 +- src/commands/verify.ts | 2 +- src/components/GenericAllStats.tsx | 13 ++++++------ src/core/process/isNumber.ts | 3 +++ src/renderers/stats.tsx | 32 ++++++++++++++++++++---------- 15 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 src/core/process/isNumber.ts diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 8a6651562..60c749d11 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -12,7 +12,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 9804867be..d95cbb283 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -25,7 +25,7 @@ export const SKILLED_CLANS: Record = { export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: false, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index 671298988..2bf925db4 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -10,7 +10,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index d1db738dc..e8ba2b3bf 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -18,7 +18,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index d73a14a70..e781d46d1 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -43,7 +43,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 13f58fe34..a890f2540 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -3,7 +3,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, handlesInteraction: true, diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index fb52b3a50..a7248fba6 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -16,7 +16,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index e34426edc..d212a2768 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -12,7 +12,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index 7d811ed16..09238ff4a 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -11,7 +11,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 35aa16395..10f20285e 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -12,7 +12,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index d19bf7762..1cb924244 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -8,7 +8,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/verify.ts b/src/commands/verify.ts index d05b64d89..22e9d33b9 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/components/GenericAllStats.tsx b/src/components/GenericAllStats.tsx index f23372027..5374a0801 100644 --- a/src/components/GenericAllStats.tsx +++ b/src/components/GenericAllStats.tsx @@ -1,4 +1,5 @@ import getWN8Percentile from '../core/blitz/getWN8Percentile.js'; +import isNumber from '../core/process/isNumber.js'; import { AllStats, SupplementaryStats } from '../types/accountInfo.js'; import GenericStats from './GenericStats/index.js'; @@ -22,13 +23,13 @@ export default function GenericAllStats({ [ 'WN8', supplementaryStats - ? supplementaryStats.WN8 === undefined - ? '--' - : supplementaryStats.WN8.toFixed(0) + ? isNumber(supplementaryStats.WN8) + ? supplementaryStats.WN8!.toFixed(0) + : '--' + : undefined, + isNumber(supplementaryStats?.WN8) + ? getWN8Percentile(supplementaryStats!.WN8!) : undefined, - supplementaryStats?.WN8 === undefined - ? undefined - : getWN8Percentile(supplementaryStats.WN8), ], [ 'Survival', diff --git a/src/core/process/isNumber.ts b/src/core/process/isNumber.ts new file mode 100644 index 000000000..930922ecb --- /dev/null +++ b/src/core/process/isNumber.ts @@ -0,0 +1,3 @@ +export default function isNumber(value: any) { + return typeof value === 'number' && !isNaN(value) && isFinite(value); +} diff --git a/src/renderers/stats.tsx b/src/renderers/stats.tsx index ee9493bee..cf7d3b9f9 100644 --- a/src/renderers/stats.tsx +++ b/src/renderers/stats.tsx @@ -57,12 +57,24 @@ export default async function stats( if (type === 'player') { const entries = Object.entries(tankStats); stats = sumStats(entries.map(([, stats]) => stats)); - const battles = entries.reduce((accumulator, [tankIdString, stats]) => { - const tankId = parseInt(tankIdString); - const tankAverage = tankAverages[tankId]; + const battlesOfTanksWithAverages = entries.reduce( + (accumulator, [tankIdString, stats]) => { + const tankId = parseInt(tankIdString); + const tankAverage = tankAverages[tankId]; - return tankAverage ? accumulator + stats.battles : accumulator; - }, 0); + return tankAverage ? accumulator + stats.battles : accumulator; + }, + 0, + ); + const battlesOfTanksWithTankopediaEntry = entries.reduce( + (accumulator, [tankIdString, stats]) => { + const tankId = parseInt(tankIdString); + const tankopediaEntry = tankopedia[tankId]; + + return tankopediaEntry ? accumulator + stats.battles : accumulator; + }, + 0, + ); supplementaryStats = { WN8: @@ -73,16 +85,16 @@ export default async function stats( return tankAverage ? accumulator + getWN8(tankAverage.all, stats) * stats.battles : accumulator; - }, 0) / battles, + }, 0) / battlesOfTanksWithAverages, tier: entries.reduce((accumulator, [tankIdString, stats]) => { const tankId = parseInt(tankIdString); - const tankAverage = tankAverages[tankId]; + const tankopediaEntry = tankopedia[tankId]; - return tankAverage - ? accumulator + tankopedia[tankId].tier * stats.battles + return tankopediaEntry + ? accumulator + tankopediaEntry.tier * stats.battles : accumulator; - }, 0) / battles, + }, 0) / battlesOfTanksWithTankopediaEntry, }; tierWeights = entries.reduce( (accumulator, [tankIdString, stats]) => {