|
|
@@ -1,6 +1,7 @@
|
|
|
import asyncio
|
|
|
import json
|
|
|
import os
|
|
|
+import sys
|
|
|
import argparse
|
|
|
from datetime import datetime
|
|
|
|
|
|
@@ -1732,7 +1733,7 @@ def format_output(optimization_result: dict, context: RunContext) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
-async def main(input_dir: str, max_levels: int = 4):
|
|
|
+async def main(input_dir: str, max_levels: int = 4, visualize: bool = False):
|
|
|
"""
|
|
|
主函数 - 使用独立步骤流程(方案A)
|
|
|
"""
|
|
|
@@ -1823,6 +1824,21 @@ async def main(input_dir: str, max_levels: int = 4):
|
|
|
json.dump(run_context.steps, f, ensure_ascii=False, indent=2)
|
|
|
print(f"Steps log saved to: {steps_file_path}")
|
|
|
|
|
|
+ # 如果需要生成可视化
|
|
|
+ if visualize:
|
|
|
+ import subprocess
|
|
|
+ output_html = os.path.join(run_context.log_dir, "visualization.html")
|
|
|
+ print(f"\n🎨 生成可视化HTML...")
|
|
|
+ result = subprocess.run([
|
|
|
+ "python", "visualize_steps.py",
|
|
|
+ steps_file_path,
|
|
|
+ "-o", output_html
|
|
|
+ ])
|
|
|
+ if result.returncode == 0:
|
|
|
+ print(f"✅ 可视化已生成: {output_html}")
|
|
|
+ else:
|
|
|
+ print(f"❌ 可视化生成失败")
|
|
|
+
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
@@ -1839,6 +1855,62 @@ if __name__ == "__main__":
|
|
|
default=4,
|
|
|
help="最大探索层数,默认: 4"
|
|
|
)
|
|
|
+ parser.add_argument(
|
|
|
+ "--visualize",
|
|
|
+ action="store_true",
|
|
|
+ default=True,
|
|
|
+ help="运行完成后自动生成可视化HTML(默认开启)"
|
|
|
+ )
|
|
|
+ parser.add_argument(
|
|
|
+ "--no-visualize",
|
|
|
+ action="store_false",
|
|
|
+ dest="visualize",
|
|
|
+ help="关闭自动生成可视化"
|
|
|
+ )
|
|
|
+ parser.add_argument(
|
|
|
+ "--visualize-only",
|
|
|
+ action="store_true",
|
|
|
+ help="只生成可视化,不运行搜索流程。自动查找input-dir下最新的输出目录"
|
|
|
+ )
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
- asyncio.run(main(args.input_dir, max_levels=args.max_levels))
|
|
|
+ # 如果只是生成可视化
|
|
|
+ if args.visualize_only:
|
|
|
+ import subprocess
|
|
|
+ import glob
|
|
|
+
|
|
|
+ # 获取版本名称
|
|
|
+ version_name = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
+ output_base = os.path.join(args.input_dir, "output", version_name)
|
|
|
+
|
|
|
+ # 查找最新的输出目录
|
|
|
+ if not os.path.exists(output_base):
|
|
|
+ print(f"❌ 找不到输出目录: {output_base}")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ # 获取所有日期目录
|
|
|
+ date_dirs = glob.glob(os.path.join(output_base, "*", "*"))
|
|
|
+ if not date_dirs:
|
|
|
+ print(f"❌ 在 {output_base} 中没有找到输出目录")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ # 按修改时间排序,获取最新的
|
|
|
+ latest_dir = max(date_dirs, key=os.path.getmtime)
|
|
|
+ steps_json = os.path.join(latest_dir, "steps.json")
|
|
|
+
|
|
|
+ if not os.path.exists(steps_json):
|
|
|
+ print(f"❌ 找不到 steps.json: {steps_json}")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ output_html = os.path.join(latest_dir, "visualization.html")
|
|
|
+ print(f"🎨 找到最新输出目录: {latest_dir}")
|
|
|
+ print(f"🎨 生成可视化: {steps_json} -> {output_html}")
|
|
|
+
|
|
|
+ result = subprocess.run([
|
|
|
+ "python", "visualize_steps.py",
|
|
|
+ steps_json,
|
|
|
+ "-o", output_html
|
|
|
+ ])
|
|
|
+ sys.exit(result.returncode)
|
|
|
+
|
|
|
+ asyncio.run(main(args.input_dir, max_levels=args.max_levels, visualize=args.visualize))
|