Files

101 lines
3.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Функции устройств + фильтр по требованиям партнёра.
Источник функций: rooms-supported-features-list (96 функций × устройства).
Фильтр: задаём требования (AirPlay, 802.1x, Auto Framing, Dante...) —
получаем устройства, которые им соответствуют.
"""
import glob
import json
import os
import re
import sys
BASE = "/opt/work-hub/compat"
OUT = BASE
TRUE_MARKS = ("√", "✓", "✔", "да", "yes", "y", "支持")
def fix(s):
if s is None:
return ""
s = str(s)
for enc in ("cp1251", "cp866"):
try:
return s.encode(enc).decode("utf-8")
except Exception:
continue
return s
def truthy(v):
t = fix(v).strip().lower()
return any(m in t for m in TRUE_MARKS)
def build_features():
"""Собирает device -> набор функций из таблиц features-list."""
files = glob.glob(os.path.join(BASE, "raw", "rooms-supported-features-list-*.yaml"))
if not files:
print("нет файла features-list")
return {}
import yaml
d = yaml.safe_load(open(files[0], encoding="utf-8"))
devices = {}
for table in d.get("tables") or []:
if not table:
continue
header = [fix(c).strip() for c in table[0]]
# первый столбец — название функции, остальные — устройства
for row in table[1:]:
if not row:
continue
feat = fix(row[0]).strip()
if not feat:
continue
for i, cell in enumerate(row[1:], start=1):
dev = header[i] if i < len(header) else ""
dev = re.sub(r"\s+", " ", dev).strip()
if not dev:
continue
entry = devices.setdefault(dev, {"features": set(), "absent": set()})
if truthy(cell):
entry["features"].add(feat)
elif fix(cell).strip():
entry["absent"].add(feat)
return devices
def main():
import yaml
devices = build_features()
out = {"vendor": "yealink",
"note": "Функции из официального rooms-supported-features-list. "
"Dante/AES67 у Yealink НЕТ — требуется внешний DSP (Biamp/Shure/QSC).",
"devices": [{"device": k,
"features": sorted(v["features"]),
"absent": sorted(v["absent"])}
for k, v in sorted(devices.items())]}
path = os.path.join(OUT, "features.yaml")
with open(path, "w", encoding="utf-8") as f:
yaml.safe_dump(out, f, allow_unicode=True, sort_keys=False, width=160)
all_feats = set()
for v in devices.values():
all_feats |= v["features"]
print("устройств с функциями: %d" % len(devices))
print("уникальных функций: %d" % len(all_feats))
print("\nустройства (первые 10):")
for k, v in list(devices.items())[:10]:
print(" %-28s функций %2d" % (k[:28], len(v["features"])))
print("\nфункции для фильтра (примеры):")
for x in sorted(all_feats)[:20]:
print(" -", x)
print("\nсохранено:", path)
return 0
if __name__ == "__main__":
sys.exit(main())