Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
// Builds one self-contained HTML page with the graphs of the simulator runs.
|
|
// Nothing is uploaded anywhere; open the file in a browser.
|
|
//
|
|
// node scripts/sim-report.mjs # turn the runs in .tmp/sim into tables
|
|
// node scripts/sim-dashboard.mjs # -> .tmp/sim/dashboard.html
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const dir = resolve(process.argv[2] ?? join(here, "..", ".tmp", "sim"));
|
|
const read = (name) => JSON.parse(readFileSync(join(dir, "data", `${name}.json`), "utf8"));
|
|
|
|
const data = {
|
|
scaling: read("scaling"),
|
|
timeline: read("timeline"),
|
|
phases: read("phases"),
|
|
arrival: read("arrival"),
|
|
generated: new Date().toISOString().slice(0, 16).replace("T", " "),
|
|
};
|
|
// "<" cannot appear in the JSON, so the data can never close its own script tag
|
|
const json = JSON.stringify(data).replace(/</g, "\\u003c");
|
|
const page = readFileSync(join(here, "sim-dashboard.template.html"), "utf8").replace("__DATA__", () => json);
|
|
const out = join(dir, "dashboard.html");
|
|
writeFileSync(out, page);
|
|
console.log(`wrote ${out} (${Math.round(page.length / 1024)} KB, ${data.scaling.length} runs)`);
|