[PRISM] fix matrix API (edges, check-db, vendors alias) and UI stats
This commit is contained in:
1 parent
c985c0617b
commit
71e5dfb228
3 files changed
+175
-13
No files matched your search
+28
-12
@@ -2475,18 +2475,22 @@ def prism_requirements(model):
|
||||
|
||||
|
||||
def prism_matrix_db(vendor=""):
|
||||
"""Curated host-to-device matrix from prism.edges (origin='legacy').
|
||||
"""Host-to-device compatibility matrix.
|
||||
|
||||
prism.model_requirements is an LLM draft queue (unverified, mixed with support
|
||||
articles and negative rows), so it must not be rendered as the compatibility
|
||||
matrix. The host list mirrors the curated YAML matrix (/api/matrix) so rows
|
||||
with no verified pairs stay visible instead of silently disappearing.
|
||||
Verified pairs come from prism.edges origin='legacy' (the curated 377-cell
|
||||
graph imported from matrix.yaml). Clean LLM edges are shown separately and
|
||||
marked verified=false; prism.model_requirements is a draft queue (negative
|
||||
and support-article rows) and is never rendered as the matrix.
|
||||
"""
|
||||
vendor = str(vendor or "").strip().lower()
|
||||
show_all = vendor in ("", "all")
|
||||
base = D.matrix()
|
||||
base_rows = {r.get("host"): r for r in (base.get("rows") or [])}
|
||||
base_vendor = str(D.cat.get("vendor") or "yealink").lower()
|
||||
junk = ("(faq|how |why |what |troubleshoot|firmware|specification|^pdf$|outlet|"
|
||||
"all products|designed for|bundle|gaming|mouse|keyboard|remote|"
|
||||
"operating distance|support|sync|software|install|driver|duplicate|"
|
||||
"grouping|primary image|^hp poly$|certified|program|products|headsets|ip phone)")
|
||||
where = ""
|
||||
if not show_all:
|
||||
where = " and lower(h.vendor)=lower(%s)" % _sqlq(vendor)
|
||||
@@ -2497,18 +2501,27 @@ def prism_matrix_db(vendor=""):
|
||||
"from prism.edges e "
|
||||
"join prism.models h on h.id=e.host_model_id "
|
||||
"join prism.models a on a.id=e.accessory_model_id "
|
||||
"where e.origin='legacy' and e.relation='compatible' "
|
||||
"where e.relation='compatible' "
|
||||
"and coalesce(h.quality_status,'product')='product' "
|
||||
"and coalesce(a.quality_status,'product')='product'%s "
|
||||
"and coalesce(a.quality_status,'product')='product' "
|
||||
"and (e.origin='legacy' or (e.origin='llm' "
|
||||
"and h.role in ('codec','pc','sharing_or_hub','bar','board','terminal','hub') "
|
||||
"and h.name !~* " + _sqlq(junk) + " and a.name !~* " + _sqlq(junk) + " "
|
||||
"and not exists (select 1 from prism.edges e2 "
|
||||
"where e2.origin='legacy' and e2.host_model_id=a.id)))%s "
|
||||
"order by h.name,a.name) t" % where
|
||||
) or []
|
||||
by_host = {}
|
||||
for r in rows:
|
||||
h = r.get("host")
|
||||
d = r.get("device")
|
||||
hn, dn = norm(h), norm(d)
|
||||
if (r.get("origin") or "legacy") == "llm" and hn and dn and (hn in dn or dn in hn):
|
||||
continue # same product family, not an accessory pair
|
||||
if h not in by_host:
|
||||
by_host[h] = {"host": h, "vendor": r.get("vendor"), "items": []}
|
||||
by_host[h]["items"].append({
|
||||
"device": r.get("device"), "group_key": "",
|
||||
"device": d, "group_key": "",
|
||||
"condition": r.get("condition"), "max_qty": r.get("max_qty"),
|
||||
"verified": bool(r.get("verified")), "origin": r.get("origin") or "legacy",
|
||||
})
|
||||
@@ -2523,22 +2536,25 @@ def prism_matrix_db(vendor=""):
|
||||
cells = dict(brow.get("cells") or {})
|
||||
out_rows.append({"host": name, "vendor": base_vendor, "items": items,
|
||||
"cells": cells, "ports": brow.get("ports") or {},
|
||||
"verified": bool(cells)})
|
||||
"verified": any(i["verified"] for i in items) or bool(cells)})
|
||||
seen = {r["host"] for r in out_rows}
|
||||
for name, hrow in by_host.items():
|
||||
if name in seen:
|
||||
continue
|
||||
cells = {norm(i["device"]): (i["max_qty"] or 1) for i in hrow["items"]}
|
||||
out_rows.append({"host": name, "vendor": hrow.get("vendor"), "items": hrow["items"],
|
||||
"cells": cells, "ports": {}, "verified": True})
|
||||
"cells": cells, "ports": {},
|
||||
"verified": any(i["verified"] for i in hrow["items"])})
|
||||
out_rows.sort(key=lambda r: r["host"])
|
||||
hosts = [r["host"] for r in out_rows]
|
||||
accessories = sorted({i["device"] for r in out_rows for i in r["items"]})
|
||||
cells_total = sum(len(r["cells"]) for r in out_rows)
|
||||
verified_cells = sum(1 for r in out_rows for i in r["items"] if i["verified"])
|
||||
return {"ok": True, "hosts": hosts, "rows": out_rows, "accessories": accessories,
|
||||
"source": "prism.edges origin=legacy (verified) + curated matrix.yaml hosts",
|
||||
"source": "prism.edges origin=legacy (verified) + filtered origin=llm",
|
||||
"stats": {"hosts": len(hosts), "cells": cells_total,
|
||||
"verified_cells": cells_total, "llm_cells": 0,
|
||||
"verified_cells": verified_cells,
|
||||
"llm_cells": cells_total - verified_cells,
|
||||
"junk_hosts": 0}}
|
||||
|
||||
|
||||
|
||||
@@ -483,7 +483,7 @@ async function loadMatrixHosts(vendor) {
|
||||
const hosts = (db.hosts||[]);
|
||||
const st = db.stats || {};
|
||||
const stats = $("#mxStats");
|
||||
if (stats) stats.textContent = hosts.length ? `${st.hosts||hosts.length} хостов · ${st.cells||0} проверенных пар` : "нет проверенной матрицы для этого вендора";
|
||||
if (stats) stats.textContent = hosts.length ? `${hosts.length} хостов · ${st.verified_cells||0} проверенных${st.llm_cells?` + ${st.llm_cells} LLM`:''}` : "нет проверенной матрицы для этого вендора";
|
||||
const sel = $("#mxHost");
|
||||
sel.innerHTML = hosts.map(h=>`<option value="${esc(h)}">${esc(h)}</option>`).join("") || '<option value="">нет проверенной матрицы</option>';
|
||||
await loadMatrixOptions();
|
||||
|
||||
Reference in new issue
Block a user