import re, sys; sys.path.insert(0,"/app")
from app.database import SessionLocal
from sqlalchemy import text as sa_text
db = SessionLocal()
rows = db.execute(sa_text("""SELECT id, question_text, explanation FROM questions
                             WHERE image_path IS NOT NULL AND image_path <> ''""")).fetchall()
STEM = re.compile(r"figure|photograph|image|shown below|pictured", re.I)
variants = {
 "base": r"figure|photograph|image|shown below|pictured",
 "+shown": r"figure|photograph|image|shown|pictured",
 "+radiograph": r"figure|photograph|image|shown below|pictured|radiograph|x-ray",
 "+shown+rad": r"figure|photograph|image|shown|pictured|radiograph|x-ray|ecg|electrocardiogram",
 "+item C": r"figure|photograph|image|shown below|pictured|item c\d",
}
for lab, pat in variants.items():
    rx = re.compile(pat, re.I)
    n = sum(1 for _q,s,e in rows if rx.search(e or "") and not STEM.search(s or ""))
    print(f"{lab:14s} only-explanation = {n}")
