from sqlalchemy import text
from backend.models.database import SessionLocal
db = SessionLocal()
print("=== MCI rows grouped by year_week ===")
for r in db.execute(text("""
    SELECT year_week, COUNT(*) AS n, SUM(quantity)::float AS qty
    FROM on_top_inputs WHERE buyer='MCI'
    GROUP BY year_week ORDER BY year_week
""")).mappings():
    print(f"  yw={r['year_week']}  rows={r['n']}  qty={r['qty']:,.0f}")
db.close()
