Download faisi/src/sandbox/prepare_windows.py from ppJustin/micro: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/datasets/ppJustin/micro/resolve/main/faisi/src/sandbox/prepare_windows.py
- Command line
-
hf download hf://datasets/ppJustin/micro/faisi/src/sandbox/prepare_windows.py
-
curl -L -o prepare_windows.py https://huggingface.co/datasets/ppJustin/micro/resolve/main/faisi/src/sandbox/prepare_windows.py
2.03 kB
| """Prepare the trusted observation-window index using W1-02 case adapters.""" | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| import sys | |
| import tempfile | |
| from .snapshot import DATASETS | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--w102-source", type=Path, required=True) | |
| parser.add_argument("--raw-root", type=Path, required=True) | |
| parser.add_argument("--snapshot-root", type=Path, required=True) | |
| parser.add_argument("--output", type=Path, required=True) | |
| args = parser.parse_args() | |
| # This trusted preparation step runs outside the query service. | |
| sys.path.insert(0, str(args.w102_source.resolve())) | |
| from adapters import normalize_pack, pack_batches, v1_batches | |
| windows = {} | |
| for dataset in DATASETS: | |
| raw = args.raw_root / dataset | |
| if not (raw / ".verified.json").is_file(): | |
| raise ValueError(f"missing integrity receipt for {dataset}") | |
| if dataset == "openrca_v1": | |
| groups = v1_batches(raw) | |
| else: | |
| groups = (normalize_pack(dataset, base, case_dir, meta) | |
| for case_dir, meta, base in pack_batches(raw, dataset)) | |
| profile = {case.case_id: [case.start, case.boundary, case.end] | |
| for group in groups for case in group.cases} | |
| available = {item.name for item in (args.snapshot_root / dataset).iterdir() if item.is_dir()} | |
| if profile.keys() != available: | |
| raise ValueError(f"observation inventory differs for {dataset}") | |
| windows[dataset] = profile | |
| print(f"{dataset}: {len(profile)} observation windows", flush=True) | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| with tempfile.NamedTemporaryFile(dir=args.output.parent, mode="w", delete=False) as stream: | |
| json.dump({"version": 1, "windows": windows}, stream, separators=(",", ":"), sort_keys=True) | |
| os.replace(stream.name, args.output) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |