File size: 2,106 Bytes
7a87926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
import json
from pathlib import Path

from ylff.services.scene_catalog import (
    build_scene_catalog,
    validate_scene_catalog,
    write_scene_catalog_jsonl,
)


def test_scene_catalog_normalizes_common_manifest_variants(tmp_path: Path):
    p = tmp_path / "capture_x"
    p.mkdir()
    (p / "manifest.json").write_text(
        json.dumps(
            {
                # camelCase + alternative keys
                "schemaVersion": "1.0",
                "captureId": "cap_x",
                "regime": "indoor_constrained",
                "difficultyFlags": "mirror, glass",
                # devices as dict
                "devices": {
                    "iphone_a": {
                        "deviceType": "iphone",
                        "video_path": "devices/iphone_a/video.mov",
                        "intrinsics_path": "devices/iphone_a/intrinsics.json",
                        "timestamps_path": "devices/iphone_a/timestamps.json",
                    }
                },
            }
        )
    )

    cat = build_scene_catalog([str(p / "manifest.json")])
    assert cat.summary["num_scenes"] == 1
    sc = cat.scenes[0]
    assert sc.capture_id == "cap_x"
    assert sc.operating_regime == "indoor_constrained"
    assert set(sc.difficulty_flags) == {"mirror", "glass"}
    assert sc.num_devices == 1


def test_scene_catalog_can_write_jsonl_and_report(tmp_path: Path):
    b1 = tmp_path / "capture_a"
    b1.mkdir()
    (b1 / "manifest.json").write_text(
        json.dumps({"schema_version": "1.0", "capture_id": "cap_a", "devices": []})
    )

    cat = build_scene_catalog([str(b1 / "manifest.json")])
    out_jsonl = tmp_path / "catalog.jsonl"
    write_scene_catalog_jsonl(cat, out_jsonl)
    txt = out_jsonl.read_text().strip().splitlines()
    assert len(txt) == 1
    obj = json.loads(txt[0])
    assert obj["capture_id"] == "cap_a"

    report = validate_scene_catalog(cat)
    assert report["num_scenes"] == 1
    assert report["no_devices"] == 1

    report = validate_scene_catalog(cat)
    assert report["num_scenes"] == 1
    assert report["no_devices"] == 1