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

22 lines
631 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';
import { tankopedia } from '../blitzstars/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 = {};
order.map((id) => {
const entry = awaitedTankopedia[id];
if (!entry) return;
if (!tierWeights[entry.tier]) tierWeights[entry.tier] = 0;
tierWeights[entry.tier]! += stats[id].battles;
});
return tierWeights;
}