| """Shared paths and the Database FK resolver for the per-entity extract scripts. |
| |
| The raw data lives in a sibling Git repo (the recorder). This dataset has no |
| local source files; every extract script reads from `EXPORTS_DIR` and writes |
| to `DATA_DIR`. |
| """ |
| import json |
| from pathlib import Path |
|
|
| ROOT = Path(__file__).parent.parent |
| DATA_DIR = ROOT / "data" |
|
|
| |
| |
| |
| |
| AGENTIC_ROOT = ROOT.parent.parent.parent / "GitHub" / "Agentic-Additive-Manufacturing-Process-Optimization" |
| EXPORTS_DIR = AGENTIC_ROOT / "data" / "exports" |
|
|
| |
| DATABASE_ROOT = ROOT.parent / "Inova-Mk1-Database" |
| DATABASE_PROFILES_DIR = DATABASE_ROOT / "source" / "PrintProfiles" |
|
|
|
|
| def iter_jsonl(path: Path): |
| """Stream a JSONL file row-by-row. Skips blank lines.""" |
| with path.open(encoding="utf-8") as f: |
| for line in f: |
| line = line.strip() |
| if not line: |
| continue |
| yield json.loads(line) |
|
|
|
|
| def load_build_to_profile_name() -> dict[int, str]: |
| """Read upstream events.jsonl, return {build_id: printProfileName}. |
| |
| Uses the `build_start` event's `payload.printProfileName` field. Builds |
| that never logged a build_start event (the recorder joined mid-run) are |
| omitted from the map. |
| """ |
| events_path = EXPORTS_DIR / "events.jsonl" |
| out: dict[int, str] = {} |
| for ev in iter_jsonl(events_path): |
| if ev.get("kind") != "build_start": |
| continue |
| name = (ev.get("payload") or {}).get("printProfileName") |
| if name: |
| out[ev["build_id"]] = name |
| return out |
|
|
|
|
| def load_profile_name_to_id() -> dict[str, str]: |
| """Read Inova-Mk1-Database PrintProfile JSONs, return {Name: Id}. |
| |
| Matches on the in-app `Name` field exactly (slashes preserved); the |
| sibling event payload uses the same form (e.g. |
| "2026_05_30 20mJ/mm Formlabs PA12 GF"). |
| """ |
| out: dict[str, str] = {} |
| for p in DATABASE_PROFILES_DIR.glob("*.json"): |
| with p.open() as f: |
| blob = json.load(f) |
| if "Name" in blob and "Id" in blob: |
| out[blob["Name"]] = blob["Id"] |
| return out |
|
|
|
|
| def build_id_to_profile_id() -> dict[int, tuple[str | None, str | None]]: |
| """Compose: {build_id: (print_profile_id, print_profile_name)}. |
| |
| Unresolved profile_id (no Database match) is returned as None alongside |
| the still-useful name string. |
| """ |
| b2name = load_build_to_profile_name() |
| n2id = load_profile_name_to_id() |
| return { |
| bid: (n2id.get(name), name) |
| for bid, name in b2name.items() |
| } |
|
|