From 23cc5491990b39bd85730e5397f4f80915a02c37 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Tue, 24 Nov 2026 12:14:52 +0300 Subject: [PATCH] [PRISM] Add model card coverage API --- ops/work/web/app.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ops/work/web/app.py b/ops/work/web/app.py index dc8dcd9..e28300c 100644 --- a/ops/work/web/app.py +++ b/ops/work/web/app.py @@ -1733,6 +1733,39 @@ def _prism_sql(sql): + +def prism_cards(only=None): + try: + cond = "" + if only in ("1", "2"): + cond = " and p.batch=%s" % int(only) + sql = ( + "select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from (" + "select m.id,m.vendor,m.name,m.role,m.domain,m.quality_status,m.review_status," + "p.batch," + "(select count(*) from prism.sources s where s.model_id=m.id) as sources," + "(select count(*) from prism.sources s where s.model_id=m.id and s.doc_type in ('product','datasheet')) as official," + "(select count(*) from prism.specs sp where sp.model_id=m.id) as specs," + "(select count(*) from prism.evidence ev where ev.model_id=m.id) as evidence," + "(select count(*) from prism.model_notes n where n.model_id=m.id) as notes," + "(select count(*) from prism.note_audits a where a.model_id=m.id) as audits," + "(select a.ok from prism.note_audits a where a.model_id=m.id order by a.id desc limit 1) as audit_ok," + "case " + " when m.quality_status <> 'product' then 'excluded' when m.review_status='needs_reextract' then 'needs_reextract'" + " when (select count(*) from prism.sources s where s.model_id=m.id and s.doc_type in ('product','datasheet')) = 0 then 'needs_source'" + " when (select count(*) from prism.specs sp where sp.model_id=m.id) < 5 then 'needs_reextract'" + " when (select count(*) from prism.model_notes n where n.model_id=m.id) < 3 then 'needs_content'" + " when (select count(*) from prism.note_audits a where a.model_id=m.id) = 0 then 'needs_audit' when (select a.ok from prism.note_audits a where a.model_id=m.id order by a.id desc limit 1) is not true then 'needs_audit'" + " else 'ready_review' end as card_status " + "from prism.models m left join prism.rerun_plan p on p.model_id=m.id " + "where m.quality_status='product'" + cond + + " order by p.batch,m.vendor,m.name) t" + ) + return _prism_sql(sql) + except Exception as e: + return {"ok": False, "error": str(e)[:200]} + + def prism_rerun(): try: sql = ( @@ -1819,6 +1852,8 @@ class H(BaseHTTPRequestHandler): return self._out(open(f, encoding="utf-8").read().encode(), ctype="text/html; charset=utf-8") if p in ("/health", "/api/health"): return self._out({"ok": True, "service": "combine-web", "devices": len(D.devices)}) + if p == "/api/prism/cards": + return self._out(prism_cards(q.get("batch", [""])[0])) if p == "/api/prism/rerun": return self._out(prism_rerun()) if p == "/api/prism/search":