feat: improve sgl output

This commit is contained in:
zkldi
2022-08-21 18:07:56 +01:00
parent 393cb22359
commit 6f21054aff
5 changed files with 35 additions and 107 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
out.*
output/
src/cache
+1 -1
View File
@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"calc-v1": "ts-node src/main.ts -v 1 -o out.json"
"calc-v1": "ts-node src/main.ts"
},
"author": "zkldi",
"license": "MIT",
-61
View File
@@ -1,61 +0,0 @@
/* eslint-disable no-await-in-loop */
import logger from "../logger";
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): Array<CalcReturns> {
const dataset = [];
for (const chart of tableInfo.charts) {
const baseLine = GetBaseline(tableInfo.table, chart.level);
if (baseLine === null) {
logger.info(`Skipped level ${tableInfo.table.name} ${chart.level}`);
continue;
}
const str = GetFString(tableInfo.table, chart);
dataset.push({
title: chart.title,
md5: chart.md5,
ecRate: 0,
hcRate: 0,
scoreCount: 0,
baseLine,
str,
});
}
const returns = [];
for (const data of dataset) {
const confidence = GetSigmoidalValue(data.scoreCount / 100);
const ecDiff = 0; // groupAverageECRate - data.ecRate;
const hcDiff = 0; // groupAverageHCRate - data.hcRate;
const ecValue = Math.max(0, data.baseLine - ecDiff * confidence);
const hcValue = Math.max(0, data.baseLine - hcDiff * confidence);
const ecPrefix = ecValue < 12 ? "☆" : "🟊";
const hcPrefix = hcValue < 12 ? "☆" : "🟊";
returns.push({
md5: data.md5,
title: data.title,
ec: ecValue,
ecStr: `${ecPrefix}${ecValue < 12 ? ecValue : ecValue - 12}`,
hc: hcValue,
hcStr: `${hcPrefix}${hcValue < 12 ? hcValue : hcValue - 12}`,
ecMetric: 0,
hcMetric: 0,
});
}
return returns;
}
+32 -44
View File
@@ -1,52 +1,17 @@
import SieglindeV0Calc from "./calc/v0";
import GetTableData from "./fetch-tables";
import logger from "./logger";
import SieglindeV1Calc from "calc/v1-jiminp";
import { Command } from "commander";
import fs from "fs";
import path from "path";
import type { CalcReturns } from "types";
if (require.main !== module) {
logger.error(`The script main.ts must be invoked directly!`);
process.exit(-1);
}
const program = new Command();
program
.option("-v, --version <The Sieglinde Version to calculate>")
.option("-o, --out <Where to output JSON>");
program.parse(process.argv);
const options: {
out?: string;
version?: string;
} = program.opts();
if (!options.out) {
logger.error(`Need to provide an --out parameter for output!`);
process.exit(-1);
}
const version = Number(options.version);
if (Number.isNaN(version)) {
throw new Error(`Unknown sieglinde version ${version}.`);
}
function WriteOut(data: string) {
fs.writeFileSync(options.out!, data);
}
void (async () => {
let calcFn;
if (version === 0) {
calcFn = SieglindeV0Calc;
} else if (version === 1) {
calcFn = SieglindeV1Calc;
} else {
throw new Error(`Unknown sieglinde version ${version}.`);
}
const calcFn = SieglindeV1Calc;
fs.mkdirSync(`${__dirname}/cache`, { recursive: true });
@@ -54,10 +19,10 @@ void (async () => {
logger.info(`Starting...`);
const calcData = [];
let i = 1;
fs.mkdirSync(path.join(__dirname, "output"), { recursive: true });
for (const table of tableInfo) {
logger.info(`Running for table ${table.table.name}. ${i}/${tableInfo.length}`);
@@ -65,14 +30,37 @@ void (async () => {
// 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));
const data = await calcFn(table);
WriteOut(JSON.stringify(calcData.flat(1)));
fs.writeFileSync(
path.join(__dirname, `output/${table.table.name}.json`),
JSON.stringify(data)
);
fs.writeFileSync(path.join(__dirname, `output/${table.table.name}.csv`), toCSV(data));
i++;
}
WriteOut(JSON.stringify(calcData.flat(1)));
logger.info(`Finished!`);
})();
function toCSV(calcData: Array<CalcReturns>) {
let str = `"md5","title","baseLevel","ec","ecStr","hc","hcStr"\n`;
for (const data of calcData) {
const row = [
data.md5,
data.title.replace(/"/gu, '""'),
data.baseLevel,
data.ec,
data.ecStr,
data.hc,
data.hcStr,
];
str = `${str}"${row.join('","')}"\n`;
}
return str;
}
+1
View File
@@ -23,6 +23,7 @@ export interface CalcReturns {
hc: number;
ecStr: string;
hcStr: string;
baseLevel: string;
// Internal values for ec/hc metrics; in the case of the v1 calc, these are
// sigma values.