#!/usr/bin/env python3
"""Final board: corrected core top 10, organic vs paid, vendor blackout, dormancy."""
import json, re
from datetime import datetime, timezone

RAW = "/home/kiro/trend-engine/trends/x/raw/"
d = json.load(open(RAW + "scan_results_2026-11-09_FULL.json"))
raw, q = d["raw"], d["qualifying"]
def pdt(s): return datetime.strptime(s, "%a %b %d %H:%M:%S %z %Y")
def sc(x): return x["likes"] + x["rt"]*2 + x["replies"]*3 + x["views"]/100
def rate(x): return x["likes"]/max(x["views"],1)*100
now = datetime.now(timezone.utc)

IRR = {"AIBuzzNews","AIGuideHQ","AITECHio","AIFrontliner","TheAIColony","AITOPIAai","GoogleLabs",
"GoogleAI","DonutAI","cladlabs","FaithJaiye2187","KammelaBala","MyStageAI","AlexStudio44",
"AI_with_jasmin","Ai_Vaidehi","ChrisLaubAI","CINEMA505","OpenAI","AnthropicAI","AIScottAdams",
"AISuperDomain","AI_Jasonyu","AIByLeo","Soaima_Ai","different_ai","via_ai_","Teamily_AI","AIsaOneHQ",
"AiWithTariq","EinsiaAI","AidenChaoyangHe","dai2noyuyuta","Lab_for_Men","Nevermined_ai","numerai","uns__nstudio"}
FILM = {"DiscussingFilm","nofilmschool"}
NONCORE = {"interesting_aIl","hubermanlab","NVIDIAAI"}

core = [x for x in q if x["handle"] not in IRR|FILM|NONCORE]
print(f"CORE BOARD: {len(core)} posts")
cs = sorted(core, key=sc, reverse=True)
print("\n=== TOP 12 CORE ===")
for i,x in enumerate(cs[:12],1):
    print(f"{i}. @{x['handle']} | {x['likes']}L {x['rt']}RT {x['replies']}R {x['views']}V | rate={rate(x):.3f}% | {x['date']}")
    print(f"   {x['text'][:150]}")
    print(f"   {x['url']}")
print(f"\ncutoff10={sc(cs[9]):.0f} rank11={sc(cs[10]):.0f} rank12={sc(cs[11]):.0f}")

paid = [x for x in cs if rate(x) < 0.25 and x["views"] >= 15000]
print(f"\nPAID-REACH (<0.25% like rate, >=15k views): {len(paid)} of {len(cs)}")
for x in paid: print(f"  @{x['handle']} {x['likes']}L/{x['views']}V {rate(x):.3f}% | {x['text'][:70]}")
print(f"ORGANIC: {len(cs)-len(paid)} of {len(cs)}")

print("\n=== VENDOR BLACKOUT (hours since newest ORIGINAL fetched) ===")
VEND = ["higgsfield","higgsfield_ai","runwayml","pika_labs","Flovaai","openart_ai","perplexity_ai",
        "AIWarper","openart_ai","Kling_ai","CharaspowerAI","EHuanglu","azed_ai","ElsaSofia__AI","heyglif","c_valenzuelab"]
for h in VEND:
    tw = [t for t in raw.get(h,[]) if not t.get("retweeted_tweet") and not t.get("isReply") and t.get("type")=="tweet"]
    if not tw: print(f"  @{h}: none"); continue
    mx = max(pdt(t["createdAt"]) for t in tw)
    print(f"  @{h:16s} newest_original={mx.strftime('%m-%d %H:%M')}  {(now-mx).total_seconds()/3600:6.1f}h ago")

print("\n=== TYPE SPLIT: what fraction of core is vendor news vs craft vs personal ===")
for h in sorted({x["handle"] for x in cs}):
    n = sum(1 for x in cs if x["handle"]==h)
    print(f"  @{h}: {n}")
