File size: 1,958 Bytes
116e377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
"""Build and validate the unified 12-control DynPose and SpatialVID sets."""

from __future__ import annotations

import json
import subprocess
from datetime import datetime, timezone
from pathlib import Path


ROOT = Path(__file__).resolve().parent
STATUS = ROOT / "camera_controls_build_status.json"
LOG = ROOT / "camera_controls_build.log"
BUILDERS = (
    ROOT / "spatialvid_eval/build_camera_controls.py",
    ROOT / "dynpose_eval/build_camera_controls.py",
)


def now() -> str:
    return datetime.now(timezone.utc).isoformat()


def write_status(payload: dict) -> None:
    STATUS.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")


def main() -> None:
    report: dict[str, object] = {"status": "running", "started_at": now(), "datasets": {}}
    write_status(report)
    with LOG.open("w", encoding="utf-8") as log:
        for builder in BUILDERS:
            dataset = builder.parent.name
            process = subprocess.run(
                ["/opt/conda/bin/python", str(builder)],
                cwd=builder.parent,
                text=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
            )
            log.write(f"===== {dataset} =====\n{process.stdout}\n")
            log.flush()
            item: dict[str, object] = {"returncode": process.returncode}
            try:
                item["validation"] = json.loads(process.stdout)
            except json.JSONDecodeError:
                item["output_tail"] = process.stdout[-4000:]
            report["datasets"][dataset] = item  # type: ignore[index]
            if process.returncode:
                report.update({"status": "failed", "finished_at": now()})
                write_status(report)
                raise SystemExit(process.returncode)
    report.update({"status": "complete", "finished_at": now()})
    write_status(report)
    print(json.dumps(report, indent=2))


if __name__ == "__main__":
    main()