diff --git a/app/routers/runs.py b/app/routers/runs.py index aee682b..9447d8a 100644 --- a/app/routers/runs.py +++ b/app/routers/runs.py @@ -172,9 +172,10 @@ async def run_detail( if not run: raise HTTPException(404, f"Run {run_id} not found") - # Get plan and artifacts + # Get plan, artifacts, and analysis plan = await run_service.get_run_plan(run_id) artifacts = await run_service.get_run_artifacts(run_id) + analysis = await run_service.get_run_analysis(run_id) # Build DAG elements for visualization dag_elements = [] @@ -208,6 +209,7 @@ async def run_detail( "run": run, "plan": plan, "artifacts": artifacts, + "analysis": analysis, } templates = get_templates(request) @@ -215,6 +217,7 @@ async def run_detail( run=run, plan=plan, artifacts=artifacts, + analysis=analysis, dag_elements=dag_elements, user=ctx, active_tab="runs", diff --git a/app/services/run_service.py b/app/services/run_service.py index c3b601d..e98e7fb 100644 --- a/app/services/run_service.py +++ b/app/services/run_service.py @@ -225,3 +225,43 @@ class RunService: artifacts.append(info) return artifacts + + async def get_run_analysis(self, run_id: str) -> List[Dict[str, Any]]: + """Get analysis data for each input in a run.""" + from pathlib import Path + import os + + run = await self.get_run(run_id) + if not run: + return [] + + cache_dir = Path(os.environ.get("CACHE_DIR", "/tmp/artdag-cache")) + analysis_dir = cache_dir / "analysis" + + results = [] + inputs = run.get("inputs", []) + if isinstance(inputs, dict): + inputs = list(inputs.values()) + + for i, input_hash in enumerate(inputs): + analysis_path = analysis_dir / f"{input_hash}.json" + analysis_data = None + + if analysis_path.exists(): + try: + with open(analysis_path) as f: + analysis_data = json.load(f) + except (json.JSONDecodeError, IOError): + pass + + results.append({ + "input_hash": input_hash, + "input_name": f"Input {i + 1}", + "has_analysis": analysis_data is not None, + "tempo": analysis_data.get("tempo") if analysis_data else None, + "beat_times": analysis_data.get("beat_times", []) if analysis_data else [], + "energy": analysis_data.get("energy") if analysis_data else None, + "raw": analysis_data, + }) + + return results diff --git a/app/templates/runs/detail.html b/app/templates/runs/detail.html index 8d78917..32a05d1 100644 --- a/app/templates/runs/detail.html +++ b/app/templates/runs/detail.html @@ -56,7 +56,7 @@ onclick="showTab('plan')">Plan Artifacts - {% if run.analysis %} + {% if analysis %} Analysis {% endif %} @@ -158,13 +158,89 @@