[WORK] Околорасходка: проверка ёмкости теперь предлагает варианты (VCH-хаб, беспроводные микрофоны, сокращение) с кнопкой «Добавить»

This commit is contained in:
root committed 2026-11-06 16:19:16 +03:00
1 parent 766dcbf1f9
commit 30705730e4
2 files changed
+99 -1

No files matched your search

+81
View File
@@ -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}
+18 -1
View File
@@ -240,6 +240,14 @@ function renderSel(){
<div class="muted" style="margin-top:6px">позиций ${ks.length} · единиц ${ks.reduce((a,k)=>a+SEL[k].qty,0)}</div>`;
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(){
</div>
${c.issues.length?`<div class="box bad">✗ ${c.issues.join('<br>✗ ')}</div>`:'<div class="box ok">✓ порты и лимиты в норме</div>'}
${c.notes.length?`<div class="muted" style="margin-top:6px">${c.notes.join('<br>')}</div>`:''}
${c.missing_power.length?`<div class="box">нет данных о питании: ${c.missing_power.join(', ')}</div>`:''}`;
${c.missing_power.length?`<div class="box">нет данных о питании: ${c.missing_power.join(', ')}</div>`:''}
${(c.suggestions&&c.suggestions.length)?`<div style="margin-top:10px">
<div class="muted" style="margin-bottom:6px">варианты решения:</div>
${c.suggestions.map((sg,i)=>`<div class="box" style="border-color:#2f81f7;background:#0d1b2e">
<div style="display:flex;justify-content:space-between;gap:8px;align-items:center">
<div><b>${esc(sg.title)}</b><div class="muted">${esc(sg.why)}</div></div>
${(sg.add&&sg.add.length)?`<button class="btn sm" onclick="addSuggestion(${i})">Добавить</button>`:''}
</div></div>`).join('')}
</div>`:''}`;
window.LAST_SUGG = c.suggestions || [];
}
async function scheme(){