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(){