[PRISM] Fix missing requirements/matrix-db functions
This commit is contained in:
1 parent
87cc382376
commit
c5c802ce6c
1 file changed
+48
@@ -2452,6 +2452,54 @@ def prism_model_card(mid):
|
||||
return row
|
||||
|
||||
|
||||
def prism_requirements(model):
|
||||
"""Requirements for a model, grouped for the Prism UI."""
|
||||
name = str(model or "").strip()
|
||||
if not name:
|
||||
return {"ok": False, "error": "model required", "groups": []}
|
||||
rows = _prism_sql(
|
||||
"select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from ("
|
||||
"select r.group_key, r.condition, r.max_qty, r.verified, a.name as option_name "
|
||||
"from prism.model_requirements r "
|
||||
"join prism.models m on m.id=r.model_id "
|
||||
"join prism.models a on a.id=r.requires_model_id "
|
||||
"where m.name=%s order by r.group_key,a.name) t" % _sqlq(name)
|
||||
) or []
|
||||
groups = {}
|
||||
for r in rows:
|
||||
key = r.get("group_key") or "other"
|
||||
g = groups.setdefault(key, {"group_key": key, "label": key, "options": []})
|
||||
g["options"].append({"name": r.get("option_name"), "max_qty": r.get("max_qty"),
|
||||
"verified": bool(r.get("verified")), "condition": r.get("condition")})
|
||||
return {"ok": True, "model": name, "groups": list(groups.values())}
|
||||
|
||||
|
||||
def prism_matrix_db(vendor=""):
|
||||
"""Host-to-device compatibility rows from prism.model_requirements."""
|
||||
vendor = str(vendor or "").strip()
|
||||
where = " and lower(m.vendor)=lower(%s)" % _sqlq(vendor) if vendor else ""
|
||||
rows = _prism_sql(
|
||||
"select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from ("
|
||||
"select m.name as host, m.vendor, a.name as device, r.group_key, "
|
||||
"r.condition, r.max_qty, r.verified "
|
||||
"from prism.model_requirements r "
|
||||
"join prism.models m on m.id=r.model_id "
|
||||
"join prism.models a on a.id=r.requires_model_id "
|
||||
"where 1=1%s order by m.name,a.name) t" % where
|
||||
) or []
|
||||
hosts = []
|
||||
by_host = {}
|
||||
for r in rows:
|
||||
h = r.get("host")
|
||||
if h not in by_host:
|
||||
hosts.append(h)
|
||||
by_host[h] = {"host": h, "vendor": r.get("vendor"), "items": []}
|
||||
by_host[h]["items"].append({"device": r.get("device"), "group_key": r.get("group_key"),
|
||||
"condition": r.get("condition"),
|
||||
"max_qty": r.get("max_qty"), "verified": bool(r.get("verified"))})
|
||||
return {"ok": True, "hosts": hosts, "rows": list(by_host.values())}
|
||||
|
||||
|
||||
def prism_group_models(group):
|
||||
rows = _prism_sql(
|
||||
"select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from ("
|
||||
|
||||
Reference in new issue
Block a user