#!/usr/bin/env python3
"""content_map(_dense) DO-ZERO a partir de moments.json (search_media/SigLIP na timeline ATUAL).
Substitui os frozen frame-keyed do timeline velho. Uso: gen_content_map.py"""
import json

M = json.load(open("moments.json"))
dense, cmap = [], []
for key, hits in M.items():
    for h in hits:
        if h.get("cam", "?") == "?":
            continue
        f = int(round(h["t"] * 30))
        dense.append({"f": f, "cam": h["cam"], "score": h["score"], "key": key})
        cmap.append({"class": key, "cam": h["cam"], "f": f, "score": h["score"]})
dense.sort(key=lambda x: x["f"]); cmap.sort(key=lambda x: x["f"])
json.dump(dense, open("content_map_dense.json", "w"))
json.dump(cmap, open("content_map.json", "w"))
from collections import Counter
print(f"content_map_dense: {len(dense)} hits {dict(Counter(h['cam'] for h in dense))}")
