fix: some rating functionality

This commit is contained in:
tresabhi committed 2024-11-20 10:50:09 -06:00
1 parent fcb848df5b
commit 5bf6a14cff
9 files changed
+104 -111

No files matched your search

+36 -19
View File
@@ -1,24 +1,41 @@
// import { Region } from '@blitzkit/core';
// import { context } from '../blitzkit/context';
// import { patientFetch } from '../blitzkit/patientFetch';
// import { regionToRegionSubdomain } from './regionToRegionSubdomain';
import { RatingLeague, RatingReward, Region } from '@blitzkit/core';
import { context } from '../blitzkit/context';
import { patientFetch } from '../blitzkit/patientFetch';
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
// const cache: Partial<Record<Region, RatingInfo>> = {};
export type RatingInfo =
| {
detail: undefined;
// export async function getRatingInfo(region: Region) {
// if (cache[region]) return cache[region]!;
title: string;
icon: string | null;
start_at: string;
finish_at: string;
current_season: number;
updated_at: string;
count: number;
// const response = await patientFetch(
// context === 'website'
// ? `/api/${region}/rating/current/info`
// : `https://${regionToRegionSubdomain(
// region,
// )}.wotblitz.com/en/api/rating-leaderboards/season/`,
// undefined,
// );
// const data = (await response.json()) as RatingInfo;
rewards: RatingReward[];
leagues: RatingLeague[];
}
| { detail: { error: string } };
// cache[region] = data;
const cache: Partial<Record<Region, RatingInfo>> = {};
// return data;
// }
export async function getRatingInfo(region: Region) {
if (cache[region]) return cache[region]!;
const response = await patientFetch(
context === 'website'
? `/api/${region}/rating/current/info`
: `https://${regionToRegionSubdomain(
region,
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
undefined,
);
const data = (await response.json()) as RatingInfo;
cache[region] = data;
return data;
}
+1 -1
View File
@@ -9,7 +9,7 @@ export * from './getAccountInfo';
export * from './getClanAccountInfo';
export * from './getClanInfo';
export * from './getLeagueFromScore';
// export * from './getRatingInfo';
export * from './getRatingInfo';
export * from './getRatingLeague';
export * from './getRatingNeighbors';
export * from './getTankStats';
+5 -5
View File
@@ -1,11 +1,11 @@
import { RatingPlayer } from '../statistics';
export const LEAGUES = [
{ name: 'diamond', minScore: 5000, index: 0 },
{ name: 'platinum', minScore: 4000, index: 1 },
{ name: 'gold', minScore: 3000, index: 2 },
{ name: 'silver', minScore: 2000, index: 3 },
{ name: 'bronze', minScore: -Infinity, index: 4 },
{ name: 'diamond', minScore: 5000, index: 0, icon: 'YOw6mZ4' },
{ name: 'platinum', minScore: 4000, index: 1, icon: 'AOzDENm' },
{ name: 'gold', minScore: 3000, index: 2, icon: 'InVGtQy' },
{ name: 'silver', minScore: 2000, index: 3, icon: 'HD4ADcL' },
{ name: 'bronze', minScore: -Infinity, index: 4, icon: 'Ka4nNyv' },
];
export interface RatingNeighbors {
neighbors: RatingPlayer[];
@@ -1,11 +1,6 @@
import {
asset,
BkrlDiscriminatedEntries,
BkrlReadStream,
Region,
} from '@blitzkit/core';
import { asset, RatingLeaderboard, Region } from '@blitzkit/core';
const cache: Record<Region, Record<number, BkrlDiscriminatedEntries>> = {
const cache: Record<Region, Record<number, RatingLeaderboard>> = {
asia: {},
eu: {},
com: {},
@@ -16,11 +11,9 @@ export async function getArchivedRatingLeaderboard(
season: number,
) {
if (!cache[region][season]) {
const info = await fetch(
asset(`regions/${region}/rating/${season}/latest.bkrl`),
)
const info = await fetch(asset(`regions/${region}/rating/${season}.pb`))
.then((response) => response.arrayBuffer())
.then((buffer) => new BkrlReadStream(buffer).bkrl());
.then((buffer) => RatingLeaderboard.decode(new Uint8Array(buffer)));
cache[region][season] = info;
}
@@ -1,32 +0,0 @@
import {
asset,
BkrlDiscriminatedEntries,
BkrlReadStream,
Region,
} from '@blitzkit/core';
const cache: Record<Region, Record<number, BkrlDiscriminatedEntries | null>> = {
com: {},
eu: {},
asia: {},
};
export async function getArchivedRatingMidnightLeaderboard(
region: Region,
season: number,
) {
if (!cache[region][season]) {
const info = await fetch(
asset(`regions/${region}/rating/${season}/midnight.bkrl`),
)
.then((response) =>
response.status === 404 ? null : response.arrayBuffer(),
)
.then((buffer) =>
buffer === null ? null : new BkrlReadStream(buffer).bkrl(),
);
cache[region][season] = info;
}
return cache[region][season];
}
+1 -1
View File
@@ -18,7 +18,7 @@ export * from './gameDefinitions';
export * from './getArchivedLatestSeasonNumber';
// export * from './getArchivedRatingInfo';
export * from './getArchivedRatingLeaderboard';
export * from './getArchivedRatingMidnightLeaderboard';
// export * from './getArchivedRatingMidnightLeaderboard';
export * from './getTimeDaysAgo';
export * from './isExplosive';
export * from './linkBlitzAndDiscord';