[WORK] Позиционный конструктор: места установки (стойка/стол/потолок/стена/периметр), проверка ёмкости VCH и питания, размеры комнаты

This commit is contained in:
root committed 2026-11-06 15:59:55 +03:00
1 parent af94614738
commit a08fb18d26
2 files changed
+322 -297

No files matched your search

+146
View File
@@ -145,6 +145,139 @@ class Data:
outs = list(dflt["out"]) or ["—"]
return ins, outs
# ── ПОЗИЦИОННЫЙ конструктор: места установки ──
POSITIONS = [
{"id": "rack", "name": "Стойка / шкаф",
"hint": "кодек, DSP, коммутатор",
"roles": ["sharing_or_hub", "power"]},
{"id": "table", "name": "Стол",
"hint": "настольные микрофоны, панели, докстанции",
"roles": ["audio", "touch", "remote"]},
{"id": "ceiling", "name": "Потолок",
"hint": "потолочные микрофоны и громкоговорители",
"roles": ["audio", "speaker", "sensor"]},
{"id": "wall", "name": "Стена / экран",
"hint": "камеры, дисплеи",
"roles": ["camera", "display"]},
{"id": "perimeter", "name": "Периметр",
"hint": "кронштейны и крепления",
"roles": ["mount", "headset"]},
]
# позиция по имени устройства (важнее роли: VCM38 — потолочный, хотя роль audio)
POSITION_RULES = [
(r"^VCM|^CM50|^CS10-D|^CLS120|^MSpeaker|^CS10\b", "ceiling"),
(r"^CM20|^CS10|^CP50|^CPE|^CP965|^CP\d|^CTP|^MTouch|^VCR|^MB-Remote|^PA\d", "table"),
(r"^UVC|^MB-CAM|^MB-12X|^SmartVision|MeetingDisplay|^ETV|^VCC", "wall"),
(r"^MCore|^VCH|^WPP|^AP0|^AVBridge|^AVHub|^BYOD|^YPS|^PVB|^PVT|MeetingEye|^A\d|^MeetingBoard|^MB-FS|^Roomcast", "rack"),
(r"[Mm]ount|Bracket|Stand|^MB-Tray|^MB-Wall|^MD-", "perimeter"),
]
def pos_of(self, name):
for pat, pos in self.POSITION_RULES:
if re.match(pat, str(name)):
return pos
return None
def positions(self, host_key, need=None):
"""Позиции комнаты: в каждой только совместимые с хостом устройства."""
need_n = {norm(x) for x in (need or [])}
hk = norm(host_key)
if hk not in self.devices:
return {"error": "хост не найден"}
host_role = self.devices[hk]["role"]
# у бара камера обычно встроенная — позицию камеры скрываем, если нет совместимых
out = []
for pos in self.POSITIONS:
items = []
for e in self.edges.get(hk, []):
t = e["to"]
r = self.devices.get(norm(t), {}).get("role")
if r not in pos["roles"]:
continue
# уточнение по позиции устройства
real_pos = self.pos_of(t)
if real_pos and real_pos != pos["id"]:
continue
if not e.get("supported") or not e.get("usable", True):
continue
a = self.attrs.get(norm(t), {})
f = {norm(x) for x in self.feats.get(norm(t), set())}
if need_n and not need_n <= f:
continue
items.append({
"model": t, "role": r,
"max_qty": e.get("max_qty"),
"condition": (e.get("condition") or "").strip()[:160],
"power_w": a.get("power.consumption_w"),
"pickup_m": a.get("audio.pickup_m"),
"zoom": a.get("camera.zoom_optical") or a.get("camera.zoom_hybrid"),
"ports_vch": a.get("ports.vch"),
})
if pos["id"] == "perimeter":
for m in self.mounts_map.get(hk, []):
items.append({"model": m, "role": "mount", "max_qty": 1,
"condition": "лист Mounts & Bracket",
"power_w": None, "pickup_m": None, "zoom": None,
"ports_vch": None})
uniq = {}
for i in items:
uniq.setdefault(i["model"], i)
items = sorted(uniq.values(), key=lambda x: x["model"])
out.append({"id": pos["id"], "name": pos["name"], "hint": pos["hint"],
"items": items})
return {"host": self.devices[hk]["name"], "host_role": host_role,
"positions": out}
# ── проверка ёмкости хоста ──
def capacity(self, host_key, items):
"""items: [[model, qty], ...]. Проверяет порты VCH, лимиты, питание."""
hk = norm(host_key)
if hk not in self.devices:
return {"error": "хост не найден"}
host = self.devices[hk]["name"]
ha = self.attrs.get(hk, {})
vch_ports = ha.get("ports.vch")
issues, notes = [], []
total_w, missing_w = 0.0, []
vch_users = 0
qtys = {}
for row in items:
model, qty = row[0], int(row[1])
qtys[model] = qtys.get(model, 0) + qty
# лимиты из матрицы
limits = {}
for e in self.edges.get(hk, []):
if e.get("supported"):
limits[norm(e["to"])] = (e.get("max_qty"), e["to"])
for model, q in qtys.items():
lim, name = limits.get(norm(model), (None, model))
if lim and q > lim:
issues.append("%s: %d шт при лимите %d" % (name, q, lim))
a = self.attrs.get(norm(model), {})
w = a.get("power.consumption_w")
if w:
total_w += w * q
else:
missing_w.append(model)
if a.get("audio.pickup_m") or a.get("ports.vch"):
vch_users += q
if vch_ports is not None and vch_users > 0:
notes.append("портов VCH у хоста: %s · устройств на VCH: %d"
% (int(vch_ports), vch_users))
if vch_users > vch_ports:
issues.append(
"VCH: %d устройств на %s порт(а) — требуется цепочка/расширитель; "
"ёмкость цепочки в данных отсутствует — ПРОВЕРИТЬ У ВЕНДОРА"
% (vch_users, int(vch_ports)))
notes.append("суммарное потребление: %.1f Вт (по данным)" % total_w)
if missing_w:
notes.append("нет данных о потреблении: %s" % ", ".join(sorted(set(missing_w))[:8]))
return {"host": host, "vch_ports": vch_ports, "vch_users": vch_users,
"total_power_w": round(total_w, 1),
"missing_power": sorted(set(missing_w)),
"issues": issues, "notes": notes}
# ── варианты для ручной сборки (только совместимые!) ──
FEATURE_ROLE = {
"aec": "audio", "anc": "audio", "dante": "audio", "aes67": "audio",
@@ -354,6 +487,19 @@ class H(BaseHTTPRequestHandler):
if k not in D.devices:
return self._out({"error": "not found"}, 404)
return self._out(D.device_row(k))
if p == "/api/positions":
return self._out(D.positions(q.get("host", [""])[0],
[x for x in q.get("need", []) if x]))
if p == "/api/capacity":
items = []
for raw in q.get("item", []):
if ":" in raw:
m, n = raw.rsplit(":", 1)
try:
items.append([m, int(n)])
except ValueError:
pass
return self._out(D.capacity(q.get("host", [""])[0], items))
if p == "/api/vendors":
return self._out(VENDORS)
if p == "/api/options":