fix: types

This commit is contained in:
TrèsAbhi committed 2024-03-25 18:43:23 -05:00
1 parent 71481f5971
commit cb101da8a8
5 files changed
+24 -53

No files matched your search

+3 -8
View File
@@ -16,12 +16,12 @@ Header {
} }
Format enum<uint8> { Format enum<uint8> {
Minimal, Base,
Superset1, Superset1,
} }
Body<Header header> match<header.format> { Body<Header header> match<header.format> {
Minimal { Base {
primary { primary {
uint32 id; uint32 id;
uint16 score; uint16 score;
@@ -37,12 +37,7 @@ Body<Header header> match<header.format> {
uint32 wins; uint32 wins;
uint32 survived; uint32 survived;
uint32 damageDealt; uint32 damage;
uint32 damageReceived;
uint32 shots;
uint32 hits;
uint32 kills; uint32 kills;
}[header.count] entries; }[header.count] entries;
}; };
+7 -13
View File
@@ -13,9 +13,9 @@ import { FileChange } from '../src/core/blitzkrieg/commitMultipleFiles.js';
import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON'; import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON';
import { superCompress } from '../src/core/blitzkrieg/superCompress'; import { superCompress } from '../src/core/blitzkrieg/superCompress';
import { import {
BkrlComprehensive1Entry, BkrlBaseEntry,
BkrlFormat, BkrlFormat,
BkrlMinimalEntry, BkrlSuperset1Entry,
BkrlWriteStream, BkrlWriteStream,
} from '../src/core/streams/bkrl'; } from '../src/core/streams/bkrl';
import { CdonValue, CdonWriteStream } from '../src/core/streams/cdon'; import { CdonValue, CdonWriteStream } from '../src/core/streams/cdon';
@@ -49,7 +49,7 @@ if (PLAYERS === undefined) {
} }
const players: Record<number, RatingPlayer> = {}; const players: Record<number, RatingPlayer> = {};
const leaderboard: BkrlMinimalEntry[] = []; const leaderboard: BkrlBaseEntry[] = [];
let registered = 0; let registered = 0;
async function branchFromPlayer(id: number) { async function branchFromPlayer(id: number) {
@@ -118,7 +118,7 @@ for (let index = 0; index < PLAYERS; index++) {
} }
console.log('Requesting further stats...'); console.log('Requesting further stats...');
const comprehensiveLeaderboard: BkrlComprehensive1Entry[] = []; const comprehensiveLeaderboard: BkrlSuperset1Entry[] = [];
let chunkIndex = 0; let chunkIndex = 0;
for (const leaderboardChunk of chunk(leaderboard, 100)) { for (const leaderboardChunk of chunk(leaderboard, 100)) {
console.log( console.log(
@@ -137,13 +137,10 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) {
leaderboardChunk[index].id === 0 leaderboardChunk[index].id === 0
? { ? {
battles: 0, battles: 0,
damageDealt: 0, damage: 0,
damageReceived: 0,
hits: 0,
id: 0, id: 0,
kills: 0, kills: 0,
score: 0, score: 0,
shots: 0,
survived: 0, survived: 0,
wins: 0, wins: 0,
} }
@@ -151,11 +148,8 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) {
id: leaderboardChunk[index].id, id: leaderboardChunk[index].id,
score: leaderboardChunk[index].score, score: leaderboardChunk[index].score,
battles: stat.statistics.rating!.battles, battles: stat.statistics.rating!.battles,
damageDealt: stat.statistics.rating!.damage_dealt, damage: stat.statistics.rating!.damage_dealt,
damageReceived: stat.statistics.rating!.damage_received,
hits: stat.statistics.rating!.hits,
kills: stat.statistics.rating!.frags, kills: stat.statistics.rating!.frags,
shots: stat.statistics.rating!.shots,
survived: stat.statistics.rating!.survived_battles, survived: stat.statistics.rating!.survived_battles,
wins: stat.statistics.rating!.wins, wins: stat.statistics.rating!.wins,
}; };
@@ -174,7 +168,7 @@ const infoContent = new CdonWriteStream().cdon(
const leaderboardWriteStream = new BkrlWriteStream(); const leaderboardWriteStream = new BkrlWriteStream();
leaderboardWriteStream.bkrl({ leaderboardWriteStream.bkrl({
format: BkrlFormat.Comprehensive1, format: BkrlFormat.Superset1,
entries: comprehensiveLeaderboard, entries: comprehensiveLeaderboard,
}); });
+2 -2
View File
@@ -45,7 +45,7 @@ export const ratingCommand = new Promise<CommandRegistry>((resolve) => {
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined; const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
const leaderboard = await getArchivedRatingLeaderboard(region, 53); const leaderboard = await getArchivedRatingLeaderboard(region, 53);
if (leaderboard.format === BkrlFormat.Minimal) { if (leaderboard.format === BkrlFormat.Base) {
throw new Error( throw new Error(
'Encountered bkrl minimal format in latest season. Wait till next cron?', 'Encountered bkrl minimal format in latest season. Wait till next cron?',
); );
@@ -412,7 +412,7 @@ export const ratingCommand = new Promise<CommandRegistry>((resolve) => {
fontWeight: 'bold', fontWeight: 'bold',
}} }}
> >
{Math.round(delta.damageDealt / delta.battles).toLocaleString( {Math.round(delta.damage / delta.battles).toLocaleString(
interaction.locale, interaction.locale,
)} )}
</span> </span>
+1 -4
View File
@@ -9,11 +9,8 @@ export function deltaBkrlBlitzStats(
) { ) {
return { return {
battles: b1.battles - a.battles, battles: b1.battles - a.battles,
damageDealt: b1.damage_dealt - a.damageDealt, damage: b1.damage_dealt - a.damage,
damageReceived: b1.damage_received - a.damageReceived,
hits: b1.hits - a.hits,
kills: b1.frags - a.kills, kills: b1.frags - a.kills,
shots: b1.shots - a.shots,
survived: b1.survived_battles - a.survived, survived: b1.survived_battles - a.survived,
wins: b1.wins - a.wins, wins: b1.wins - a.wins,
score: b2.score - a.score, score: b2.score - a.score,
+11 -26
View File
@@ -2,11 +2,11 @@ import { times } from 'lodash';
import { ReadStream, WriteStream } from './buffer'; import { ReadStream, WriteStream } from './buffer';
export enum BkrlFormat { export enum BkrlFormat {
Minimal, Base,
Superset1, Superset1,
} }
export interface BkrlMinimalEntry { export interface BkrlBaseEntry {
id: number; id: number;
score: number; score: number;
} }
@@ -19,19 +19,14 @@ export interface BkrlSuperset1Entry {
wins: number; wins: number;
survived: number; survived: number;
damageDealt: number; damage: number;
damageReceived: number;
shots: number;
hits: number;
kills: number; kills: number;
} }
export type BkrlDiscriminatedEntries = export type BkrlDiscriminatedEntries =
| { | {
format: BkrlFormat.Minimal; format: BkrlFormat.Base;
entries: BkrlMinimalEntry[]; entries: BkrlBaseEntry[];
} }
| { | {
format: BkrlFormat.Superset1; format: BkrlFormat.Superset1;
@@ -47,16 +42,16 @@ export class BkrlReadStream extends ReadStream {
body(header: ReturnType<typeof this.header>): BkrlDiscriminatedEntries { body(header: ReturnType<typeof this.header>): BkrlDiscriminatedEntries {
switch (header.format) { switch (header.format) {
case BkrlFormat.Minimal: { case BkrlFormat.Base: {
return { return {
format: BkrlFormat.Minimal, format: BkrlFormat.Base,
entries: times( entries: times(
header.count, header.count,
() => () =>
({ ({
id: this.uint32(), id: this.uint32(),
score: this.uint16(), score: this.uint16(),
}) satisfies BkrlMinimalEntry, }) satisfies BkrlBaseEntry,
), ),
}; };
} }
@@ -75,12 +70,7 @@ export class BkrlReadStream extends ReadStream {
wins: this.uint32(), wins: this.uint32(),
survived: this.uint32(), survived: this.uint32(),
damageDealt: this.uint32(), damage: this.uint32(),
damageReceived: this.uint32(),
shots: this.uint32(),
hits: this.uint32(),
kills: this.uint32(), kills: this.uint32(),
}) satisfies BkrlSuperset1Entry, }) satisfies BkrlSuperset1Entry,
), ),
@@ -115,7 +105,7 @@ export class BkrlWriteStream extends WriteStream {
body(discriminatedEntries: BkrlDiscriminatedEntries) { body(discriminatedEntries: BkrlDiscriminatedEntries) {
switch (discriminatedEntries.format) { switch (discriminatedEntries.format) {
case BkrlFormat.Minimal: { case BkrlFormat.Base: {
discriminatedEntries.entries.forEach((entry) => { discriminatedEntries.entries.forEach((entry) => {
this.uint32(entry.id); this.uint32(entry.id);
this.uint16(entry.score); this.uint16(entry.score);
@@ -132,12 +122,7 @@ export class BkrlWriteStream extends WriteStream {
this.uint32(entry.wins); this.uint32(entry.wins);
this.uint32(entry.survived); this.uint32(entry.survived);
this.uint32(entry.damageDealt); this.uint32(entry.damage);
this.uint32(entry.damageReceived);
this.uint32(entry.shots);
this.uint32(entry.hits);
this.uint32(entry.kills); this.uint32(entry.kills);
}); });
break; break;