Merge pull request #18 from tresabhi/1.9.5

This commit is contained in:
TrèsAbhi authored and GitHub committed 2023-07-06 20:27:59 -05:00
commit aa8115d260
13 files changed
+73 -30

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
# Blitzkrieg 1.9.5
Hopefully this is the last round of fixes for Blitzkrieg `1.9``.
## Fixes
- All commands have been tweaked to work even with a lack of a tankopedia entry
- This should fix test tanks not showing up
- `/today` now properly preserves all WN8 entries
+17 -2
View File
@@ -71,12 +71,27 @@ export const eligibleCommand: CommandRegistry = {
(await entries.reduce<PossiblyPromise<number>>(
async (accumulator, [tankIdString, stats]) => {
const tankId = parseInt(tankIdString);
const tankTier = (await tankopedia)[tankId].tier;
const tankopediaEntry = (await tankopedia)[tankId];
if (!tankopediaEntry) return accumulator;
const tankTier = tankopediaEntry.tier;
return (await accumulator) + tankTier * stats.battles;
},
0,
)) / stats.battles;
)) /
(await entries.reduce<PossiblyPromise<number>>(
async (accumulator, [tankIdString, stats]) => {
const tankId = parseInt(tankIdString);
const tankopediaEntry = (await tankopedia)[tankId];
if (!tankopediaEntry) return accumulator;
return stats.battles;
},
0,
));
const WN8 =
(await entries.reduce<PossiblyPromise<number>>(
async (accumulator, [tankIdString, stats]) => {
+15 -9
View File
@@ -7,6 +7,7 @@ import Wrapper from '../components/Wrapper.js';
import { BLITZ_SERVERS } from '../constants/servers.js';
import getTankStats from '../core/blitz/getTankStats.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import resolveTankName from '../core/blitz/resolveTankName.js';
import {
TIER_ROMAN_NUMERALS,
Tier,
@@ -79,7 +80,10 @@ export const ownedTanksCommand: CommandRegistry = {
const tankStats = await getTankStats(server, id);
const tanks = (
await Promise.all(
tankStats.map(async (tankData) => (await tankopedia)[tankData.tank_id]),
tankStats.map(async (tankData) => ({
...(await tankopedia)[tankData.tank_id],
tank_id: tankData.tank_id,
})),
)
).filter((tank) => tank?.tier === tier);
const clanData = await getWargamingResponse<PlayerClanData>(
@@ -106,14 +110,16 @@ export const ownedTanksCommand: CommandRegistry = {
{tanks.length > 0 && (
<Tanks.Root>
{tanks.map((tank) => (
<Tanks.Item
key={tank.tank_id}
name={tank.name}
type={tank.type}
icon={tank.images.normal}
/>
))}
{await Promise.all(
tanks.map(async (tank) => (
<Tanks.Item
key={tank.tank_id}
name={await resolveTankName(tank.tank_id)}
type={tank.type}
icon={tank.images?.normal}
/>
)),
)}
</Tanks.Root>
)}
+3 -1
View File
@@ -69,7 +69,9 @@ export default function AllStatsOverview({
>
<WN8SurroundingStat
label="Tier"
value={supplementaryStats.tier.toFixed(2)}
value={
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
}
/>
<WN8SurroundingStat
label="Survival"
+4 -1
View File
@@ -40,7 +40,10 @@ export default function GenericAllStats({
['Wins', stats.wins],
['Losses', stats.losses],
['Average damage', (stats.damage_dealt / stats.battles).toFixed(0)],
['Average tier', supplementaryStats?.tier.toFixed(2)],
[
'Average tier',
supplementaryStats?.tier ? supplementaryStats?.tier.toFixed(2) : '--',
],
['Average XP', (stats.xp / stats.battles).toFixed(0)],
['Average shots', (stats.shots / stats.battles).toFixed(2)],
['Average hits', (stats.hits / stats.battles).toFixed(2)],
+5 -2
View File
@@ -2,7 +2,7 @@ import { TANK_ICONS, TankType } from '../../../core/blitz/tankopedia.js';
export interface ItemProps {
icon?: string;
type: TankType;
type?: TankType;
name: string;
}
@@ -23,7 +23,10 @@ export function Item({ icon, type, name }: ItemProps) {
{icon && <img src={icon} style={{ flex: 1, objectFit: 'contain' }} />}
<div style={{ display: 'flex', margin: 'auto', gap: 4 }}>
<img src={TANK_ICONS[type]} style={{ width: 14, height: 14 }} />
{type && (
<img src={TANK_ICONS[type]} style={{ width: 14, height: 14 }} />
)}
<span
style={{ fontSize: 16, textAlign: 'center', whiteSpace: 'nowrap' }}
>
+1 -1
View File
@@ -1,6 +1,6 @@
import { tankopedia } from './tankopedia.js';
export default async function resolveTankName(tankId: number) {
const tankopediaName = (await tankopedia)[tankId].name;
const tankopediaName = (await tankopedia)[tankId]?.name;
return tankopediaName ? tankopediaName : `Unknown Tank ${tankId}`;
}
+1 -1
View File
@@ -13,7 +13,7 @@ export interface TankopediaEntry {
}
export interface Tankopedia {
[id: number]: TankopediaEntry;
[id: number]: TankopediaEntry | undefined;
}
console.log('Caching tankopedia...');
+1 -1
View File
@@ -39,7 +39,7 @@ export default async function evolution<Type extends StatType>(
: undefined;
} else {
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
image = (await tankopedia)[tankId!].images.normal;
image = (await tankopedia)[tankId!]?.images.normal;
}
let histories: Histories;
+7 -3
View File
@@ -49,7 +49,7 @@ export default async function stats<Type extends StatType>(
: undefined;
} else if (type === 'tank') {
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
image = (await tankopedia)[tankId!].images.normal;
image = (await tankopedia)[tankId!]?.images.normal;
}
const tankStats = await getTankStatsDiffed(server, id, start, end);
@@ -109,7 +109,11 @@ export default async function stats<Type extends StatType>(
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
async (accumulator, [tankIdString, stats]) => {
const tankId = parseInt(tankIdString);
const tier = (await tankopedia)[tankId].tier as Tier;
const tankopediaEntry = (await tankopedia)[tankId];
if (!tankopediaEntry) return accumulator;
const tier = tankopediaEntry.tier as Tier;
if ((await accumulator)[tier]) {
(await accumulator)[tier]! += stats.battles;
@@ -128,7 +132,7 @@ export default async function stats<Type extends StatType>(
WN8: stats
? calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!])
: undefined,
tier: (await tankopedia)[tankId!].tier,
tier: (await tankopedia)[tankId!]?.tier,
};
}
+3 -3
View File
@@ -47,7 +47,7 @@ export default async function statsfull<Type extends StatType>(
: undefined;
} else if (type === 'tank') {
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
image = (await tankopedia)[tankId!].images.normal;
image = (await tankopedia)[tankId!]?.images.normal;
}
const tankStats = await getTankStatsDiffed(server, id, start, end);
@@ -111,7 +111,7 @@ export default async function statsfull<Type extends StatType>(
if (!tankopediaEntry) return accumulator;
const tier = (await tankopedia)[tankId].tier as Tier;
const tier = tankopediaEntry.tier as Tier;
if ((await accumulator)[tier]) {
(await accumulator)[tier]! += stats.battles;
@@ -128,7 +128,7 @@ export default async function statsfull<Type extends StatType>(
supplementaryStats = {
WN8: calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!]),
tier: (await tankopedia)[tankId!].tier,
tier: (await tankopedia)[tankId!]?.tier,
};
}
+6 -5
View File
@@ -56,22 +56,23 @@ export default async function today({ server, id }: ResolvedPlayer) {
const todayWN8s = await tankStatsOverTimeEntries.reduce<
PossiblyPromise<Record<number, number>>
>(async (accumulator, [tankIdString, tankStats]) => {
const tankId = Number(tankIdString);
const tankId = parseInt(tankIdString);
return tankId === 0 || (await tankAverages)[tankId] === undefined
return tankId === 0 || !(await tankAverages)[tankId]
? accumulator
: {
...accumulator,
...(await 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,
...(await accumulator),
[tank_id]: calculateWN8(
(await tankAverages)[tank_id].all,
careerStats[tank_id],
@@ -132,7 +133,7 @@ export default async function today({ server, id }: ResolvedPlayer) {
icon={
tankId === 0
? undefined
: (await tankopedia)[tankIdString as unknown as number].images
: (await tankopedia)[tankIdString as unknown as number]?.images
.normal
}
/>
+1 -1
View File
@@ -21,7 +21,7 @@ export interface AllStats {
export interface SupplementaryStats {
// if undefined, WN8 is not available for tanks without averages
WN8?: number;
tier: number;
tier?: number;
}
export interface ClanStats {