#!/usr/bin/env python3 """P0-таксономия Комбайна: группы, дубли, пробелы, кандидаты SIP/H.323.""" import json import re import yaml from collections import Counter, defaultdict CAT = "/opt/work-hub/compat/catalog.yaml" VAL = "/opt/work-hub/compat/values.yaml" OUT_JSON = "/root/buryan-infra/ops/combine/taxonomy-2026-11-18.json" OUT_MD = "/root/buryan-infra/ops/combine/TAXONOMY-2026-11-18.md" cat = yaml.safe_load(open(CAT, encoding="utf-8")) catalog = cat.get("devices", []) values = yaml.safe_load(open(VAL, encoding="utf-8")) vlist = values if isinstance(values, list) else values.get("devices", []) vdev = [x.get("device") for x in vlist if isinstance(x, dict) and x.get("device")] cnames = {d.get("name", "") for d in catalog} def group(name, role=""): n = (name or "").lower() r = (role or "").lower() if "meetingbar" in n: return "B_video_bars" if "meetingboard" in n or "pvb" in n: return "B_video_bars_boards" if any(x in n for x in ("meetingeye", "mcore", "mvc", "pvt", "teams rooms", "mtr-w")): return "A_integration_terminals" if any(x in n for x in ("sip-t", "t88", "w70", "wh6", "uh38", "bh72", "ehs", "dect")): return "T_telephony" if any(x in n for x in ("uvc", "smartvision", "mb-cam", "mb-12x", "cam50", "byod")): return "D_usb_byod" if any(x in n for x in ("vcm", "cm20", "cm50", "mspeaker", "pa20", "cp50", "cp70", "cp90", "cp96", "cpe", "cpw", "cs10", "ap08", "mspeech", "audio")): return "E_audio" if any(x in n for x in ("ctp", "mtouch", "touch")): return "E_control" if any(x in n for x in ("rch", "ax83", "ax86", "switch", "poe")): return "E_infra" if any(x in n for x in ("display", "etv", "телевизор", "проектор", "tv", "projector")): return "E_display" if any(x in n for x in ("mount", "mtower", "mb-fs", "кронштейн")): return "E_mount" if any(x in n for x in ("yps", "power", "розетка", "заряд", "charger")): return "E_power" if any(x in n for x in ("room designer", "roomconnect", "software", "ymcs")): return "E_software" return "E_other" def clean(name): n = (name or "").strip() n = re.sub(r"\s*\((?:\d+|only.*?|included.*?)\)\s*$", "", n, flags=re.I) n = re.sub(r"\s*\[\d+\]\s*$", "", n) return n.strip() # duplicates by cleaned name buckets = defaultdict(list) for d in catalog: buckets[clean(d.get("name", ""))].append(d.get("name", "")) dups = {k: v for k, v in buckets.items() if len(v) > 1} # merged/suspicious names suspicious = [n for n in cnames if any(x in n for x in ("/", "&", ";", "MeetingBar (", "Meetingboard (", "Yealink ("))] groups = defaultdict(list) for d in catalog: groups[group(d.get("name"), d.get("role"))].append({"name": d.get("name"), "role": d.get("role"), "source": "catalog"}) for name in vdev: if name in cnames: continue groups[group(name)].append({"name": name, "role": None, "source": "values-only"}) # candidates for SIP/H.323: explicit protocols absent, so only name-based candidates candidates = [] for d in catalog: n = (d.get("name") or "").lower() if any(x in n for x in ("meetingeye", "meetingbar a40", "meetingbar a50", "pvb", "pvt")): candidates.append({"name": d.get("name"), "reason": "по имени/линейке; protocols в данных отсутствует", "verified": False}) result = { "generated": "2026-11-18", "catalog_count": len(catalog), "values_count": len(vdev), "values_only": sorted([v for v in vdev if v not in cnames]), "duplicates": dups, "suspicious": sorted(suspicious), "group_counts": {k: len(v) for k, v in groups.items()}, "groups": {k: v for k, v in groups.items()}, "protocols_field": "absent", "sip_h323_candidates": candidates, "missing_fields": ["vendor", "domain", "line", "protocols", "form_factor", "integrated", "limits", "source", "version"], } json.dump(result, open(OUT_JSON, "w", encoding="utf-8"), ensure_ascii=False, indent=2) lines = ["# P0-таксономия «Комбайна» — 18.11.2026", "", "Каталог: **%d** записей. Values: **%d** устройств. Только в values: **%d**." % (len(catalog), len(vdev), len(result["values_only"])), "", "## Группы", "| Группа | Кол-во |", "|---|---|"] for k, n in sorted(result["group_counts"].items(), key=lambda x: -x[1]): lines.append("| %s | %d |" % (k, n)) lines += ["", "## Дубли (по очищенному имени)", "| Имя | Варианты |", "|---|---|"] for k, v in sorted(dups.items()): lines.append("| %s | %s |" % (k, " · ".join(v))) lines += ["", "## Подозрительные слитые записи", *["- " + x for x in sorted(suspicious)]] lines += ["", "## SIP/H.323: кандидаты (не подтверждены)", "| Модель | Причина |", "|---|---|"] for c in candidates: lines.append("| %s | %s |" % (c["name"], c["reason"])) lines += ["", "## Устройства только в values.yaml (первые 60)", *["- " + x for x in result["values_only"][:60]]] lines += ["", "## Чего не хватает в схеме", *["- " + x for x in result["missing_fields"]]] open(OUT_MD, "w", encoding="utf-8").write("\n".join(lines) + "\n") print("saved", OUT_JSON, OUT_MD) print("groups", result["group_counts"]) print("dups", len(dups), "values-only", len(result["values_only"]), "sip candidates", len(candidates))