import json
from pathlib import Path
CP = Path("/Users/manta/Documents/Projects/TheRoad-I1/projects/b0ad5c18-5140-4022-a2b0-805de0e5a385/checkpoints/episodes/0d30302a-51c8-4ac9-98e2-6cd9180512bf")

# 1) entity_relation에서 L03/L04/L10 관련 관계
try:
    rel = json.loads((CP / "entity_relation" / "manifest.json").read_text())["data"]
    rels = rel.get("relations") or rel.get("relation_facts") or []
    for r in rels:
        s = json.dumps(r, ensure_ascii=False)
        if any(k in s for k in ("L03", "L04", "L10")):
            print("[rel]", s[:200])
except Exception as e:
    print("entity_relation:", e)

# 2) dwelling_zone_map 구조
try:
    dz = json.loads((CP / "dwelling_zone_map" / "manifest.json").read_text())["data"]
    print("\n[dwelling_zone_map keys]", list(dz.keys())[:8])
    s = json.dumps(dz, ensure_ascii=False)
    for sid in ("L03", "L04", "L10"):
        print(f"  contains {sid}:", sid in s)
except Exception as e:
    print("dwelling_zone_map:", e)

# 3) background_classify building_groups — 같은 building에 묶였는지
try:
    bc = json.loads((CP / "background_classify" / "manifest.json").read_text())["data"]
    for bg in bc.get("building_groups") or []:
        locs = [(m.get("loc_id"), m.get("is_indoor")) for m in bg.get("members") or []]
        if any(l in ("L03", "L04", "L10") for l, _ in locs):
            print("\n[building_group]", bg.get("group_id"), locs)
except Exception as e:
    print("background_classify:", e)

# 4) background_render 그룹에서 S11 shot의 bg
try:
    br = json.loads((CP / "background_render" / "manifest.json").read_text())["data"]
    for bg_id, gr in (br.get("groups") or {}).items():
        sids = gr.get("shot_ids") or []
        if any("S11_" in str(x) or "S4_" in str(x) for x in sids):
            print("\n[bg group]", bg_id, "loc=", gr.get("location_id"), sids)
except Exception as e:
    print("background_render:", e)
