87 lines
3.1 KiB
Python
87 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Версия библиотеки устройств: дата, счётчики, источники, пробелы.
|
|
|
|
Пишет /opt/work-hub/compat/library.yaml и используется сервисом каталога,
|
|
чтобы в интерфейсе было видно, насколько данные свежие.
|
|
"""
|
|
import glob
|
|
import os
|
|
import re
|
|
import sys
|
|
import time
|
|
|
|
BASE = "/opt/work-hub/compat"
|
|
OUT = os.path.join(BASE, "library.yaml")
|
|
|
|
|
|
def norm(s):
|
|
return re.sub(r"[^a-z0-9]", "", str(s).lower())
|
|
|
|
|
|
def main():
|
|
import yaml
|
|
cat = yaml.safe_load(open(os.path.join(BASE, "catalog.yaml"), encoding="utf-8")) or {}
|
|
devices = cat.get("devices") or []
|
|
graph = yaml.safe_load(open(os.path.join(BASE, "graph.yaml"), encoding="utf-8")) or {}
|
|
edges = graph.get("edges") or []
|
|
|
|
def count(src):
|
|
return sum(1 for e in edges if (e.get("source") or "") == src)
|
|
|
|
iface_v = yaml.safe_load(open(os.path.join(BASE, "interfaces_verified.yaml"),
|
|
encoding="utf-8")) or {}
|
|
pkg_v = yaml.safe_load(open(os.path.join(BASE, "package_verified.yaml"),
|
|
encoding="utf-8")) or {}
|
|
proposals = 0
|
|
pf = os.path.join(BASE, "proposals", "llm-proposals.yaml")
|
|
if os.path.exists(pf):
|
|
try:
|
|
d = yaml.safe_load(open(pf, encoding="utf-8")) or {}
|
|
proposals = len(d.get("proposals") or [])
|
|
except Exception:
|
|
pass
|
|
res = 0
|
|
for f in glob.glob("/opt/work-hub/research/results-*.jsonl"):
|
|
with open(f, encoding="utf-8") as fh:
|
|
res += sum(1 for _ in fh)
|
|
|
|
lib = {
|
|
"library": {
|
|
"vendor": "yealink",
|
|
"domain": "vcs",
|
|
"version": time.strftime("%Y.%m.%d-%H%M"),
|
|
"generated_at": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
"devices": len(devices),
|
|
"edges_total": len(edges),
|
|
"edges_by_source": {
|
|
"matrix": count("matrix"),
|
|
"accessories_list": count("accessories_list"),
|
|
},
|
|
"verified": {
|
|
"ports": len(iface_v.get("devices") or []),
|
|
"package": len(pkg_v.get("devices") or []),
|
|
},
|
|
"llm": {"documents_processed": res, "proposals_pending": proposals},
|
|
"gaps": [
|
|
"VCM38 — нет даташита в источнике",
|
|
"ёмкость цепочки VCH — нет документа",
|
|
"MCore/A40/A50 — только один источник (sparse)",
|
|
],
|
|
}
|
|
}
|
|
with open(OUT, "w", encoding="utf-8") as f:
|
|
yaml.safe_dump(lib, f, allow_unicode=True, sort_keys=False, width=160)
|
|
print("library.yaml записан:")
|
|
for k, v in lib["library"].items():
|
|
if isinstance(v, dict):
|
|
print(" %-16s %s" % (k, v))
|
|
elif isinstance(v, list):
|
|
print(" %-16s %d позиций" % (k, len(v)))
|
|
else:
|
|
print(" %-16s %s" % (k, v))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|