mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
Merge pull request #4 from tresabhi:1.5.4
fix: career WN8s now accounts for all tanks
This commit is contained in:
2 files changed
+51
-16
No files matched your search
+36
-6
@@ -11,6 +11,7 @@ import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import sumStats from '../core/blitz/sumStats.js';
|
||||
@@ -59,11 +60,38 @@ export default {
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const tankStats = await getTankStats(interaction, server, id);
|
||||
let stats: AllStats;
|
||||
let supplementaryStats: SupplementaryStats | undefined;
|
||||
let hasWN8AccumulatedAtAll = false;
|
||||
|
||||
if (period === 'career') {
|
||||
stats = accountInfo[id].statistics.all;
|
||||
const totalBattles = tankStats.reduce(
|
||||
(accumulator, { all }) => accumulator + all.battles,
|
||||
0,
|
||||
);
|
||||
|
||||
supplementaryStats = {
|
||||
tier:
|
||||
tankStats.reduce(
|
||||
(accumulator, { tank_id, all }) =>
|
||||
accumulator + tankopedia[tank_id].tier * all.battles,
|
||||
0,
|
||||
) / totalBattles,
|
||||
WN8:
|
||||
tankStats.reduce((accumulator, { tank_id, all }) => {
|
||||
if (tankAverages[tank_id]) {
|
||||
const tankWN8 = getWN8(tankAverages[tank_id].all, all);
|
||||
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
|
||||
hasWN8AccumulatedAtAll = true;
|
||||
|
||||
return accumulator + tankWN8 * all.battles;
|
||||
} else return accumulator;
|
||||
}, 0) / totalBattles,
|
||||
};
|
||||
} else {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
@@ -78,34 +106,36 @@ export default {
|
||||
0,
|
||||
);
|
||||
|
||||
let hasWN8AccumulatedAtAll = false;
|
||||
|
||||
supplementaryStats = {
|
||||
tier:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankTier = tankopedia[tankId].tier;
|
||||
|
||||
return accumulator + tankTier * stats.battles;
|
||||
}, 0) / totalBattles,
|
||||
WN8:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const tankId = parseInt(tankIdString);
|
||||
|
||||
// edge case where new tanks don't have averages
|
||||
if (tankAverages[tankId]) {
|
||||
const tankWN8 = getWN8(tankAverages[tankId].all, stats);
|
||||
|
||||
if (isNaN(tankWN8)) return accumulator;
|
||||
|
||||
hasWN8AccumulatedAtAll = true;
|
||||
|
||||
return accumulator + tankWN8 * stats.battles;
|
||||
} else return accumulator;
|
||||
}, 0) / totalBattles,
|
||||
};
|
||||
|
||||
if (!hasWN8AccumulatedAtAll) supplementaryStats.WN8 = undefined;
|
||||
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
}
|
||||
|
||||
if (!hasWN8AccumulatedAtAll) supplementaryStats.WN8 = undefined;
|
||||
|
||||
const image = await render(
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
|
||||
+15
-10
@@ -90,15 +90,16 @@ export default {
|
||||
},
|
||||
{},
|
||||
);
|
||||
const careerWN8s = tankStatsOverTimeEntries.reduce<Record<number, number>>(
|
||||
(accumulator, [tankIdString]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
|
||||
return tankId === 0 || tankAverages[tankId] === undefined
|
||||
const careerWN8s = careerTankStatsRaw.reduce<Record<number, number>>(
|
||||
(accumulator, { tank_id }) => {
|
||||
return tank_id === 0 || tankAverages[tank_id] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tankId]: getWN8(tankAverages[tankId].all, careerStats[tankId]),
|
||||
[tank_id]: getWN8(
|
||||
tankAverages[tank_id].all,
|
||||
careerStats[tank_id],
|
||||
),
|
||||
};
|
||||
},
|
||||
{},
|
||||
@@ -119,13 +120,17 @@ export default {
|
||||
);
|
||||
careerWN8s[0] =
|
||||
careerWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString, wn8]) =>
|
||||
accumulator + wn8 * careerStats[Number(tankIdString)].battles,
|
||||
(accumulator, [tankIdString, WN8]) =>
|
||||
isNaN(WN8)
|
||||
? accumulator
|
||||
: accumulator + WN8 * careerStats[Number(tankIdString)].battles,
|
||||
0,
|
||||
) /
|
||||
careerWN8sEntries.reduce(
|
||||
(accumulator, [tankIdString]) =>
|
||||
accumulator + careerStats[Number(tankIdString)].battles,
|
||||
(accumulator, [tankIdString, WN8]) =>
|
||||
isNaN(WN8)
|
||||
? accumulator
|
||||
: accumulator + careerStats[Number(tankIdString)].battles,
|
||||
0,
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user