mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: extended ratings stats
This commit is contained in:
1 parent
8faa1143e9
commit
38af2f2817
10 files changed
+160
-68
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||
|
||||
type BlitzResponse<Data extends object> =
|
||||
| {
|
||||
status: 'error';
|
||||
@@ -23,7 +25,7 @@ async function manageQueue() {
|
||||
}, 1000);
|
||||
|
||||
const { url, resolve } = queue.shift()!;
|
||||
const data = (await fetch(url)
|
||||
const data = (await patientFetch(url)
|
||||
.then((response) => response.json())
|
||||
.catch((error) => ({ status: 'error', error }))) as BlitzResponse<
|
||||
typeof resolve
|
||||
|
||||
@@ -51,6 +51,28 @@ export interface ClanStats {
|
||||
dropped_capture_points: number;
|
||||
}
|
||||
|
||||
interface RatingStats {
|
||||
spotted: number;
|
||||
calibration_battles_left: number;
|
||||
hits: number;
|
||||
frags: number;
|
||||
recalibration_start_time: number;
|
||||
mm_rating: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
is_recalibration: boolean;
|
||||
capture_points: number;
|
||||
battles: number;
|
||||
damage_dealt: number;
|
||||
damage_received: number;
|
||||
shots: number;
|
||||
frags8p: number;
|
||||
xp: number;
|
||||
win_and_survived: number;
|
||||
survived_battles: number;
|
||||
dropped_capture_points: number;
|
||||
}
|
||||
|
||||
interface IndividualAccountInfo {
|
||||
account_id: number;
|
||||
created_at: number;
|
||||
@@ -61,6 +83,7 @@ interface IndividualAccountInfo {
|
||||
statistics: {
|
||||
all: AllStats;
|
||||
clan: ClanStats;
|
||||
rating?: RatingStats;
|
||||
frags: null | number;
|
||||
};
|
||||
}
|
||||
@@ -74,11 +97,11 @@ export async function getAccountInfo<
|
||||
ReturnType = Ids extends number
|
||||
? IndividualAccountInfo
|
||||
: IndividualAccountInfo[],
|
||||
>(region: Region, ids: Ids) {
|
||||
>(region: Region, ids: Ids, extra: string[] = []) {
|
||||
const object = await fetchBlitz<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds(
|
||||
ids,
|
||||
)}`,
|
||||
)}${extra.length === 0 ? '' : `&extra=${extra.join(',')}`}`,
|
||||
);
|
||||
|
||||
if (typeof ids === 'number') {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Region, RegionSubdomain } from '../../constants/regions';
|
||||
|
||||
export default function regionSubdomainToRegion(
|
||||
regionDomain: RegionSubdomain,
|
||||
): Region {
|
||||
return regionDomain === 'na' ? 'com' : regionDomain;
|
||||
}
|
||||
+12
-12
@@ -1,17 +1,17 @@
|
||||
import { times } from 'lodash';
|
||||
import { ReadStream, WriteStream } from './buffer';
|
||||
|
||||
enum Format {
|
||||
export enum BkrlFormat {
|
||||
Minimal,
|
||||
Comprehensive1,
|
||||
}
|
||||
|
||||
interface BkrlMinimalEntry {
|
||||
export interface BkrlMinimalEntry {
|
||||
id: number;
|
||||
score: number;
|
||||
}
|
||||
|
||||
interface BkrlComprehensive1Entry {
|
||||
export interface BkrlComprehensive1Entry {
|
||||
id: number;
|
||||
score: number;
|
||||
|
||||
@@ -30,11 +30,11 @@ interface BkrlComprehensive1Entry {
|
||||
|
||||
type DiscriminatedEntries =
|
||||
| {
|
||||
format: Format.Minimal;
|
||||
format: BkrlFormat.Minimal;
|
||||
entries: BkrlMinimalEntry[];
|
||||
}
|
||||
| {
|
||||
format: Format.Comprehensive1;
|
||||
format: BkrlFormat.Comprehensive1;
|
||||
entries: BkrlComprehensive1Entry[];
|
||||
};
|
||||
|
||||
@@ -47,9 +47,9 @@ export class BkrlReadStream extends ReadStream {
|
||||
|
||||
body(header: ReturnType<typeof this.header>): DiscriminatedEntries {
|
||||
switch (header.format) {
|
||||
case Format.Minimal: {
|
||||
case BkrlFormat.Minimal: {
|
||||
return {
|
||||
format: Format.Minimal,
|
||||
format: BkrlFormat.Minimal,
|
||||
entries: times(
|
||||
header.count,
|
||||
() =>
|
||||
@@ -61,9 +61,9 @@ export class BkrlReadStream extends ReadStream {
|
||||
};
|
||||
}
|
||||
|
||||
case Format.Comprehensive1: {
|
||||
case BkrlFormat.Comprehensive1: {
|
||||
return {
|
||||
format: Format.Comprehensive1,
|
||||
format: BkrlFormat.Comprehensive1,
|
||||
entries: times(
|
||||
header.count,
|
||||
() =>
|
||||
@@ -92,7 +92,7 @@ export class BkrlReadStream extends ReadStream {
|
||||
header() {
|
||||
return {
|
||||
version: this.uint16(),
|
||||
format: this.uint8() as Format,
|
||||
format: this.uint8() as BkrlFormat,
|
||||
count: this.uint32(),
|
||||
};
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export class BkrlWriteStream extends WriteStream {
|
||||
|
||||
body(discriminatedEntries: DiscriminatedEntries) {
|
||||
switch (discriminatedEntries.format) {
|
||||
case Format.Minimal: {
|
||||
case BkrlFormat.Minimal: {
|
||||
discriminatedEntries.entries.forEach((entry) => {
|
||||
this.uint32(entry.id);
|
||||
this.uint16(entry.score);
|
||||
@@ -123,7 +123,7 @@ export class BkrlWriteStream extends WriteStream {
|
||||
break;
|
||||
}
|
||||
|
||||
case Format.Comprehensive1: {
|
||||
case BkrlFormat.Comprehensive1: {
|
||||
discriminatedEntries.entries.forEach((entry) => {
|
||||
this.uint32(entry.id);
|
||||
this.uint16(entry.score);
|
||||
|
||||
Reference in new issue
Block a user