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 {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -25,7 +25,7 @@ export const SKILLED_CLANS: Record<SkilledClan, string> = {
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: false,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -10,7 +10,7 @@ import { client } from '../index.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -18,7 +18,7 @@ const DEFAULT_THRESHOLD = 7;
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -43,7 +43,7 @@ const COMP_TANKS = [
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -3,7 +3,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
handlesInteraction: true,
+1 -1
View File
@@ -16,7 +16,7 @@ type SortBy = 'name' | 'count';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -12,7 +12,7 @@ import { AccountInfo } from '../types/accountInfo.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -11,7 +11,7 @@ import { ClanList } from '../types/clanList.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -12,7 +12,7 @@ import { AccountList } from '../types/accountList.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -8,7 +8,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -1
View File
@@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+7 -6
View File
@@ -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',
+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') {
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<Type extends StatType>(
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<TierWeightsRecord>(
(accumulator, [tankIdString, stats]) => {