From cb101da8a8d3f1b1214a249eb176903bfb2c6f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:43:23 -0500 Subject: [PATCH] fix: types --- docs/guide/bkrl.md | 11 ++----- scripts/buildRatingLeaderboard.ts | 20 ++++-------- src/commands/rating.tsx | 4 +-- src/core/statistics/deltaBkrlBlitzStats.ts | 5 +-- src/core/streams/bkrl.ts | 37 +++++++--------------- 5 files changed, 24 insertions(+), 53 deletions(-) diff --git a/docs/guide/bkrl.md b/docs/guide/bkrl.md index 03c8db8c2..80f1ecdd2 100644 --- a/docs/guide/bkrl.md +++ b/docs/guide/bkrl.md @@ -16,12 +16,12 @@ Header { } Format enum { - Minimal, + Base, Superset1, } Body
match { - Minimal { + Base { primary { uint32 id; uint16 score; @@ -37,12 +37,7 @@ Body
match { uint32 wins; uint32 survived; - uint32 damageDealt; - uint32 damageReceived; - - uint32 shots; - uint32 hits; - + uint32 damage; uint32 kills; }[header.count] entries; }; diff --git a/scripts/buildRatingLeaderboard.ts b/scripts/buildRatingLeaderboard.ts index 710fee84d..937694d83 100644 --- a/scripts/buildRatingLeaderboard.ts +++ b/scripts/buildRatingLeaderboard.ts @@ -13,9 +13,9 @@ import { FileChange } from '../src/core/blitzkrieg/commitMultipleFiles.js'; import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON'; import { superCompress } from '../src/core/blitzkrieg/superCompress'; import { - BkrlComprehensive1Entry, + BkrlBaseEntry, BkrlFormat, - BkrlMinimalEntry, + BkrlSuperset1Entry, BkrlWriteStream, } from '../src/core/streams/bkrl'; import { CdonValue, CdonWriteStream } from '../src/core/streams/cdon'; @@ -49,7 +49,7 @@ if (PLAYERS === undefined) { } const players: Record = {}; -const leaderboard: BkrlMinimalEntry[] = []; +const leaderboard: BkrlBaseEntry[] = []; let registered = 0; async function branchFromPlayer(id: number) { @@ -118,7 +118,7 @@ for (let index = 0; index < PLAYERS; index++) { } console.log('Requesting further stats...'); -const comprehensiveLeaderboard: BkrlComprehensive1Entry[] = []; +const comprehensiveLeaderboard: BkrlSuperset1Entry[] = []; let chunkIndex = 0; for (const leaderboardChunk of chunk(leaderboard, 100)) { console.log( @@ -137,13 +137,10 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) { leaderboardChunk[index].id === 0 ? { battles: 0, - damageDealt: 0, - damageReceived: 0, - hits: 0, + damage: 0, id: 0, kills: 0, score: 0, - shots: 0, survived: 0, wins: 0, } @@ -151,11 +148,8 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) { id: leaderboardChunk[index].id, score: leaderboardChunk[index].score, battles: stat.statistics.rating!.battles, - damageDealt: stat.statistics.rating!.damage_dealt, - damageReceived: stat.statistics.rating!.damage_received, - hits: stat.statistics.rating!.hits, + damage: stat.statistics.rating!.damage_dealt, kills: stat.statistics.rating!.frags, - shots: stat.statistics.rating!.shots, survived: stat.statistics.rating!.survived_battles, wins: stat.statistics.rating!.wins, }; @@ -174,7 +168,7 @@ const infoContent = new CdonWriteStream().cdon( const leaderboardWriteStream = new BkrlWriteStream(); leaderboardWriteStream.bkrl({ - format: BkrlFormat.Comprehensive1, + format: BkrlFormat.Superset1, entries: comprehensiveLeaderboard, }); diff --git a/src/commands/rating.tsx b/src/commands/rating.tsx index 669a7331a..6d765ada9 100644 --- a/src/commands/rating.tsx +++ b/src/commands/rating.tsx @@ -45,7 +45,7 @@ export const ratingCommand = new Promise((resolve) => { const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined; const leaderboard = await getArchivedRatingLeaderboard(region, 53); - if (leaderboard.format === BkrlFormat.Minimal) { + if (leaderboard.format === BkrlFormat.Base) { throw new Error( 'Encountered bkrl minimal format in latest season. Wait till next cron?', ); @@ -412,7 +412,7 @@ export const ratingCommand = new Promise((resolve) => { fontWeight: 'bold', }} > - {Math.round(delta.damageDealt / delta.battles).toLocaleString( + {Math.round(delta.damage / delta.battles).toLocaleString( interaction.locale, )} diff --git a/src/core/statistics/deltaBkrlBlitzStats.ts b/src/core/statistics/deltaBkrlBlitzStats.ts index 749b24bd0..670d31b9a 100644 --- a/src/core/statistics/deltaBkrlBlitzStats.ts +++ b/src/core/statistics/deltaBkrlBlitzStats.ts @@ -9,11 +9,8 @@ export function deltaBkrlBlitzStats( ) { return { battles: b1.battles - a.battles, - damageDealt: b1.damage_dealt - a.damageDealt, - damageReceived: b1.damage_received - a.damageReceived, - hits: b1.hits - a.hits, + damage: b1.damage_dealt - a.damage, kills: b1.frags - a.kills, - shots: b1.shots - a.shots, survived: b1.survived_battles - a.survived, wins: b1.wins - a.wins, score: b2.score - a.score, diff --git a/src/core/streams/bkrl.ts b/src/core/streams/bkrl.ts index 6af5a7027..19bdf31d9 100644 --- a/src/core/streams/bkrl.ts +++ b/src/core/streams/bkrl.ts @@ -2,11 +2,11 @@ import { times } from 'lodash'; import { ReadStream, WriteStream } from './buffer'; export enum BkrlFormat { - Minimal, + Base, Superset1, } -export interface BkrlMinimalEntry { +export interface BkrlBaseEntry { id: number; score: number; } @@ -19,19 +19,14 @@ export interface BkrlSuperset1Entry { wins: number; survived: number; - damageDealt: number; - damageReceived: number; - - shots: number; - hits: number; - + damage: number; kills: number; } export type BkrlDiscriminatedEntries = | { - format: BkrlFormat.Minimal; - entries: BkrlMinimalEntry[]; + format: BkrlFormat.Base; + entries: BkrlBaseEntry[]; } | { format: BkrlFormat.Superset1; @@ -47,16 +42,16 @@ export class BkrlReadStream extends ReadStream { body(header: ReturnType): BkrlDiscriminatedEntries { switch (header.format) { - case BkrlFormat.Minimal: { + case BkrlFormat.Base: { return { - format: BkrlFormat.Minimal, + format: BkrlFormat.Base, entries: times( header.count, () => ({ id: this.uint32(), score: this.uint16(), - }) satisfies BkrlMinimalEntry, + }) satisfies BkrlBaseEntry, ), }; } @@ -75,12 +70,7 @@ export class BkrlReadStream extends ReadStream { wins: this.uint32(), survived: this.uint32(), - damageDealt: this.uint32(), - damageReceived: this.uint32(), - - shots: this.uint32(), - hits: this.uint32(), - + damage: this.uint32(), kills: this.uint32(), }) satisfies BkrlSuperset1Entry, ), @@ -115,7 +105,7 @@ export class BkrlWriteStream extends WriteStream { body(discriminatedEntries: BkrlDiscriminatedEntries) { switch (discriminatedEntries.format) { - case BkrlFormat.Minimal: { + case BkrlFormat.Base: { discriminatedEntries.entries.forEach((entry) => { this.uint32(entry.id); this.uint16(entry.score); @@ -132,12 +122,7 @@ export class BkrlWriteStream extends WriteStream { this.uint32(entry.wins); this.uint32(entry.survived); - this.uint32(entry.damageDealt); - this.uint32(entry.damageReceived); - - this.uint32(entry.shots); - this.uint32(entry.hits); - + this.uint32(entry.damage); this.uint32(entry.kills); }); break;