import json,datetime,collections
UTC=datetime.timezone.utc
CARD={"claude-opus-5":(5,6.25,10,.5,25),"claude-opus-5-5":(4,5,8,.2,20),
      "claude-opus-4-8":(5,6.25,10,.5,25),"claude-opus-4-7":(5,6.25,10,.5,25),
      "claude-fable-5-1":(10,12.5,20,.25,50),"claude-fable-5":(10,12.5,20,1.0,50),
      "claude-sonnet-5":(2,2.5,4,.2,10),"claude-sonnet-4-6":(3,3.75,6,.3,15),
      "claude-haiku-4-5-20251001":(1,1.25,2,.1,5),"claude-haiku-4-5":(1,1.25,2,.1,5)}
recs=json.load(open("recs.json"))
for r in recs:
    r["dt"]=datetime.datetime.fromisoformat(r["dt"])
    c=CARD.get(r["model"])
    r["cost"]=0.0 if not c else (r["inp"]*c[0]+r["w5"]*c[1]+r["w1"]*c[2]+r["rd"]*c[3]+r["out"]*c[4])/1e6
RESET=datetime.datetime(2026,10,1,0,59,59,tzinfo=UTC)
print("windows aligned to the REPORTED reset boundary (Thu 00:59:59 UTC):\n")
print(f"{'window':34s} {'$ total':>10s} {'responses':>10s}   dominant model")
for k in range(9):
    e=RESET-datetime.timedelta(days=7*k); s=e-datetime.timedelta(days=7)
    sel=[r for r in recs if s<=r["dt"]<e]
    if not sel: continue
    t=sum(r["cost"] for r in sel)
    bm=collections.Counter()
    for r in sel: bm[r["model"]]+=r["cost"]
    top=bm.most_common(1)[0] if bm else ("-",0)
    tag=" <-- CURRENT (58% used)" if k==0 else ""
    print(f"{s:%Y-%m-%d} -> {e:%Y-%m-%d}   ${t:9,.2f} {len(sel):10,}   {top[0]} {100*top[1]/max(t,1e-9):.0f}%{tag}")
