(node_id: str)
| 351 | |
| 352 | # 添加节点和边的递归函数 |
| 353 | def add_node_recursive(node_id: str): |
| 354 | if node_id not in nodes: |
| 355 | return |
| 356 | |
| 357 | node = nodes[node_id] |
| 358 | |
| 359 | # 构建节点标签 |
| 360 | status_sym = "✓" if node.run_status == "OK" else "✗" if node.run_status == "FAIL" else "?" |
| 361 | stage_name = {"root": "R", "draft": "D", "improve": "I", "debug": "DB"}.get(node.stage, node.stage[:1].upper()) |
| 362 | |
| 363 | label_lines = [ |
| 364 | f"{status_sym} {stage_name} {node.id[:8]}", |
| 365 | ] |
| 366 | |
| 367 | if node.metric is not None: |
| 368 | label_lines.append(f"metric: {node.metric:.4f}") |
| 369 | else: |
| 370 | label_lines.append("metric: N/A") |
| 371 | |
| 372 | if node.is_terminal: |
| 373 | label_lines.append("[TERMINAL]") |
| 374 | |
| 375 | label = "\n".join(label_lines) |
| 376 | |
| 377 | # 根据状态和阶段设置颜色 |
| 378 | if node.run_status == "OK": |
| 379 | if node.metric is not None and node.metric > 0.9: |
| 380 | fillcolor = "#90EE90" # 浅绿色 - 高metric |
| 381 | else: |
| 382 | fillcolor = "#E8F5E9" # 浅绿色 - 成功但metric一般 |
| 383 | elif node.run_status == "FAIL": |
| 384 | fillcolor = "#FFCDD2" # 浅红色 - 失败 |
| 385 | else: |
| 386 | fillcolor = "#F5F5F5" # 灰色 - 未知 |
| 387 | |
| 388 | # 根据阶段调整颜色 |
| 389 | if node.stage == "root": |
| 390 | fillcolor = "#BBDEFB" # 浅蓝色 - 根节点 |
| 391 | elif node.stage == "draft": |
| 392 | fillcolor = "#FFF3E0" # 浅橙色 - draft节点 |
| 393 | |
| 394 | # 添加节点 |
| 395 | g.node( |
| 396 | node_id, |
| 397 | label=label, |
| 398 | fillcolor=fillcolor |
| 399 | ) |
| 400 | |
| 401 | # 递归添加子节点和边 |
| 402 | for child_id in node.children_ids: |
| 403 | if child_id in nodes: |
| 404 | add_node_recursive(child_id) |
| 405 | g.edge(node_id, child_id) |
| 406 | |
| 407 | # 从根节点开始构建 |
| 408 | if root_id not in nodes: |
no test coverage detected