[PRISM] Add model card coverage API
This commit is contained in:
1 parent
b9f54904a4
commit
23cc549199
1 file changed
+35
@@ -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":
|
||||
|
||||
Reference in new issue
Block a user