[WORK] Форма авто-режима (что включить), крепления не дублируют комплект, обратный поиск по аксессуару, Roomcast больше не хост
This commit is contained in:
1 parent
f0260e9842
commit
2b00676119
4 files changed
+212
-21
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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")
|
||||
+78
-8
@@ -83,7 +83,16 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord
|
||||
<label>Мест</label>
|
||||
<div style="display:flex;align-items:center;gap:8px"><input type="range" id="seats" min="2" max="30" value="10"><b id="seatsv">10</b></div>
|
||||
<div class="muted" id="roomout" style="margin-top:4px"></div>
|
||||
<button class="btn" style="width:100%;margin-top:12px" onclick="doAutofill()">Собрать автоматически</button>
|
||||
<div id="af-form" style="margin-top:12px;border-top:1px solid #30363d;padding-top:10px">
|
||||
<div class="muted" style="margin-bottom:5px">авто-режим: что включить</div>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-mic" checked> микрофоны</label>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-camera" checked> камера</label>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-panel" checked> панель</label>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-sharing" checked> презентация</label>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-display" checked> дисплей</label>
|
||||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="inc-mount"> крепление</label>
|
||||
<button class="btn" style="width:100%;margin-top:10px" onclick="doAutofill()">Собрать автоматически</button>
|
||||
</div>
|
||||
<h3 style="margin-top:14px">Требования</h3>
|
||||
<div id="reqs"><span class="muted">загрузка…</span></div>
|
||||
</div>
|
||||
@@ -128,8 +137,17 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord
|
||||
<!-- МАТРИЦА -->
|
||||
<section id="sec-matrix" class="hidden">
|
||||
<div class="card"><h3>Матрица совместимости</h3>
|
||||
<input id="mq" placeholder="фильтр по модели…" style="max-width:260px;margin-bottom:10px" oninput="renderMatrix()">
|
||||
<div id="matrixbox" style="overflow:auto;max-height:68vh"><span class="muted">загрузка…</span></div>
|
||||
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px">
|
||||
<input id="mq" placeholder="фильтр по модели…" style="max-width:220px" oninput="renderMatrix()">
|
||||
<span class="muted">проверить пару:</span>
|
||||
<select id="chk-host" style="max-width:220px"></select>
|
||||
<input id="chk-dev" placeholder="VCM36-W" list="acc-list" style="max-width:170px" onchange="accessoryHosts()">
|
||||
<datalist id="acc-list"></datalist>
|
||||
<button class="btn sm" onclick="checkPair()">Проверить</button>
|
||||
<span id="chkres"></span>
|
||||
</div>
|
||||
<div id="mxdetail"></div>
|
||||
<div id="matrixbox" style="overflow:auto;max-height:60vh"><span class="muted">загрузка…</span></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -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?`<div class="muted">${notes.map(esc).join('; ')}</div>`:'');
|
||||
}
|
||||
async function renderCables(){
|
||||
const ks=Object.keys(SEL); if(!ks.length){$('#cablesbox').innerHTML='<span class="muted">соберите состав</span>';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=`<div class="card" style="margin-bottom:10px;border-color:#2f81f7">
|
||||
<h3 style="color:#79c0ff">${esc(d.name)} — совместимые аксессуары</h3>
|
||||
${comp.level!=='full'?`<div class="box">⚠ ${esc(comp.note||'')}</div>`:''}
|
||||
${items.map(x=>`<div style="margin-bottom:6px"><b>${esc(x.name)}</b> (${x.items.length}):
|
||||
${x.items.map(i=>`<span class="tag" onclick="checkOne('${key}','${esc(i.model)}')">${esc(i.model)}${i.max_qty?' до '+i.max_qty:''}</span>`).join('')}</div>`).join('')}
|
||||
<div id="onecheck" style="margin-top:8px"></div></div>`;
|
||||
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=`<div class="box ${ok?'ok':'bad'}"><b>${esc(r.host||host)} + ${esc(r.device||model)}</b> — ${esc(r.verdict||'')}
|
||||
${r.condition?`<div class="muted">${esc(r.condition).slice(0,120)}</div>`:''}</div>`;
|
||||
}
|
||||
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='<span class="muted">ни один хост не поддерживает</span>';return;}
|
||||
$('#chkres').innerHTML=`<b>${esc(r.device)}</b>: ${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=`<b style="color:${ok?'#3fb950':'#f85149'}">${esc(r.verdict||'')}</b>`;
|
||||
}
|
||||
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=>`<option>${esc(x)}</option>`).join('');
|
||||
}
|
||||
if($('#acc-list').children.length===0){
|
||||
$('#acc-list').innerHTML=(MATRIX.accessories||[]).map(a=>`<option>${esc(a)}</option>`).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+=`<th style="writing-mode:vertical-rl;transform:rotate(180deg);height:100px">${esc(a).slice(0,24)}</th>`);
|
||||
h+='</tr>';
|
||||
rows.forEach(r=>{
|
||||
h+=`<tr><td style="font-weight:600;white-space:nowrap">${esc(r.host)}</td>
|
||||
const rk=r.host.toLowerCase().replace(/[^a-z0-9]/g,'');
|
||||
h+=`<tr onclick="hostDetail('${rk}')" style="cursor:pointer">
|
||||
<td style="font-weight:600;white-space:nowrap;color:#79c0ff">${esc(r.host)}</td>
|
||||
<td class="muted">${(r.ports.in||[]).join(',')}</td><td class="muted">${(r.ports.out||[]).join(',')}</td>`;
|
||||
accs.forEach(a=>{const v=r.cells[a.toLowerCase().replace(/[^a-z0-9]/g,'')];
|
||||
h+=`<td style="text-align:center;color:${v?'#3fb950':'#30363d'}">${v?(v>1?v:'✓'):'·'}</td>`;});
|
||||
h+=`<td style="text-align:center;color:${v?'#3fb950':'#30363d'}" ${v?`onclick="event.stopPropagation();checkOne('${rk}','${esc(a)}')"`:''}>${v?(v>1?v:'✓'):'·'}</td>`;});
|
||||
h+='</tr>';
|
||||
});
|
||||
$('#matrixbox').innerHTML=h+'</table>';
|
||||
|
||||
Reference in new issue
Block a user