Add X-Rank leaderboard data

This commit is contained in:
Matt Isenhower
2023-02-12 09:07:02 -08:00
parent 63a4654481
commit 8b2cd71e5f
4 changed files with 172 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import StageScheduleUpdater from "./updaters/StageScheduleUpdater.mjs";
import CoopUpdater from "./updaters/CoopUpdater.mjs";
import FestivalUpdater from "./updaters/FestivalUpdater.mjs";
import { regionTokens } from "../splatnet/NsoClient.mjs";
import XRankUpdater from "./updaters/XRankUpdater.mjs";
function updaters() {
const tokens = regionTokens();
@@ -15,6 +16,8 @@ function updaters() {
tokens.EU && new FestivalUpdater('EU'),
tokens.JP && new FestivalUpdater('JP'),
tokens.AP && new FestivalUpdater('AP'),
new XRankUpdater('Tentatek', 'ATLANTIC'),
new XRankUpdater('Takoroka', 'PACIFIC'),
].filter(u => u);
}

View File

@@ -0,0 +1,49 @@
import prefixedConsole from "../../common/prefixedConsole.mjs";
import DataUpdater from "./DataUpdater.mjs";
export default class XRankDetailUpdater extends DataUpdater
{
name = 'X-Rank Detail';
filename = 'xrank/xrank.detail';
imagePaths = [
'$..image.url',
'$..image2d.url',
'$..image2dThumbnail.url',
'$..image3d.url',
'$..image3dThumbnail.url',
];
constructor(seasonId, xRankDetailType) {
super();
this.seasonId = seasonId;
this.xRankDetailType = xRankDetailType;
this.filename += `.${seasonId}.${xRankDetailType.key}`;
}
get console() {
this._console ??= prefixedConsole('Updater', this.region, this.name, this.seasonId, this.xRankDetailType.name);
return this._console;
}
async getData(locale) {
let result;
let edges = [];
let dataKey = this.xRankDetailType.dataKey;
// Get each page's data
let pages = this.splatnet(locale).getXRankingDetailPages(this.xRankDetailType, this.seasonId);
for await (let page of pages) {
result = page;
edges.push(...page.data.node[dataKey].edges);
}
// Replace the list of nodes with the complete list from all pages
result.data.node[dataKey].edges = edges;
return result;
}
}

View File

@@ -0,0 +1,47 @@
import prefixedConsole from "../../common/prefixedConsole.mjs";
import DataUpdater from "./DataUpdater.mjs";
import XRankDetailUpdater from "./XRankDetailUpdater.mjs";
export default class XRankUpdater extends DataUpdater
{
name = 'X-Rank';
filename = 'xrank/xrank';
imagePaths = [
'$..image.url',
'$..image2d.url',
'$..image2dThumbnail.url',
'$..image3d.url',
'$..image3dThumbnail.url',
];
constructor(divisionName, divisionKey) {
super();
this.divisionName = divisionName;
this.divisionKey = divisionKey;
this.filename += `.${divisionName.toLowerCase()}`;
}
get console() {
this._console ??= prefixedConsole('Updater', this.region, this.name, this.divisionName);
return this._console;
}
async getData(locale) {
let result = await this.splatnet(locale).getXRankingData(this.divisionKey);
let seasonId = result.data.xRanking.currentSeason.id;
await this.updateSeasonDetail(seasonId);
return result;
}
async updateSeasonDetail(seasonId) {
for (let type of this.splatnet().getXRankingDetailQueryTypes()) {
let updater = new XRankDetailUpdater(seasonId, type);
await updater.updateIfNeeded();
}
}
}