# -*- coding: utf-8 -*-
"""直近のLLM評価結果を確認する: 送信した濃度別入力 と 返ってきた評価JSON。"""
import json, sqlite3, sys, os
sys.stdout.reconfigure(encoding="utf-8")

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
db = os.path.join(ROOT, "local_batch_api", "output_full", "ramen_soup_evaluations.sqlite3")
conn = sqlite3.connect(db)
rows = conn.execute(
    "SELECT input_video_path, request_json, assessment_json, error FROM evaluations ORDER BY id"
).fetchall()
print(f"DB total records: {len(rows)}\n")
for vpath, req, asj, err in rows:
    name = os.path.basename(vpath)
    a = json.loads(asj) if asj else None
    note = ""
    try:
        for c in json.loads(req).get("input", [{}])[0].get("content", []):
            if c.get("type") == "input_text":
                for line in c["text"].splitlines():
                    if "スープ濃度" in line:
                        note = line.strip()
    except Exception:
        pass
    print("=" * 70)
    print(f"{name}  err={err or 'none'}")
    if note:
        print(f"  sent density input: {note}")
    if a:
        print(f"  visual_density : {a.get('visual_density')}")
        print(f"  assessable     : {a.get('assessable')}  retake={a.get('retake_recommended')}")
        print(f"  water_level    : {a.get('water_level')}")
        print(f"  oil_emulsif.   : {a.get('oil_emulsification')}")
        print(f"  summary        : {str(a.get('summary'))[:80]}")
conn.close()
