File size: 1,710 Bytes
71df3b8
884dabc
8cdbe7c
 
 
884dabc
 
 
 
 
 
 
8cdbe7c
884dabc
 
8cdbe7c
 
 
884dabc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Shared paths and helpers for the extract scripts.

The raw data lives in the recorder repo, which contains this dataset as a
submodule (`datasets/Inova-Mk1-Telemetry`). 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"

# Recorder-repo location. The Telemetry dataset has no local source/ tree;
# its raw inputs are the flat exports written by
# `Agentic-Additive-Manufacturing-Process-Optimization/scripts/export.py`.
# This repo is a submodule at `datasets/Inova-Mk1-Telemetry` inside the
# recorder repo → two climbs from ROOT reach the recorder root.
AGENTIC_ROOT = ROOT.parent.parent
EXPORTS_DIR = AGENTIC_ROOT / "data" / "exports"


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