# -*- coding: utf-8 -*- r'''从设备拉取 TSV 并跑塌陷窗口分析。 用法: python _build/rp_analyze.py long2h A # 已有的 2 小时数据 python _build/rp_analyze.py ab_A A # 新跑的 A 组 python _build/rp_analyze.py ab_B B # B 组 ''' from __future__ import annotations import subprocess import sys from pathlib import Path HERE = Path(__file__).parent sys.path.insert(0, str(HERE)) from devssh import run # noqa: E402 def fetch(remote: str, local: Path) -> bool: if local.is_file() and local.stat().st_size > 0: print(" (本地已有 %s,直接用)" % local.name) return True out = run("cat %s" % remote, timeout=180)[1] if not out.strip(): print(" ✗ %s 是空的或读不到" % remote) return False local.write_text(out, encoding="utf-8", newline="\n") print(" 已拉取 %s(%d 行)" % (local.name, len(out.splitlines()))) return True def main() -> int: if len(sys.argv) < 3: print("用法: rp_analyze.py <前缀> <标签>") return 2 prefix, label = sys.argv[1], sys.argv[2] conns = HERE / ("dl_%s_conns.tsv" % prefix) health = HERE / ("dl_%s_health.tsv" % prefix) ok1 = fetch("/root/%s_conns.tsv" % prefix, conns) ok2 = fetch("/root/%s_health.tsv" % prefix, health) if not (ok1 and ok2): return 1 print() rc = subprocess.call([sys.executable, str(HERE / "rp_collapse.py"), label, str(conns), str(health)]) return rc if __name__ == "__main__": sys.exit(main())