mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: moved tankopedia and tankaverages into a runtime cache
This commit is contained in:
1 parent
95b105cb65
commit
00b721f34f
29 files changed
+268
-235
No files matched your search
@@ -38,8 +38,8 @@ export default async function evolution<Type extends StatType>(
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
} else {
|
||||
nameDiscriminator = `(${resolveTankName(tankId!)})`;
|
||||
image = tankopedia[tankId!].images.normal;
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
}
|
||||
|
||||
let histories: Histories;
|
||||
|
||||
+48
-40
@@ -22,6 +22,7 @@ import {
|
||||
SupplementaryStats,
|
||||
} from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise.js';
|
||||
|
||||
export type StatType = 'player' | 'tank';
|
||||
|
||||
@@ -47,8 +48,8 @@ export default async function stats<Type extends StatType>(
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${resolveTankName(tankId!)})`;
|
||||
image = tankopedia[tankId!].images.normal;
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
}
|
||||
|
||||
const tankStats = await getTankStatsDiffed(server, id, start, end);
|
||||
@@ -59,54 +60,61 @@ export default async function stats<Type extends StatType>(
|
||||
if (type === 'player') {
|
||||
const entries = Object.entries(tankStats);
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
const battlesOfTanksWithAverages = entries.reduce(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = tankAverages[tankId];
|
||||
const battlesOfTanksWithAverages = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage ? accumulator + stats.battles : accumulator;
|
||||
},
|
||||
0,
|
||||
);
|
||||
const battlesOfTanksWithTankopediaEntry = entries.reduce(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = tankopedia[tankId];
|
||||
return tankAverage ? (await accumulator) + stats.battles : accumulator;
|
||||
}, 0);
|
||||
const battlesOfTanksWithTankopediaEntry = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry ? accumulator + stats.battles : accumulator;
|
||||
},
|
||||
0,
|
||||
);
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + stats.battles
|
||||
: accumulator;
|
||||
}, 0);
|
||||
|
||||
supplementaryStats = {
|
||||
WN8:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = tankAverages[tankId];
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage
|
||||
? accumulator + calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
}, 0) / battlesOfTanksWithAverages,
|
||||
return tankAverage
|
||||
? (await accumulator) +
|
||||
calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
0,
|
||||
)) / battlesOfTanksWithAverages,
|
||||
tier:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = tankopedia[tankId];
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? accumulator + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
}, 0) / battlesOfTanksWithTankopediaEntry,
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
0,
|
||||
)) / battlesOfTanksWithTankopediaEntry,
|
||||
};
|
||||
tierWeights = entries.reduce<TierWeightsRecord>(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tier = tankopedia[tankId].tier as Tier;
|
||||
const tier = (await tankopedia)[tankId].tier as Tier;
|
||||
|
||||
if (accumulator[tier]) {
|
||||
accumulator[tier]! += stats.battles;
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
} else {
|
||||
accumulator[tier] = stats.battles;
|
||||
(await accumulator)[tier] = stats.battles;
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
@@ -118,9 +126,9 @@ export default async function stats<Type extends StatType>(
|
||||
|
||||
supplementaryStats = {
|
||||
WN8: stats
|
||||
? calculateWN8(tankAverages[tankId!].all, tankStats[tankId!])
|
||||
? calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!])
|
||||
: undefined,
|
||||
tier: tankopedia[tankId!].tier,
|
||||
tier: (await tankopedia)[tankId!].tier,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+48
-40
@@ -21,6 +21,7 @@ import {
|
||||
SupplementaryStats,
|
||||
} from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise.js';
|
||||
|
||||
export type StatType = 'player' | 'tank';
|
||||
|
||||
@@ -45,8 +46,8 @@ export default async function statsfull<Type extends StatType>(
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${resolveTankName(tankId!)})`;
|
||||
image = tankopedia[tankId!].images.normal;
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
}
|
||||
|
||||
const tankStats = await getTankStatsDiffed(server, id, start, end);
|
||||
@@ -57,54 +58,61 @@ export default async function statsfull<Type extends StatType>(
|
||||
if (type === 'player') {
|
||||
const entries = Object.entries(tankStats);
|
||||
stats = sumStats(entries.map(([, stats]) => stats));
|
||||
const battlesOfTanksWithAverages = entries.reduce(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = tankAverages[tankId];
|
||||
const battlesOfTanksWithAverages = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage ? accumulator + stats.battles : accumulator;
|
||||
},
|
||||
0,
|
||||
);
|
||||
const battlesOfTanksWithTankopediaEntry = entries.reduce(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = tankopedia[tankId];
|
||||
return tankAverage ? (await accumulator) + stats.battles : accumulator;
|
||||
}, 0);
|
||||
const battlesOfTanksWithTankopediaEntry = await entries.reduce<
|
||||
PossiblyPromise<number>
|
||||
>(async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry ? accumulator + stats.battles : accumulator;
|
||||
},
|
||||
0,
|
||||
);
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + stats.battles
|
||||
: accumulator;
|
||||
}, 0);
|
||||
|
||||
supplementaryStats = {
|
||||
WN8:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = tankAverages[tankId];
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankAverage = (await tankAverages)[tankId];
|
||||
|
||||
return tankAverage
|
||||
? accumulator + calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
}, 0) / battlesOfTanksWithAverages,
|
||||
return tankAverage
|
||||
? (await accumulator) +
|
||||
calculateWN8(tankAverage.all, stats) * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
0,
|
||||
)) / battlesOfTanksWithAverages,
|
||||
tier:
|
||||
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = tankopedia[tankId];
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
return tankopediaEntry
|
||||
? accumulator + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
}, 0) / battlesOfTanksWithTankopediaEntry,
|
||||
return tankopediaEntry
|
||||
? (await accumulator) + tankopediaEntry.tier * stats.battles
|
||||
: accumulator;
|
||||
},
|
||||
0,
|
||||
)) / battlesOfTanksWithTankopediaEntry,
|
||||
};
|
||||
tierWeights = entries.reduce<TierWeightsRecord>(
|
||||
(accumulator, [tankIdString, stats]) => {
|
||||
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tier = tankopedia[tankId].tier as Tier;
|
||||
const tier = (await tankopedia)[tankId].tier as Tier;
|
||||
|
||||
if (accumulator[tier]) {
|
||||
accumulator[tier]! += stats.battles;
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
} else {
|
||||
accumulator[tier] = stats.battles;
|
||||
(await accumulator)[tier] = stats.battles;
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
@@ -115,8 +123,8 @@ export default async function statsfull<Type extends StatType>(
|
||||
stats = tankStats[tankId!];
|
||||
|
||||
supplementaryStats = {
|
||||
WN8: calculateWN8(tankAverages[tankId!].all, tankStats[tankId!]),
|
||||
tier: tankopedia[tankId!].tier,
|
||||
WN8: calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!]),
|
||||
tier: (await tankopedia)[tankId!].tier,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+55
-51
@@ -18,6 +18,7 @@ import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise.js';
|
||||
|
||||
export default async function today({ server, id }: ResolvedPlayer) {
|
||||
const tankStatsOverTime = await getTankStatsDiffed(
|
||||
@@ -52,33 +53,31 @@ export default async function today({ server, id }: ResolvedPlayer) {
|
||||
}
|
||||
|
||||
const tankStatsOverTimeEntries = Object.entries(tankStatsOverTime);
|
||||
const todayWN8s = tankStatsOverTimeEntries.reduce<Record<number, number>>(
|
||||
(accumulator, [tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const todayWN8s = await tankStatsOverTimeEntries.reduce<
|
||||
PossiblyPromise<Record<number, number>>
|
||||
>(async (accumulator, [tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
|
||||
return tankId === 0 || tankAverages[tankId] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tankId]: calculateWN8(tankAverages[tankId].all, tankStats),
|
||||
};
|
||||
},
|
||||
{},
|
||||
);
|
||||
const careerWN8s = careerTankStatsRaw.reduce<Record<number, number>>(
|
||||
(accumulator, { tank_id }) => {
|
||||
return tank_id === 0 || tankAverages[tank_id] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tank_id]: calculateWN8(
|
||||
tankAverages[tank_id].all,
|
||||
careerStats[tank_id],
|
||||
),
|
||||
};
|
||||
},
|
||||
{},
|
||||
);
|
||||
return tankId === 0 || (await tankAverages)[tankId] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tankId]: calculateWN8((await tankAverages)[tankId].all, tankStats),
|
||||
};
|
||||
}, {});
|
||||
const careerWN8s = await careerTankStatsRaw.reduce<
|
||||
PossiblyPromise<Record<number, number>>
|
||||
>(async (accumulator, { tank_id }) => {
|
||||
return tank_id === 0 || (await tankAverages)[tank_id] === undefined
|
||||
? accumulator
|
||||
: {
|
||||
...accumulator,
|
||||
[tank_id]: calculateWN8(
|
||||
(await tankAverages)[tank_id].all,
|
||||
careerStats[tank_id],
|
||||
),
|
||||
};
|
||||
}, {});
|
||||
const todayWN8sEntries = Object.entries(todayWN8s);
|
||||
const careerWN8sEntries = Object.entries(careerWN8s);
|
||||
|
||||
@@ -109,32 +108,37 @@ export default async function today({ server, id }: ResolvedPlayer) {
|
||||
0,
|
||||
);
|
||||
|
||||
const rows = tankStatsOverTimeEntries.map(([tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const career = careerStats[tankId];
|
||||
const rows = await Promise.all(
|
||||
tankStatsOverTimeEntries.map(async ([tankIdString, tankStats]) => {
|
||||
const tankId = Number(tankIdString);
|
||||
const career = careerStats[tankId];
|
||||
|
||||
return (
|
||||
<Breakdown.Row
|
||||
key={tankId}
|
||||
name={tankId === 0 ? 'Total' : resolveTankName(Number(tankIdString))}
|
||||
winrate={tankStats.wins / tankStats.battles}
|
||||
careerWinrate={career.wins / career.battles}
|
||||
WN8={isNaN(todayWN8s[tankId]) ? undefined : todayWN8s[tankId]}
|
||||
careerWN8={isNaN(careerWN8s[tankId]) ? undefined : careerWN8s[tankId]}
|
||||
damage={tankStats.damage_dealt / tankStats.battles}
|
||||
careerDamage={career.damage_dealt / career.battles}
|
||||
survival={tankStats.survived_battles / tankStats.battles}
|
||||
careerSurvival={career.survived_battles / career.battles}
|
||||
battles={tankStats.battles}
|
||||
careerBattles={career.battles}
|
||||
icon={
|
||||
tankId === 0
|
||||
? undefined
|
||||
: tankopedia[tankIdString as unknown as number].images.normal
|
||||
}
|
||||
/>
|
||||
);
|
||||
});
|
||||
return (
|
||||
<Breakdown.Row
|
||||
key={tankId}
|
||||
name={
|
||||
tankId === 0 ? 'Total' : await resolveTankName(Number(tankIdString))
|
||||
}
|
||||
winrate={tankStats.wins / tankStats.battles}
|
||||
careerWinrate={career.wins / career.battles}
|
||||
WN8={isNaN(todayWN8s[tankId]) ? undefined : todayWN8s[tankId]}
|
||||
careerWN8={isNaN(careerWN8s[tankId]) ? undefined : careerWN8s[tankId]}
|
||||
damage={tankStats.damage_dealt / tankStats.battles}
|
||||
careerDamage={career.damage_dealt / career.battles}
|
||||
survival={tankStats.survived_battles / tankStats.battles}
|
||||
careerSurvival={career.survived_battles / career.battles}
|
||||
battles={tankStats.battles}
|
||||
careerBattles={career.battles}
|
||||
icon={
|
||||
tankId === 0
|
||||
? undefined
|
||||
: (await tankopedia)[tankIdString as unknown as number].images
|
||||
.normal
|
||||
}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
|
||||
Reference in new issue
Block a user