fix(api): _get_metrics_file_path 先解析 result.task_id(uuid)—修 runner task_id≠文件名 task_id 导致 benchmark-curve/risk-series 404
This commit is contained in:
@@ -329,11 +329,16 @@ def optimization_results(task_id: str):
|
|||||||
# ===== Task 4: Backtest result API extensions =====
|
# ===== Task 4: Backtest result API extensions =====
|
||||||
|
|
||||||
def _get_metrics_file_path(task_id: str) -> str | None:
|
def _get_metrics_file_path(task_id: str) -> str | None:
|
||||||
"""Get the metrics file path for a task_id from orchestrator config."""
|
"""Get the metrics file path. Resolves the request task_id to the result's
|
||||||
|
internal task_id first — run_cta_backtest writes {task_id}_metrics.json under
|
||||||
|
ITS OWN uuid task_id (result.task_id), which differs from the runner's task_id."""
|
||||||
orch = get_orchestrator()
|
orch = get_orchestrator()
|
||||||
|
r = orch.get_result(task_id)
|
||||||
|
if r is None or not getattr(r, "task_id", None):
|
||||||
|
return None
|
||||||
if hasattr(orch, 'db_path') and orch.db_path:
|
if hasattr(orch, 'db_path') and orch.db_path:
|
||||||
file_dir = os.path.dirname(os.path.abspath(orch.db_path))
|
file_dir = os.path.dirname(os.path.abspath(orch.db_path))
|
||||||
metrics_file = os.path.join(file_dir, f"{task_id}_metrics.json")
|
metrics_file = os.path.join(file_dir, f"{r.task_id}_metrics.json")
|
||||||
if os.path.exists(metrics_file):
|
if os.path.exists(metrics_file):
|
||||||
return metrics_file
|
return metrics_file
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user