Files
blitzkit/src/core/statistics/getTierWeights.ts
T

22 lines
635 B
TypeScript
Raw Normal View History

2023-10-11 18:57:51 -05:00
import { TierWeightsRecord } from '../../components/TierWeights';
2023-10-14 11:25:42 -05:00
import { AllStats } from '../blitz/getAccountInfo';
2023-11-29 12:17:21 -06:00
import { tankopedia } from '../blitzkrieg/tankopedia';
2023-10-11 18:57:51 -05:00
export async function getTierWeights(
stats: Record<number, AllStats>,
order: number[] = Object.keys(stats).map(parseInt),
) {
const awaitedTankopedia = await tankopedia;
const tierWeights: TierWeightsRecord = {};
2023-11-29 12:17:21 -06:00
order.forEach((id) => {
2023-10-11 18:57:51 -05:00
const entry = awaitedTankopedia[id];
if (!entry) return;
if (!tierWeights[entry.tier]) tierWeights[entry.tier] = 0;
tierWeights[entry.tier]! += stats[id].battles;
});
return tierWeights;
}