Fix QuantReport: fuzzy file matching + proper backtestId from historical data

- API: fuzzy matcher resolves files by strategy name substring
- Frontend: backtestId now uses historical[name].name (the filename)
- Server restarted with quant_report endpoint
This commit is contained in:
ramseshk
2026-08-06 03:50:28 +00:00
parent 0e08543823
commit 79870925f7
2 changed files with 36 additions and 8 deletions
+35 -7
View File
@@ -440,13 +440,41 @@ app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
@app.get("/api/quant-report/{name}") @app.get("/api/quant-report/{name}")
async def get_quant_report(name: str): async def get_quant_report(name: str):
"""Compute full QF-Lib quant report from a backtest file.""" """Compute full QF-Lib quant report from a backtest file.
backtest_path = os.path.join(BACKTEST_DIR, name) Accepts either an exact filename or a strategy-name prefix.
if not os.path.exists(backtest_path): """
# Try historical # Build candidate paths
hist_path = os.path.join(HISTORICAL_DIR, name) candidates = []
if os.path.exists(hist_path): exact_path = os.path.join(BACKTEST_DIR, name)
backtest_path = hist_path hist_exact = os.path.join(HISTORICAL_DIR, name)
candidates.extend([exact_path, hist_exact])
# Try exact match first
for path in candidates:
if os.path.exists(path):
backtest_path = path
break
else:
# Fuzzy match: look for files containing the name
for d in [BACKTEST_DIR, HISTORICAL_DIR]:
if not os.path.exists(d): continue
for f in os.listdir(d):
# Match: name is a substring of filename (case insensitive)
name_clean = name.lower().replace(" ", "_").replace(".json", "")
f_clean = f.lower()
if name_clean in f_clean or f_clean.startswith(name_clean):
candidates.append(os.path.join(d, f))
if not candidates:
# Try partial match on strategy name
for d in [BACKTEST_DIR, HISTORICAL_DIR]:
if not os.path.exists(d): continue
for f in os.listdir(d):
parts = f.lower().replace(".json", "").split("_")
name_parts = name.lower().replace(" ", "_").split("_")
if all(p in parts for p in name_parts):
candidates.append(os.path.join(d, f))
if candidates:
backtest_path = candidates[0]
else: else:
return JSONResponse({"error": f"Backtest '{name}' not found"}, status_code=404) return JSONResponse({"error": f"Backtest '{name}' not found"}, status_code=404)
try: try:
File diff suppressed because one or more lines are too long