diff --git a/ops/work/tools/build_catalog.py b/ops/work/tools/build_catalog.py index feab102..94c44f0 100644 --- a/ops/work/tools/build_catalog.py +++ b/ops/work/tools/build_catalog.py @@ -33,7 +33,16 @@ ROLE_RULES = [ # ROLE_RULES2 ] +ROLE_OVERRIDE = { + "roomcast": "sharing_or_hub", + "roomcast e2": "sharing_or_hub", + "roomcast-e2": "sharing_or_hub", +} + + def role_of(name): + if str(name).strip().lower() in ROLE_OVERRIDE: + return ROLE_OVERRIDE[str(name).strip().lower()] for pat, role in ROLE_RULES: if re.match(pat, name, re.I): return role diff --git a/ops/work/web/combine_core.py b/ops/work/web/combine_core.py index 0cf660d..2621074 100644 --- a/ops/work/web/combine_core.py +++ b/ops/work/web/combine_core.py @@ -184,6 +184,16 @@ class Core: return {"items": x.get("items") or [], "kits": [], "source": "auto"} return {"items": [], "kits": [], "source": None} + # ── крепление уже в комплекте? ── + def mount_included(self, name): + pkg = self.package(name) + for it in pkg.get("items") or []: + low = str(it).lower() + if any(w in low for w in ("кронштейн", "крепёж", "крепеж", "bracket", + "mount", "стойк")): + return True + return False + # ── полнота данных ── def completeness(self, host_key): hk = norm(host_key) @@ -203,6 +213,94 @@ class Core: level, note = "none", "связей нет" return {"level": level, "note": note, "edges": total, "sources": srcs} + # ── авто-сборка по выбору пользователя ── + def autofill(self, host_key, seats=8, include=None, need=None): + """include: ['camera','panel','display','mount','sharing','mic']""" + include = set(include or ["mic", "camera", "panel", "display", "sharing"]) + need = list(need or []) + hk = norm(host_key) + if hk not in self.devices: + return {"error": "хост не найден"} + host = self.devices[hk]["name"] + need_m = 3 if seats <= 6 else 6 if seats <= 12 else 8 if seats <= 16 else 10 + items, notes = [], [] + + def by_role(role): + return [e for e in self.edges_of(hk) + if self.devices.get(norm(e["to"]), {}).get("role") == role] + + items.append({"model": host, "qty": 1, "role": "Хост", "why": "основа"}) + + # микрофоны + if "mic" in include: + built = self.attrs.get(hk, {}).get("audio.pickup_m") + if built and built >= need_m: + notes.append("встроенный микрофон покрывает %s м (нужно %s м)" + % (built, need_m)) + else: + cands = sorted(((self.attrs.get(norm(e["to"]), {}).get("audio.pickup_m") or 0, e) + for e in by_role("audio")), key=lambda x: -x[0]) + if cands: + p, e = cands[0] + qty = max(1, -(-need_m // max(int(p), 1))) if p else 1 + items.append({"model": e["to"], "qty": qty, "role": "Микрофон", + "why": "нужно %s м, у %s %s м" % (need_m, e["to"], p or "—")}) + + if "camera" in include: + cams = by_role("camera") + if cams: + def sc(e): + a = self.attrs.get(norm(e["to"]), {}) + z = (a.get("camera.zoom_optical") or 0) + (a.get("camera.zoom_hybrid") or 0) + c = 1 if "content camera" in (e.get("condition") or "").lower() else 0 + return z - c * 100 + cams.sort(key=sc, reverse=True) + items.append({"model": cams[0]["to"], "qty": 1, "role": "Камера", + "why": "совместима"}) + + if "panel" in include: + p = by_role("touch") + if p: + items.append({"model": p[0]["to"], "qty": 1, "role": "Панель", "why": "совместима"}) + + if "sharing" in include: + sh = [e for e in by_role("sharing_or_hub") + if re.match(r"^WPP", e["to"], re.I) or re.match(r"^VCH", e["to"], re.I)] + if sh: + items.append({"model": sh[0]["to"], "qty": 1, "role": "Презентация", + "why": "совместима"}) + + if "display" in include: + d = by_role("display") + if d: + items.append({"model": d[0]["to"], "qty": 1, "role": "Дисплей", "why": "совместим"}) + else: + notes.append("у Yealink нет дисплея для этого хоста — нужен внешний ТВ") + + if "mount" in include: + mnts = self.mounts_map.get(hk) or [] + chosen = None + for m in mnts: + if not self.mount_included(m): + chosen = m + break + if chosen: + items.append({"model": chosen, "qty": 1, "role": "Кронштейн", + "why": "совместим, не входит в комплект"}) + elif mnts: + notes.append("все совместимые крепления уже входят в комплект") + else: + notes.append("совместимых креплений нет") + + if any(norm(x) == "dante" for x in need): + notes.append("требуется Dante — добавьте комплект CM50+CS10-D+AP08") + + cap = self.capacity(hk, [[i["model"], i["qty"]] for i in items + if not i["model"].startswith("встроенный")]) + return {"host": host, "seats": seats, "need_pickup": need_m, + "items": items, "notes": notes, "capacity": cap, + "completeness": self.completeness(hk)} + # ── совместимость ── def edges_of(self, host_key, supported_only=True): out = [] diff --git a/ops/work/web/services/svc_engine.py b/ops/work/web/services/svc_engine.py index f1730e8..3b7d09e 100644 --- a/ops/work/web/services/svc_engine.py +++ b/ops/work/web/services/svc_engine.py @@ -163,20 +163,33 @@ def bom(q, body): "cables": C.cable_schedule(hk, items)} -def autofill(q, body): - """Guided default: собрать состав по комнате автоматически.""" - res = bom(q, body) - if res.get("error"): - return res - items = [] - for b in res["bom"]: - if b["model"].startswith(("встроенный", "внешний")): +def accessory_hosts(q, body): + """Обратный взгляд: какой аксессуар поддерживают какие хосты.""" + ak = cc.norm((q.get("device") or [""])[0]) + name = C.devices.get(ak, {}).get("name") or (q.get("device") or [""])[0] + hosts = [] + for hk, edges in C.edges.items(): + if C.devices.get(hk, {}).get("role") != "codec": continue - items.append({"model": b["model"], "qty": b["qty"], "role": b["role"], - "why": b.get("why")}) - return {"host": res["host"], "seats": res["seats"], - "items": items, "warnings": res["warnings"], - "capacity": res["capacity"], "completeness": C.completeness(cc.norm(res["host"]))} + for e in edges: + if cc.norm(e["to"]) != ak: + continue + if not e.get("supported") or not e.get("usable", True): + continue + hosts.append({"host": C.devices[hk]["name"], "max_qty": e.get("max_qty"), + "condition": (e.get("condition") or "").strip()[:120]}) + break + return {"device": name, "hosts": sorted(hosts, key=lambda x: x["host"]), + "count": len(hosts)} + + +def autofill(q, body): + """Guided default: собрать состав по выбору пользователя.""" + host = (q.get("host") or [""])[0] + seats = int((q.get("seats") or ["8"])[0]) + include = [x for x in (q.get("include") or []) if x] + need = [x for x in (q.get("need") or []) if x] + return C.autofill(host, seats, include or None, need) def checklist(q, body): @@ -279,6 +292,7 @@ serve({ "/cables": cables, "/bom": bom, "/autofill": autofill, + "/accessory": accessory_hosts, "/checklist": checklist, "/xlsx": xlsx, }, int(sys.argv[1]) if len(sys.argv) > 1 else 8102, "engine") diff --git a/ops/work/web/webui.html b/ops/work/web/webui.html index 9972a35..37543b7 100644 --- a/ops/work/web/webui.html +++ b/ops/work/web/webui.html @@ -83,7 +83,16 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord