From 30705730e482bf00b7d2cb34b6e5cb1782730a39 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Fri, 6 Nov 2026 16:19:16 +0300 Subject: [PATCH] =?UTF-8?q?[WORK]=20=D0=9E=D0=BA=D0=BE=D0=BB=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D1=85=D0=BE=D0=B4=D0=BA=D0=B0:=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D1=91=D0=BC=D0=BA=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D0=BB=D0=B0=D0=B3=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D1=8B=20(VCH-=D1=85?= =?UTF-8?q?=D0=B0=D0=B1,=20=D0=B1=D0=B5=D1=81=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=BD=D1=8B=D0=B5=20=D0=BC=D0=B8=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D1=84=D0=BE=D0=BD=D1=8B,=20=D1=81=D0=BE=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B5)=20=D1=81=20=D0=BA=D0=BD=D0=BE?= =?UTF-8?q?=D0=BF=D0=BA=D0=BE=D0=B9=20=C2=AB=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/work/web/app.py | 81 +++++++++++++++++++++++++++++++++++++++++ ops/work/web/index.html | 19 +++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/ops/work/web/app.py b/ops/work/web/app.py index 8959240..c4d9344 100644 --- a/ops/work/web/app.py +++ b/ops/work/web/app.py @@ -417,6 +417,85 @@ class Data: "package": pkg, "limits": lim}) return out + # ── предложения: как закрыть проблему ── + def suggest_fixes(self, host_key, items, issues, missing_power): + hk = norm(host_key) + ha = self.attrs.get(hk, {}) + vch_ports = ha.get("ports.vch") + qtys = {} + for row in items: + qtys[row[0]] = qtys.get(row[0], 0) + int(row[1]) + + def compat(role): + out = [] + for e in self.edges.get(hk, []): + if not e.get("supported") or not e.get("usable", True): + continue + if self.devices.get(norm(e["to"]), {}).get("role") != role: + continue + a = self.attrs.get(norm(e["to"]), {}) + out.append({"model": e["to"], "max_qty": e.get("max_qty"), + "vch": a.get("ports.vch"), "wifi": a.get("network.wifi"), + "poe": a.get("network.poe"), + "power_w": a.get("power.consumption_w")}) + return out + + variants = [] + need_vch = any("VCH" in i for i in issues) + + if need_vch: + # вариант 1: добавить хаб с VCH-портами + # hub_filter: только реальные VCH-хабы (VCH51/VCH51 Pro), не донглы + hubs = [] + for h in compat("sharing_or_hub"): + if not re.match(r"^VCH", h["model"], re.I): + iv = self.iface_map.get(norm(h["model"])) or {} + if "VCH" not in (iv.get("in") or []) + (iv.get("out") or []): + continue + hubs.append(h) + for h in hubs[:3]: + variants.append({ + "title": "Добавить %s" % h["model"], + "why": "даёт %s VCH-порт(а) для цепочки" % (h["vch"] or 1), + "add": [[h["model"], 1]], + "kind": "hub"}) + if not hubs: + for h in compat("sharing_or_hub")[:2]: + variants.append({ + "title": "Добавить %s" % h["model"], + "why": "расширяет подключение (VCH-порты не указаны в данных — проверить)", + "add": [[h["model"], 1]], "kind": "hub_unknown"}) + # вариант 2: беспроводные микрофоны + wifi = [a for a in compat("audio") if a.get("wifi")] + for a in wifi[:2]: + variants.append({ + "title": "Заменить проводные на %s" % a["model"], + "why": "беспроводной микрофон — не занимает VCH-порт", + "replace_role": "audio", "add": [[a["model"], 1]], + "kind": "wireless"}) + # вариант 3: уменьшить количество + variants.append({ + "title": "Сократить количество на VCH", + "why": "у хоста %s VCH-порт(а) — распределить устройства или снизить число" + % (int(vch_ports) if vch_ports else "?"), + "kind": "reduce"}) + + if missing_power: + variants.append({ + "title": "Уточнить питание", + "why": "нет данных о потреблении: %s — запросить у вендора" + % ", ".join(missing_power[:5]), + "kind": "data"}) + + # PoE-бюджет: если есть устройства без PoE, но с питанием + no_poe = [m for m in qtys if not (self.attrs.get(norm(m), {}) or {}).get("network.poe")] + if no_poe: + variants.append({ + "title": "Проверить питание %s" % ", ".join(no_poe[:3]), + "why": "у этих устройств нет данных о PoE — возможно, нужен блок питания", + "kind": "data"}) + return variants + # ── проверка ёмкости хоста ── def capacity(self, host_key, items): """items: [[model, qty], ...]. Проверяет порты VCH, лимиты, питание.""" @@ -461,7 +540,9 @@ class Data: notes.append("суммарное потребление: %.1f Вт (по данным)" % total_w) if missing_w: notes.append("нет данных о потреблении: %s" % ", ".join(sorted(set(missing_w))[:8])) + suggestions = self.suggest_fixes(host_key, items, issues, sorted(set(missing_w))) return {"host": host, "vch_ports": vch_ports, "vch_users": vch_users, + "suggestions": suggestions, "total_power_w": round(total_w, 1), "missing_power": sorted(set(missing_w)), "issues": issues, "notes": notes} diff --git a/ops/work/web/index.html b/ops/work/web/index.html index 6445b30..f1e8d10 100644 --- a/ops/work/web/index.html +++ b/ops/work/web/index.html @@ -240,6 +240,14 @@ function renderSel(){
позиций ${ks.length} · единиц ${ks.reduce((a,k)=>a+SEL[k].qty,0)}
`; capacity(); } +async function addSuggestion(i){ + const sg=(window.LAST_SUGG||[])[i]; if(!sg||!sg.add) return; + sg.add.forEach(([model,qty])=>{ + const cur=SEL[model]||{qty:0,limit:99,role:'Предложение',cond:''}; + cur.qty=Math.max(cur.qty,0)+qty; SEL[model]=cur; + }); + renderSel(); +} async function capacity(){ const h=$('#host').value, ks=Object.keys(SEL); if(!ks.length)return; @@ -253,7 +261,16 @@ async function capacity(){ ${c.issues.length?`
✗ ${c.issues.join('
✗ ')}
`:'
✓ порты и лимиты в норме
'} ${c.notes.length?`
${c.notes.join('
')}
`:''} - ${c.missing_power.length?`
нет данных о питании: ${c.missing_power.join(', ')}
`:''}`; + ${c.missing_power.length?`
нет данных о питании: ${c.missing_power.join(', ')}
`:''} + ${(c.suggestions&&c.suggestions.length)?`
+
варианты решения:
+ ${c.suggestions.map((sg,i)=>`
+
+
${esc(sg.title)}
${esc(sg.why)}
+ ${(sg.add&&sg.add.length)?``:''} +
`).join('')} +
`:''}`; + window.LAST_SUGG = c.suggestions || []; } async function scheme(){