From ea7ef026f0ab038d07dfc1e388f5893ffccd84d8 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sat, 20 Aug 2022 13:03:41 +0100 Subject: [PATCH] feat: more sieglinde general work --- sieglinde/package.json | 3 +- sieglinde/src/calc/v1-jiminp.ts | 7 ++--- sieglinde/src/fetch-tables.ts | 4 ++- sieglinde/src/main.ts | 35 ++++++++++++----------- sieglinde/src/scripts/fetch-chart-data.ts | 20 +++++++++++++ sieglinde/src/util/calc.ts | 2 -- 6 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 sieglinde/src/scripts/fetch-chart-data.ts diff --git a/sieglinde/package.json b/sieglinde/package.json index c666ab634..c75598c8e 100644 --- a/sieglinde/package.json +++ b/sieglinde/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "calc-v1": "ts-node src/main.ts -v 1 -o out.json" }, "author": "zkldi", "license": "MIT", diff --git a/sieglinde/src/calc/v1-jiminp.ts b/sieglinde/src/calc/v1-jiminp.ts index 503c3a906..dca1a0ee5 100644 --- a/sieglinde/src/calc/v1-jiminp.ts +++ b/sieglinde/src/calc/v1-jiminp.ts @@ -62,19 +62,16 @@ export default async function SieglindeV2Calc(tableInfo: TableRes): Promise ecComputer.songDifficulty.has(chart.md5)) .map((chart) => { const ecValue = ecComputer.songDifficulty.get(chart.md5)!; - const ecPrefix = "σ"; - const hcValue = hcComputer.songDifficulty.get(chart.md5)!; - const hcPrefix = "σ"; return { md5: chart.md5, title: chart.title, baseLevel: GetFString(tableInfo.table, chart), ec: ecValue, - ecStr: `${ecPrefix}${ecValue.toFixed(2)}`, + ecStr: `a`, hc: hcValue, - hcStr: `${hcPrefix}${hcValue.toFixed(2)}`, + hcStr: `a`, }; }); } diff --git a/sieglinde/src/fetch-tables.ts b/sieglinde/src/fetch-tables.ts index 452defec4..11a6682da 100644 --- a/sieglinde/src/fetch-tables.ts +++ b/sieglinde/src/fetch-tables.ts @@ -14,7 +14,9 @@ export interface TableRes { export default async function GetTableData(): Promise> { const out = []; - for (const table of registeredTables) { + for (const table of registeredTables.filter( + (e) => e.name === "Insane" || e.name === "Normal" + )) { const charts = await fetch(table.url).then((r) => r.json()); out.push({ table, charts }); diff --git a/sieglinde/src/main.ts b/sieglinde/src/main.ts index ef3d3deff..78f2a6524 100644 --- a/sieglinde/src/main.ts +++ b/sieglinde/src/main.ts @@ -48,28 +48,29 @@ void (async () => { throw new Error(`Unknown sieglinde version ${version}.`); } - if (version === 0) { - fs.mkdirSync(`${__dirname}/cache`, { recursive: true }); + fs.mkdirSync(`${__dirname}/cache`, { recursive: true }); - const tableInfo = await GetTableData(); + const tableInfo = await GetTableData(); - logger.info(`Starting...`); + logger.info(`Starting...`); - const calcData = []; + const calcData = []; - for (const table of tableInfo) { - // literally all the parallelism in this codebase has to be turned off because - // the lr2ir runs off of a toaster which attempts to gut you if you make more than one - // request a second. - // eslint-disable-next-line no-await-in-loop - calcData.push(await calcFn(table)); - } + let i = 1; - WriteOut(JSON.stringify(calcData.flat(1))); + for (const table of tableInfo) { + logger.info(`Running for table ${table.table.name}. ${i}/${tableInfo.length}`); - logger.info(`Finished!`); - } else { - logger.error(`Unsupported/Unknown version ${version}.`); - process.exit(-1); + // literally all the parallelism in this codebase has to be turned off because + // the lr2ir runs off of a toaster which attempts to gut you if you make more than one + // request a second. + // eslint-disable-next-line no-await-in-loop + calcData.push(await calcFn(table)); + + i++; } + + WriteOut(JSON.stringify(calcData.flat(1))); + + logger.info(`Finished!`); })(); diff --git a/sieglinde/src/scripts/fetch-chart-data.ts b/sieglinde/src/scripts/fetch-chart-data.ts new file mode 100644 index 000000000..141b3425a --- /dev/null +++ b/sieglinde/src/scripts/fetch-chart-data.ts @@ -0,0 +1,20 @@ +import GetTableData from "../fetch-tables"; +import { ChunkifyPromiseAll, GetScoresForMD5 } from "../util"; + +export default async function FetchAllTableScores() { + const tableInfo = await GetTableData(); + + const promises = []; + + for (const table of tableInfo) { + for (const chart of table.charts) { + promises.push(() => GetScoresForMD5(chart.md5)); + } + } + + await ChunkifyPromiseAll(promises, 100); +} + +if (require.main === module) { + void FetchAllTableScores(); +} diff --git a/sieglinde/src/util/calc.ts b/sieglinde/src/util/calc.ts index 9410c9ed8..dd385e03a 100644 --- a/sieglinde/src/util/calc.ts +++ b/sieglinde/src/util/calc.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ - import logger from "../logger"; type SongId = string;