mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: patient ratings leaderboard building
This commit is contained in:
1 parent
f02db2a2d8
commit
3d9872a671
1 file changed
+22
-7
@@ -13,11 +13,26 @@ import commitMultipleFiles from './commitMultipleFiles.js';
|
|||||||
* Central European Time (UTC+1): use 0 23 * * *.
|
* Central European Time (UTC+1): use 0 23 * * *.
|
||||||
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
* Central Asia Standard Time (UTC+7): use 0 17 * * *.
|
||||||
*
|
*
|
||||||
* na/ratings/49/info.json: season info like rewards, start & end time, etc.
|
* [region]/ratings/[season]/info.json: season info like rewards, start & end time, etc.
|
||||||
* na/ratings/49/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
* [region]/ratings/[season]/latest.json: the absolute latest leaderboard recorded at UTC+0 midnight
|
||||||
* na/ratings/49/midnight.json: last midnight's leaderboard relative to the region
|
* [region]/ratings/[season]/midnight.json: last midnight's leaderboard relative to the region
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
async function patientFetch(url: string) {
|
||||||
|
let patientResponse: Response;
|
||||||
|
|
||||||
|
while (patientResponse! === undefined) {
|
||||||
|
try {
|
||||||
|
patientResponse = await fetch(url);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Failed to fetch ${url}; retrying in 1 minute...`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1 * 60 * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return patientResponse;
|
||||||
|
}
|
||||||
|
|
||||||
export type BlitzkriegRatingsLeaderboard = { id: number; score: number }[];
|
export type BlitzkriegRatingsLeaderboard = { id: number; score: number }[];
|
||||||
|
|
||||||
const publish = argv.includes('--publish');
|
const publish = argv.includes('--publish');
|
||||||
@@ -27,7 +42,7 @@ const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1];
|
|||||||
if (!server) throw new Error('Region parameter not specified');
|
if (!server) throw new Error('Region parameter not specified');
|
||||||
|
|
||||||
const NEIGHBORS = 1000;
|
const NEIGHBORS = 1000;
|
||||||
const PLAYERS = await fetch(
|
const PLAYERS = await patientFetch(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
)
|
)
|
||||||
.then((response) => response.json() as Promise<RatingsInfo>)
|
.then((response) => response.json() as Promise<RatingsInfo>)
|
||||||
@@ -42,7 +57,7 @@ const leaderboard: BlitzkriegRatingsLeaderboard = [];
|
|||||||
let registered = 0;
|
let registered = 0;
|
||||||
|
|
||||||
async function branchFromPlayer(id: number) {
|
async function branchFromPlayer(id: number) {
|
||||||
const { neighbors } = await fetch(
|
const { neighbors } = await patientFetch(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
||||||
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
||||||
|
|
||||||
@@ -73,7 +88,7 @@ async function branchFromPlayer(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function branchFromLeague(id: number) {
|
async function branchFromLeague(id: number) {
|
||||||
const { result } = await fetch(
|
const { result } = await patientFetch(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
||||||
).then((response) => response.json() as Promise<{ result: RatingsPlayer[] }>);
|
).then((response) => response.json() as Promise<{ result: RatingsPlayer[] }>);
|
||||||
|
|
||||||
@@ -111,7 +126,7 @@ const leaderboardJSON = JSON.stringify(leaderboard);
|
|||||||
if (publish) {
|
if (publish) {
|
||||||
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
const octokit = new Octokit({ auth: env.GH_TOKEN });
|
||||||
|
|
||||||
const info = await fetch(
|
const info = await patientFetch(
|
||||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
).then(
|
).then(
|
||||||
(response) =>
|
(response) =>
|
||||||
|
|||||||
Reference in new issue
Block a user