Refactor: lay the repo out by section (core, collection, analysis, planner, site) (#8)

Moves only; no behaviour changes. Every file now lives under the part of the project it
belongs to, each section has a README, and docs/PRIVACY.md collects the rules all parts follow.

  core/        engine.js, graph.js, solver.js, python/clean.py
  collection/  sources/ (form, register, PDF check, daily update), bot/ (importer)
  analysis/    stats/ (Python statistics), network/ (build-graph.js), reports/ (POLICY.md)
  planner/     build-policy.js, policy-report.js
  site/        atlas/ (the page), build.js, qa/
  tests/       core/ (unit), parity/ (JS vs Python), fixtures/

Checked against the previous layout: tests pass; coded runs, test outputs, graph.json and
policy.json are byte-identical; the built site differs only in comments that name file paths.
The published file names Ken's bot downloads (solver.js, graph.js, data/policy.json) are unchanged.

Also removes the undefined/ folder of QA screenshots committed by mistake (the QA scripts now
default to a temp folder) and test.txt, and drops the unused npm workspaces.


Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ekcSchiano
2026-11-03 19:46:33 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent dcd5117373
commit 432e04c2c7
66 changed files with 201 additions and 2695 deletions
+42
View File
@@ -0,0 +1,42 @@
"""check_colours.py: are the dragon colours (valley.js INK, index.html --dr-*) still distinguishable?
python site/qa/check_colours.py
"""
"""Pairwise CIEDE2000 between dragon colours, normal vision and simulated colour-vision deficiencies (Machado 2009, severity 1),
plus contrast against the backgrounds they sit on."""
import itertools, sys
import numpy as np
from skimage.color import rgb2lab, deltaE_ciede2000
MAP = {"Red": "#cc3346", "Orange": "#e08a2a", "Brown": "#4e3020", "Green": "#2f8f6f", "Blue": "#2a58b8", "Black": "#22182a"}
UI = {"Red": "#e8435e", "Orange": "#ff9533", "Brown": "#d1a47a", "Green": "#3fc0a8", "Blue": "#7ea6ff", "Black": "#e0d8ea"}
if len(sys.argv) > 1: # candidate palettes passed as name=hex,...
for arg in sys.argv[1:]:
k, v = arg.split(":", 1)
d = dict(x.split("=") for x in v.split(","))
(MAP if k == "map" else UI).update(d)
BG = {"map paper": "#e9c88f", "map canopy": "#6c6b40", "ui dark": "#210f19"}
M = { # Machado et al. 2009, severity 1.0, applied in linear RGB
"protan": [[0.152286, 1.052583, -0.204868], [0.114503, 0.786281, 0.099216], [-0.003882, -0.048116, 1.051998]],
"deutan": [[0.367322, 0.860646, -0.227968], [0.280085, 0.672501, 0.047413], [-0.011820, 0.042940, 0.968881]],
"tritan": [[1.255528, -0.076749, -0.178779], [-0.078411, 0.930809, 0.147602], [0.004733, 0.691367, 0.303900]],
}
def rgb(h): h = h.lstrip("#"); return np.array([int(h[i:i + 2], 16) for i in (0, 2, 4)]) / 255
def lin(c): return np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4)
def unlin(c): c = np.clip(c, 0, 1); return np.where(c <= 0.0031308, c * 12.92, 1.055 * c ** (1 / 2.4) - 0.055)
def sim(c, kind): return c if kind == "normal" else unlin(np.array(M[kind]) @ lin(c))
def lab(c): return rgb2lab(c.reshape(1, 1, 3)).reshape(3)
def de(a, b): return float(deltaE_ciede2000(lab(a), lab(b)))
def lum(c): l = lin(c); return 0.2126 * l[0] + 0.7152 * l[1] + 0.0722 * l[2]
def contrast(a, b): x, y = sorted([lum(a), lum(b)], reverse=True); return (x + 0.05) / (y + 0.05)
for name, P in [("MAP (on paper)", MAP), ("UI (on dark)", UI)]:
print(f"\n== {name}: pairs with CIEDE2000 < 20 under any vision (flag), worst first")
rows = []
for a, b in itertools.combinations(P, 2):
ds = {k: de(sim(rgb(P[a]), k), sim(rgb(P[b]), k)) for k in ["normal", "protan", "deutan", "tritan"]}
rows.append((min(ds.values()), a, b, ds))
for m, a, b, ds in sorted(rows):
if m < 20: print(f" {a:6} vs {b:6} " + " ".join(f"{k} {v:5.1f}" for k, v in ds.items()))
print(" contrast vs backgrounds:")
for c in P:
print(f" {c:6} " + " ".join(f"{bg} {contrast(rgb(P[c]), rgb(h)):.1f}" for bg, h in BG.items() if (bg.startswith('map') if P is MAP else bg.startswith('ui'))))
+72
View File
@@ -0,0 +1,72 @@
// QA crawl: every tab, text dump, links, buttons, console errors. node crawl.js <outdir>
const { chromium } = require("playwright");
const fs = require("fs");
// screenshots and logs go to the folder given, or a temp folder (never a folder named "undefined" in the repo)
const OUT = process.argv[2] || require("path").join(require("os").tmpdir(), "atlas-qa");
require("fs").mkdirSync(OUT, { recursive: true });
const BASE = "http://localhost:8765/";
(async () => {
const b = await chromium.launch();
const log = { errors: [], links: [], buttons: [], tabs: {} };
for (const [vpName, vp] of [["desktop", { width: 1440, height: 1000 }], ["phone", { width: 390, height: 844 }]]) {
const p = await b.newPage({ viewport: vp });
p.on("pageerror", (e) => log.errors.push(`${vpName} pageerror: ${e.message}`));
p.on("console", (m) => { if (m.type() === "error" && !/net::ERR|Failed to load resource/.test(m.text())) log.errors.push(`${vpName} console: ${m.text()}`); });
for (const t of ["valley", "odds", "dragons", "deep", "data"]) {
await p.goto(BASE + "#" + t); await p.waitForTimeout(t === "valley" ? 2500 : 1800);
// open every <details> so hidden text is reviewed too
await p.$$eval(`#panel-${t} details`, (ds) => ds.forEach((d) => (d.open = true)));
await p.waitForTimeout(300);
await p.screenshot({ path: `${OUT}/${vpName}-${t}.png`, fullPage: true });
if (vpName === "desktop") {
log.tabs[t] = await p.evaluate((t) => document.querySelector("#panel-" + t).innerText, t);
const links = await p.$$eval(`#panel-${t} a[href], header a[href], footer a[href]`, (as) => as.map((a) => ({ text: a.innerText.trim().slice(0, 60), href: a.getAttribute("href") })));
links.forEach((l) => log.links.push({ tab: t, ...l }));
const btns = await p.$$eval(`#panel-${t} button`, (bs) => bs.map((x) => x.innerText.trim().replace(/\s+/g, " ").slice(0, 50)));
log.buttons.push({ tab: t, n: btns.length, sample: [...new Set(btns)].slice(0, 40) });
}
// overflow check
const sw = await p.evaluate(() => document.documentElement.scrollWidth);
if (sw > vp.width + 1) log.errors.push(`${vpName} ${t}: horizontal overflow ${sw}px`);
}
await p.close();
}
// click every button in every tab (desktop), checking for errors after each
const p = await b.newPage({ viewport: { width: 1440, height: 1000 } });
p.on("pageerror", (e) => log.errors.push(`click pageerror: ${e.message}`));
for (const t of ["valley", "odds", "dragons", "deep", "data"]) {
await p.goto(BASE + "#" + t); await p.waitForTimeout(2000);
const n = await p.$$eval(`#panel-${t} button`, (bs) => bs.length);
let clicked = 0;
for (let i = 0; i < Math.min(n, 120); i++) {
const bs = await p.$$(`#panel-${t} button`);
if (!bs[i]) continue;
const vis = await bs[i].isVisible();
if (!vis) continue;
const label = (await bs[i].innerText()).trim().slice(0, 40);
if (/download|copy/i.test(label)) continue;
try { await bs[i].click({ timeout: 1500 }); clicked++; await p.waitForTimeout(120); } catch (e) { log.errors.push(`${t}: could not click "${label}": ${e.message.split("\n")[0]}`); }
const cur = await p.evaluate(() => location.hash);
if (!cur.startsWith("#" + t)) { await p.goto(BASE + "#" + t); await p.waitForTimeout(1200); }
}
log.tabs[t + "_clicked"] = clicked;
}
// in-page links
await p.goto(BASE); await p.waitForTimeout(2000);
for (const l of log.links.filter((x) => x.href.startsWith("#"))) {
await p.goto(BASE + "#" + l.tab); await p.waitForTimeout(800);
const el = await p.$(`#panel-${l.tab} a[href="${l.href}"]`);
if (!el || !(await el.isVisible())) continue;
await el.click(); await p.waitForTimeout(800);
const sel = await p.evaluate(() => document.querySelector("[role=tab][aria-selected=true]").id);
const target = l.href.slice(1).split("/")[0];
const exists = await p.evaluate((id) => !!document.getElementById(id) || ["valley","odds","dragons","deep","data"].includes(id), target);
l.result = `${sel}${exists ? "" : " MISSING TARGET"}`;
}
fs.writeFileSync(`${OUT}/log.json`, JSON.stringify(log, null, 1));
for (const [t, txt] of Object.entries(log.tabs)) if (typeof txt === "string") fs.writeFileSync(`${OUT}/text-${t}.txt`, txt);
console.log("errors:", log.errors.length, log.errors.slice(0, 20));
console.log("clicked:", Object.entries(log.tabs).filter(([k]) => k.endsWith("_clicked")));
console.log("links:"); log.links.forEach((l) => console.log(" ", l.tab, "|", l.text, "|", l.href, "|", l.result || ""));
await b.close();
})();
+44
View File
@@ -0,0 +1,44 @@
// Valley map QA: for idle and every dragon/route, find text or labels that overlap, fall outside the map, or are too faint.
const { chromium } = require("playwright");
// screenshots and logs go to the folder given, or a temp folder (never a folder named "undefined" in the repo)
const OUT = process.argv[2] || require("path").join(require("os").tmpdir(), "atlas-qa");
require("fs").mkdirSync(OUT, { recursive: true });
(async () => {
const b = await chromium.launch();
const p = await b.newPage({ viewport: { width: 1440, height: 1000 } });
const states = [["idle", "#valley"]];
for (const c of ["red", "orange", "brown", "green", "blue", "black"]) states.push([c, "#valley/" + c]);
const extra = { blue: ["shadow-Blue"], red: ["tree-Red"], orange: ["tree-Greens"], brown: ["tree-Greens"] };
for (const id of (process.env.POINTS || "dir:Center,comp:Alone,scream,bully,wounded,hour,tree,valley,stream,meadow").split(",")) states.push(["at-" + id, "#valley/at/" + encodeURIComponent(id)]);
for (const [c, encs] of Object.entries(extra)) encs.forEach((e) => states.push([c + "/" + e, `#valley/${c}/${e}`]));
for (const [name, hash] of states) {
await p.goto("http://localhost:8765/" + hash); await p.waitForTimeout(1800);
const res = await p.evaluate(() => {
const svg = document.querySelector("#ex-map"), S = svg.getBoundingClientRect();
const items = [];
svg.querySelectorAll("text").forEach((t) => {
const r = t.getBoundingClientRect();
if (!r.width) return;
// walk up for opacity
let op = 1; for (let e = t; e && e !== svg; e = e.parentElement) op *= parseFloat(getComputedStyle(e).opacity || 1) * parseFloat(e.getAttribute("fill-opacity") || 1);
items.push({ kind: "text", txt: t.textContent.trim(), r: { l: r.left, t: r.top, rr: r.right, b: r.bottom }, op });
});
const out = [], over = [];
items.forEach((a) => { if (a.r.l < S.left - 1 || a.r.rr > S.right + 1 || a.r.t < S.top - 1 || a.r.b > S.bottom + 1) out.push(a.txt); });
for (let i = 0; i < items.length; i++) for (let j = i + 1; j < items.length; j++) {
const A = items[i].r, B = items[j].r;
const ix = Math.min(A.rr, B.rr) - Math.max(A.l, B.l), iy = Math.min(A.b, B.b) - Math.max(A.t, B.t);
if (ix > 3 && iy > 3 && items[i].txt !== items[j].txt) over.push(`"${items[i].txt}" × "${items[j].txt}"`);
}
const dragons = [...svg.querySelectorAll(".ex-dragon")].map((d) => ({ l: d.getAttribute("aria-label") || "twin", op: +d.getAttribute("opacity") })).filter((d) => d.op < 0.3);
const card = document.querySelector(".ex-route-card.on") || (document.querySelector(".ex-from") && document.querySelector(".ex-from"));
return { out, over, faint: dragons.map((d) => `${d.l.split(".")[0]} ${d.op}`), focus: card ? card.innerText.replace(/\s+/g, " ").slice(0, 160) : "" };
});
console.log(`\n[${name}] ${res.focus}`);
if (res.out.length) console.log(" outside:", res.out.join(" | "));
if (res.over.length) console.log(" overlaps:", [...new Set(res.over)].join(" | "));
if (res.faint.length) console.log(" faint (<0.3):", res.faint.join(" | "));
await p.locator("#ex-map").screenshot({ path: `${OUT}/map-${name.replace(/[/:]/g, "_")}.png` });
}
await b.close();
})();