Fix analysis display for recipe-based runs

Add get_run_analysis() to RunService to load per-input analysis from
CACHE_DIR/analysis/{hash}.json files. Update runs router and template
to display tempo, beats, energy, and beat timeline visualization.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-01-11 08:05:40 +00:00
parent 29d8d06d76
commit 945fb3b413
3 changed files with 126 additions and 7 deletions

View File

@@ -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