feat: dataset builder
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a1e9ce86a0
commit
ca9f3bbb83
@@ -0,0 +1,42 @@
|
||||
import { buildSong } from "./dataset.ts";
|
||||
import type { TierId } from "../gen/tiers.ts";
|
||||
import { TIERS } from "../gen/tiers.ts";
|
||||
|
||||
function parseSeeds(s: string): number[] {
|
||||
const out: number[] = [];
|
||||
for (const part of s.split(",")) {
|
||||
const m = /^(\d+)-(\d+)$/.exec(part);
|
||||
if (m) for (let i = Number(m[1]); i <= Number(m[2]); i++) out.push(i);
|
||||
else if (/^\d+$/.test(part)) out.push(Number(part));
|
||||
else throw new Error(`bad seeds: ${s}`);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function arg(args: string[], name: string, def: string): string {
|
||||
const i = args.indexOf(`--${name}`);
|
||||
return i >= 0 && args[i + 1] ? args[i + 1]! : def;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const [cmd, ...rest] = process.argv.slice(2);
|
||||
switch (cmd) {
|
||||
case "gen": {
|
||||
const tiers = arg(rest, "tiers", "t1a,t1b,t1c,t1d").split(",") as TierId[];
|
||||
for (const t of tiers) if (!(t in TIERS)) throw new Error(`unknown tier: ${t}`);
|
||||
const seeds = parseSeeds(arg(rest, "seeds", "1-5"));
|
||||
const root = arg(rest, "root", "data");
|
||||
for (const t of tiers) for (const s of seeds) {
|
||||
const t0 = performance.now();
|
||||
const dir = await buildSong(t, s, root);
|
||||
console.log(`${dir} (${((performance.now() - t0) / 1000).toFixed(1)}s)`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.error("usage: bun run bench gen [--tiers t1a,t1b] [--seeds 1-5] [--root data]");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
Reference in New Issue
Block a user