From 2b0067611980837d0371418c7886e867bf2cbef5 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Fri, 6 Nov 2026 18:11:10 +0300 Subject: [PATCH] =?UTF-8?q?[WORK]=20=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE-=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=20(=D1=87=D1=82=D0=BE=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D1=8C),=20=D0=BA=D1=80=D0=B5=D0=BF=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B5=20=D0=B4=D1=83=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D1=8E=D1=82=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=82,=20=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BF=D0=BE=20=D0=B0?= =?UTF-8?q?=D0=BA=D1=81=D0=B5=D1=81=D1=81=D1=83=D0=B0=D1=80=D1=83,=20Roomc?= =?UTF-8?q?ast=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=85=D0=BE=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/work/tools/build_catalog.py | 9 +++ ops/work/web/combine_core.py | 98 +++++++++++++++++++++++++++++ ops/work/web/services/svc_engine.py | 40 ++++++++---- ops/work/web/webui.html | 86 ++++++++++++++++++++++--- 4 files changed, 212 insertions(+), 21 deletions(-) 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
10
- +
+
авто-режим: что включить
+ + + + + + + +

Требования

загрузка…
@@ -128,8 +137,17 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord @@ -235,12 +253,21 @@ async function renderChecklist(){ } async function doAutofill(){ const h=$('#host').value; - const r=await J(`${SVC.engine}/autofill?host=${h}&seats=${$('#seats').value}`); + const inc=['mic','camera','panel','sharing','display','mount'] + .filter(k=>$('#inc-'+k).checked); + const need=[...NEED].map(n=>'need='+encodeURIComponent(n)).join('&'); + const incq=inc.map(k=>'include='+k).join('&'); + const r=await J(`${SVC.engine}/autofill?host=${h}&seats=${$('#seats').value}&${incq}&${need}`); if(r.error){alert(r.error);return;} SEL={}; - (r.items||[]).forEach(it=>{SEL[it.model]={qty:it.qty,limit:99,role:it.role};}); + (r.items||[]).forEach(it=>{ + if(it.role==='Хост')return; + SEL[it.model]={qty:it.qty,limit:99,role:it.role}; + }); renderSel(); - $('#projinfo').textContent='собрано автоматически: '+(r.items||[]).length+' позиций'; + const notes=(r.notes||[]); + $('#projinfo').innerHTML='собрано: '+Object.keys(SEL).length+' позиций' + +(notes.length?`
${notes.map(esc).join('; ')}
`:''); } async function renderCables(){ const ks=Object.keys(SEL); if(!ks.length){$('#cablesbox').innerHTML='соберите состав';return;} @@ -294,12 +321,53 @@ async function loadProject(id){ SEL={}; (p.items||[]).forEach(it=>{SEL[it.model]={qty:it.qty,limit:99,role:'из проекта'};}); await reload(); renderSel(); $('#projinfo').textContent='загружен: '+(p.name||id); } +async function hostDetail(key){ + const d=await J(`${SVC.catalog}/device?key=${key}`); + if(d.error){return;} + const accs=(d.attributes?[]:[]); + const g=await J(`${SVC.engine}/groups?host=${key}`); + const items=(g.groups||[]).filter(x=>x.items.length); + const comp=g.completeness||{}; + $('#mxdetail').innerHTML=`
+

${esc(d.name)} — совместимые аксессуары

+ ${comp.level!=='full'?`
⚠ ${esc(comp.note||'')}
`:''} + ${items.map(x=>`
${esc(x.name)} (${x.items.length}): + ${x.items.map(i=>`${esc(i.model)}${i.max_qty?' до '+i.max_qty:''}`).join('')}
`).join('')} +
`; + window.scrollTo({top:0,behavior:'smooth'}); +} +async function checkOne(host,model){ + const r=await J(`${SVC.engine}/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(model)}`); + const ok=r.supported&&r.usable!==false; + $('#onecheck').innerHTML=`
${esc(r.host||host)} + ${esc(r.device||model)} — ${esc(r.verdict||'')} + ${r.condition?`
${esc(r.condition).slice(0,120)}
`:''}
`; +} +async function accessoryHosts(){ + const dev=$('#chk-dev').value.trim(); + if(!dev||!MATRIX)return; + const r=await J(`${SVC.engine}/accessory?device=${encodeURIComponent(dev)}`); + if(!r.count){$('#chkres').innerHTML='ни один хост не поддерживает';return;} + $('#chkres').innerHTML=`${esc(r.device)}: ${r.hosts.map(h=>esc(h.host)).join(', ')}`; +} +async function checkPair(){ + const host=$('#chk-host').value, dev=$('#chk-dev').value.trim(); + if(!dev){return;} + const r=await J(`${SVC.engine}/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(dev)}`); + const ok=r.supported&&r.usable!==false; + $('#chkres').innerHTML=`${esc(r.verdict||'')}`; +} async function loadMatrix(){ if(!MATRIX)MATRIX=await J(SVC.catalog+'/matrix'); renderMatrix(); } function renderMatrix(){ if(!MATRIX)return; + if($('#chk-host').options.length===0){ + $('#chk-host').innerHTML=(MATRIX.hosts||[]).map(x=>``).join(''); + } + if($('#acc-list').children.length===0){ + $('#acc-list').innerHTML=(MATRIX.accessories||[]).map(a=>``).join(''); + } const f=($('#mq').value||'').toLowerCase(); const accs=MATRIX.accessories.filter(a=>a.toLowerCase().includes(f)); const rows=MATRIX.rows.filter(r=>r.host.toLowerCase().includes(f)); @@ -307,10 +375,12 @@ function renderMatrix(){ accs.forEach(a=>h+=`${esc(a).slice(0,24)}`); h+=''; rows.forEach(r=>{ - h+=`${esc(r.host)} + const rk=r.host.toLowerCase().replace(/[^a-z0-9]/g,''); + h+=` + ${esc(r.host)} ${(r.ports.in||[]).join(',')}${(r.ports.out||[]).join(',')}`; accs.forEach(a=>{const v=r.cells[a.toLowerCase().replace(/[^a-z0-9]/g,'')]; - h+=`${v?(v>1?v:'✓'):'·'}`;}); + h+=`${v?(v>1?v:'✓'):'·'}`;}); h+=''; }); $('#matrixbox').innerHTML=h+'';