from apps.editor.models import Project
from apps.editor.views import _get_project_active_transcript

p = Project.objects.get(pk=8)
src = p.ai_suggestions.filter(is_active=True).order_by("-updated_at", "-created_at").first()
alts = (src.structured_response or {}).get("alternatives") or []
tr = _get_project_active_transcript(p)
words_by_id = {int(w.id): w for w in tr.words.all()}

TARGETS = {30, 29, 23, 22, 20, 18, 16, 14, 13}

print(f"Total: {len(alts)}\n")
for i, a in enumerate(alts, 1):
    if i not in TARGETS:
        continue
    name = (a.get("sequence_name") or a.get("topic_label") or "?")
    sm = int(a.get("start_ms") or 0)
    em = int(a.get("end_ms") or 0)
    dur = (em - sm) / 1000
    desc = a.get("conversation_summary") or a.get("editorial_rationale") or a.get("candidate_source_detail") or ""
    wids = [int(w) for w in (a.get("word_ids") or []) if int(w) in words_by_id]
    text_words = [getattr(words_by_id[wid], "text", "") for wid in wids]
    excerpt = " ".join(text_words)
    print(f"=== #{i} [{sm/1000:.0f}-{em/1000:.0f}s dur={dur:.0f}s] ===")
    print(f"NAME: {name}")
    print(f"DESC: {desc[:300]}")
    print(f"TEXT ({len(text_words)} words): {excerpt[:1200]}")
    print()
