feat: add render-algo subcommand for single-algorithm GT+detection PNG
This commit is contained in:
@@ -209,9 +209,38 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
p_watch.add_argument("--window-sec", type=int, default=30, help="检测间隔秒数 (default: 30)")
|
||||
p_watch.add_argument("--url", default="ws://root:taosdata@localhost:6041", help="TDengine WebSocket URL")
|
||||
|
||||
# render-algo
|
||||
p_ra = sub.add_parser("render-algo", help="单算法 GT+检测渲染 PNG")
|
||||
p_ra.add_argument("--gt-csv", required=True, help="GT CSV 文件路径")
|
||||
p_ra.add_argument("--det-json", required=True, help="detect-batch --json 输出的 JSON 文件")
|
||||
p_ra.add_argument("--algo", required=True, help="算法名称")
|
||||
p_ra.add_argument("--output", required=True, help="PNG 输出路径")
|
||||
p_ra.add_argument("--value-col", default="value", help="数值列名 (default: value)")
|
||||
p_ra.add_argument("--title", default="", help="图表标题")
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def cmd_render_algo(args):
|
||||
"""render-algo 子命令:单算法 GT+检测渲染 PNG。"""
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||
|
||||
import json
|
||||
from ts_anomaly_td.io_csv import read_csv
|
||||
from ts_anomaly_td.visualize import render_algo
|
||||
|
||||
ts, vals, labels = read_csv(args.gt_csv, value_col=args.value_col)
|
||||
|
||||
with open(args.det_json) as f:
|
||||
det_data = json.load(f)
|
||||
|
||||
# det_json 格式: {"algo": "ksigma", "windows": [[start, end], ...], "error": null}
|
||||
windows = det_data.get("windows", [])
|
||||
|
||||
title = args.title or f"{Path(args.gt_csv).stem} / {args.algo}"
|
||||
render_algo(ts, vals, labels, windows, args.algo, args.output, title=title)
|
||||
|
||||
|
||||
def main():
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
@@ -223,6 +252,7 @@ def main():
|
||||
"e2e": cmd_e2e,
|
||||
"visualize": cmd_visualize,
|
||||
"watch": cmd_watch,
|
||||
"render-algo": cmd_render_algo,
|
||||
}
|
||||
|
||||
fn = dispatch.get(args.command)
|
||||
|
||||
Reference in New Issue
Block a user