fix: average tiers not showing up in /stats

This commit is contained in:
TresAbhi committed 2023-06-23 16:58:17 +00:00
1 parent f134efa1e8
commit 8b9f665d47
15 files changed
+44 -28

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ const executionStart = new Date().getTime();
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -25,7 +25,7 @@ export const SKILLED_CLANS: Record<SkilledClan, string> = {
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: false, inPublic: false,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -10,7 +10,7 @@ import { client } from '../index.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -18,7 +18,7 @@ const DEFAULT_THRESHOLD = 7;
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -43,7 +43,7 @@ const COMP_TANKS = [
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -3,7 +3,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
handlesInteraction: true, handlesInteraction: true,
+1 -1
View File
@@ -16,7 +16,7 @@ type SortBy = 'name' | 'count';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -12,7 +12,7 @@ import { AccountInfo } from '../types/accountInfo.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -11,7 +11,7 @@ import { ClanList } from '../types/clanList.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -12,7 +12,7 @@ import { AccountList } from '../types/accountList.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -8,7 +8,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+1 -1
View File
@@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
+7 -6
View File
@@ -1,4 +1,5 @@
import getWN8Percentile from '../core/blitz/getWN8Percentile.js'; import getWN8Percentile from '../core/blitz/getWN8Percentile.js';
import isNumber from '../core/process/isNumber.js';
import { AllStats, SupplementaryStats } from '../types/accountInfo.js'; import { AllStats, SupplementaryStats } from '../types/accountInfo.js';
import GenericStats from './GenericStats/index.js'; import GenericStats from './GenericStats/index.js';
@@ -22,13 +23,13 @@ export default function GenericAllStats({
[ [
'WN8', 'WN8',
supplementaryStats supplementaryStats
? supplementaryStats.WN8 === undefined ? isNumber(supplementaryStats.WN8)
? '--' ? supplementaryStats.WN8!.toFixed(0)
: supplementaryStats.WN8.toFixed(0) : '--'
: undefined,
isNumber(supplementaryStats?.WN8)
? getWN8Percentile(supplementaryStats!.WN8!)
: undefined, : undefined,
supplementaryStats?.WN8 === undefined
? undefined
: getWN8Percentile(supplementaryStats.WN8),
], ],
[ [
'Survival', 'Survival',
+3
View File
@@ -0,0 +1,3 @@
export default function isNumber(value: any) {
return typeof value === 'number' && !isNaN(value) && isFinite(value);
}
+22 -10
View File
@@ -57,12 +57,24 @@ export default async function stats<Type extends StatType>(
if (type === 'player') { if (type === 'player') {
const entries = Object.entries(tankStats); const entries = Object.entries(tankStats);
stats = sumStats(entries.map(([, stats]) => stats)); stats = sumStats(entries.map(([, stats]) => stats));
const battles = entries.reduce((accumulator, [tankIdString, stats]) => { const battlesOfTanksWithAverages = entries.reduce(
const tankId = parseInt(tankIdString); (accumulator, [tankIdString, stats]) => {
const tankAverage = tankAverages[tankId]; const tankId = parseInt(tankIdString);
const tankAverage = tankAverages[tankId];
return tankAverage ? accumulator + stats.battles : accumulator; return tankAverage ? accumulator + stats.battles : accumulator;
}, 0); },
0,
);
const battlesOfTanksWithTankopediaEntry = entries.reduce(
(accumulator, [tankIdString, stats]) => {
const tankId = parseInt(tankIdString);
const tankopediaEntry = tankopedia[tankId];
return tankopediaEntry ? accumulator + stats.battles : accumulator;
},
0,
);
supplementaryStats = { supplementaryStats = {
WN8: WN8:
@@ -73,16 +85,16 @@ export default async function stats<Type extends StatType>(
return tankAverage return tankAverage
? accumulator + getWN8(tankAverage.all, stats) * stats.battles ? accumulator + getWN8(tankAverage.all, stats) * stats.battles
: accumulator; : accumulator;
}, 0) / battles, }, 0) / battlesOfTanksWithAverages,
tier: tier:
entries.reduce((accumulator, [tankIdString, stats]) => { entries.reduce((accumulator, [tankIdString, stats]) => {
const tankId = parseInt(tankIdString); const tankId = parseInt(tankIdString);
const tankAverage = tankAverages[tankId]; const tankopediaEntry = tankopedia[tankId];
return tankAverage return tankopediaEntry
? accumulator + tankopedia[tankId].tier * stats.battles ? accumulator + tankopediaEntry.tier * stats.battles
: accumulator; : accumulator;
}, 0) / battles, }, 0) / battlesOfTanksWithTankopediaEntry,
}; };
tierWeights = entries.reduce<TierWeightsRecord>( tierWeights = entries.reduce<TierWeightsRecord>(
(accumulator, [tankIdString, stats]) => { (accumulator, [tankIdString, stats]) => {