feat: core chunk 5

This commit is contained in:
TrèsAbhi committed 2023-10-14 11:25:42 -05:00
1 parent 9bdb14e13a
commit ed8bab7df8
37 files changed
+91 -165

No files matched your search

+4 -4
View File
@@ -1,9 +1,9 @@
import { TreeTypeString } from '../../components/Tanks';
import sumStats from '../../LEGACY_core/blitz/sumStats';
import { tankopedia } from '../../LEGACY_core/blitz/tankopedia';
import { DiffedTankStats } from '../../LEGACY_core/blitzstars/getDiffedTankStats';
import { tankAverages } from '../../LEGACY_core/blitzstars/tankAverages';
import { DiffedTankStats } from '../blitzstars/getStatsInPeriod';
import { tankAverages } from '../blitzstars/tankAverages';
import { tankopedia } from '../blitzstars/tankopedia';
import calculateWN8 from './calculateWN8';
import sumStats from './sumStats';
export interface StatFilters {
nation?: string;
+22
View File
@@ -0,0 +1,22 @@
import { TierWeightsRecord } from '../../components/TierWeights';
import { AllStats } from '../blitz/getAccountInfo';
import { tankopedia } from '../blitzstars/tankopedia';
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;
}
+33
View File
@@ -0,0 +1,33 @@
import { AllStats } from '../blitz/getAccountInfo';
import { emptyAllStats } from '../blitzstars/getStatsInPeriod';
export default function sumStats(allStatsCollection: AllStats[]) {
return allStatsCollection.reduce((accumulated, current) => {
function sum(value: (allStats: AllStats) => number) {
return value(accumulated) + value(current);
}
function max(value: (allStats: AllStats) => number) {
return Math.max(value(accumulated), value(current));
}
return {
battles: sum((a) => a.battles),
wins: sum((a) => a.wins),
capture_points: sum((a) => a.capture_points),
damage_dealt: sum((a) => a.damage_dealt),
damage_received: sum((a) => a.damage_received),
dropped_capture_points: sum((a) => a.dropped_capture_points),
frags: sum((a) => a.frags),
frags8p: sum((a) => a.frags8p),
hits: sum((a) => a.hits),
losses: sum((a) => a.losses),
max_frags: max((a) => a.max_frags),
max_xp: max((a) => a.max_xp),
shots: sum((a) => a.shots),
spotted: sum((a) => a.spotted),
survived_battles: sum((a) => a.survived_battles),
win_and_survived: sum((a) => a.win_and_survived),
xp: sum((a) => a.xp),
} satisfies AllStats;
}, emptyAllStats);
}