style: lint sieglinde (unfinished)

This commit is contained in:
zkldi
2022-07-04 02:15:43 +01:00
parent 3977d8058e
commit 4c69a37483
6 changed files with 42 additions and 28 deletions
+3 -3
View File
@@ -1,13 +1,13 @@
/* eslint-disable no-await-in-loop */
import { TableRes } from "../fetch-tables";
import logger from "../logger";
import { CalcReturns } from "../types";
import { GetBaseline, GetFString, GetScoresForMD5, GetSigmoidalValue, Mean } from "../util";
import type { TableRes } from "../fetch-tables";
import type { CalcReturns } from "../types";
/**
* Sieglinde V0 calc. This just reads out hardcoded values for each table, with no fuzzing.
*/
export default function SieglindeV0Calc(tableInfo: TableRes): CalcReturns[] {
export default function SieglindeV0Calc(tableInfo: TableRes): Array<CalcReturns> {
const dataset = [];
for (const chart of tableInfo.charts) {
+9 -8
View File
@@ -1,7 +1,5 @@
/* eslint-disable no-await-in-loop */
import { TableRes } from "../fetch-tables";
import logger from "../logger";
import { CalcReturns } from "../types";
import {
ChunkifyPromiseAll,
GetBaseline,
@@ -9,6 +7,8 @@ import {
GetScoresForMD5,
GetSigmoidalValue,
} from "../util";
import type { TableRes } from "../fetch-tables";
import type { CalcReturns } from "../types";
interface ChartData {
title: string;
@@ -30,7 +30,7 @@ interface ChartData {
*
* This, however, completely does not work. We genuinely cannot use this at all.
*/
export default async function SieglindeV0Calc(tableInfo: TableRes): Promise<CalcReturns[]> {
export default async function SieglindeV0Calc(tableInfo: TableRes): Promise<Array<CalcReturns>> {
// We can't do this in full-parallel. The LR2IR hyper-aggressively rate limits this stuff.
const promises = tableInfo.charts.map((chart) => async () => {
@@ -62,7 +62,7 @@ export default async function SieglindeV0Calc(tableInfo: TableRes): Promise<Calc
const dataset = (await ChunkifyPromiseAll(promises, 100)).filter(
(k) => k !== null
) as ChartData[];
) as Array<ChartData>;
const tableLevelAverageClearRates = GetAverageClearRatesForLevel(dataset);
@@ -92,6 +92,7 @@ export default async function SieglindeV0Calc(tableInfo: TableRes): Promise<Calc
ecStr: `${ecPrefix}${(ecValue < 12.01 ? ecValue : ecValue - 12).toFixed(2)}`,
hc: hcValue,
hcStr: `${hcPrefix}${(hcValue < 12.01 ? hcValue : hcValue - 12).toFixed(2)}`,
// DEBUG
ecRate: data.ecRate,
ecGroupAvg: groupAverageECRate,
@@ -108,7 +109,7 @@ export default async function SieglindeV0Calc(tableInfo: TableRes): Promise<Calc
return returns;
}
function GetAverageClearRatesForLevel(dataset: ChartData[]) {
function GetAverageClearRatesForLevel(dataset: Array<ChartData>) {
const tableLevelTotalClearRates: Record<string, { ec: number; hc: number; total: number }> = {};
for (const scoreRates of dataset) {
@@ -121,9 +122,9 @@ function GetAverageClearRatesForLevel(dataset: ChartData[]) {
} else {
const d = tableLevelTotalClearRates[scoreRates.str];
d.ec += scoreRates.ecRate;
d.hc += scoreRates.hcRate;
d.total += 1;
d.ec = d.ec + scoreRates.ecRate;
d.hc = d.hc + scoreRates.hcRate;
d.total = d.total + 1;
}
}
+5 -4
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import { BMSTablesDataset, BMSTableChart } from "./types";
import fetch from "node-fetch";
import type { BMSTablesDataset, BMSTableChart } from "./types";
export const BMS_TABLES = {
insane: "★",
@@ -14,7 +14,7 @@ export const BMS_TABLES = {
dpInsane: "★",
};
const registeredTables: BMSTablesDataset[] = [
const registeredTables: Array<BMSTablesDataset> = [
{
name: "Insane",
playtype: "7K",
@@ -64,6 +64,7 @@ const registeredTables: BMSTablesDataset[] = [
url: "http://lr2.sakura.ne.jp/data/score.json",
prefix: BMS_TABLES.overjoy,
},
// {
// name: "DP Insane",
// description: "The 14K Insane table.",
@@ -86,10 +87,10 @@ const registeredTables: BMSTablesDataset[] = [
export interface TableRes {
table: BMSTablesDataset;
charts: BMSTableChart[];
charts: Array<BMSTableChart>;
}
export default async function GetTableData(): Promise<TableRes[]> {
export default async function GetTableData(): Promise<Array<TableRes>> {
const out = [];
// only 7k supported atm
+1 -1
View File
@@ -1,5 +1,5 @@
const TableValueGetters: Record<
"Insane" | "Normal" | "Stella" | "Satellite" | "Insane2" | "Normal2" | "Overjoy",
"Insane" | "Insane2" | "Normal" | "Normal2" | "Overjoy" | "Satellite" | "Stella",
(x: string) => number | null
> = {
Insane: (c) => {
+5 -3
View File
@@ -1,8 +1,8 @@
import logger from "./logger";
import fs from "fs";
import { Command } from "commander";
import SieglindeV0Calc from "./calc/v0";
import GetTableData from "./fetch-tables";
import logger from "./logger";
import { Command } from "commander";
import fs from "fs";
if (require.main !== module) {
logger.error(`The script main.ts must be invoked directly!`);
@@ -10,6 +10,7 @@ if (require.main !== module) {
}
const program = new Command();
program
.option("-v, --version <The Sieglinde Version to calculate>")
.option("-o, --out <Where to output JSON>");
@@ -37,6 +38,7 @@ function WriteOut(data: string) {
logger.info(`Starting...`);
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
+19 -9
View File
@@ -1,10 +1,10 @@
/* eslint-disable no-await-in-loop */
import fetch from "node-fetch";
import { XMLParser } from "fast-xml-parser";
import { BMSTableChart, BMSTablesDataset } from "./types";
import TableValueGetters from "./lookups";
import { writeFile, readFile } from "fs/promises";
import logger from "./logger";
import TableValueGetters from "./lookups";
import { XMLParser } from "fast-xml-parser";
import fetch from "node-fetch";
import { writeFile, readFile } from "fs/promises";
import type { BMSTableChart, BMSTablesDataset } from "./types";
const parser = new XMLParser();
@@ -55,6 +55,7 @@ export async function GetScoresForMD5(md5: string) {
} catch (err) {
tries++;
const sleepTime = (1000 * tries + (Math.random() - 0.5) * 1000) * 2;
logger.warn(`Got throttled (${md5}): Sleeping for ${sleepTime.toFixed(0)}ms. ${err}`);
await Sleep(sleepTime);
@@ -64,7 +65,7 @@ export async function GetScoresForMD5(md5: string) {
throw new Error(`Couldn't fetch data in 3 tries. Giving up and killing self.`);
}
export function Mean(d: number[]) {
export function Mean(d: Array<number>) {
return d.reduce((a, r) => a + r, 0) / d.length;
}
@@ -87,7 +88,11 @@ export function GetFString(table: BMSTablesDataset, chart: BMSTableChart) {
}
export function Sleep(ms: number) {
return new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
return new Promise<void>((resolve) =>
setTimeout(() => {
resolve();
}, ms)
);
}
/**
@@ -101,19 +106,24 @@ export function Sleep(ms: number) {
*
* @returns Same as calling Promise.all on your promises.
*/
export async function ChunkifyPromiseAll<D>(promiseFns: (() => Promise<D>)[], chunkSize: number) {
export async function ChunkifyPromiseAll<D>(
promiseFns: Array<() => Promise<D>>,
chunkSize: number
) {
const slices = [];
for (let i = 0; i < promiseFns.length; i += chunkSize) {
for (let i = 0; i < promiseFns.length; i = i + chunkSize) {
const slice = promiseFns.slice(i, i + chunkSize);
slices.push(slice);
}
const results = [];
for (const [n, slice] of Object.entries(slices)) {
logger.info(`>>>>> RUNNING SLICE ${n}`);
const d = await Promise.all(slice.map((fn) => fn()));
logger.info(`>>>>> FINISHED SLICE ${n}`, { len: d.length });
results.push(...d);