fix predict

This commit is contained in:
2026-08-24 19:10:32 +08:00
parent 286626dfe5
commit 1f72dfdc1e
3 changed files with 96 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ from datetime import datetime, timezone
from pathlib import Path
from urllib.parse import urlparse
import joblib
import pandas as pd
from .pipeline import load_database_url, parse_time_ms, predict_from_csv, prepare_data
@@ -84,9 +85,28 @@ def ensure_database(
def build_predictions(data_dir: Path, artifact: Path, output_dir: Path) -> dict[str, object]:
manifest = json.loads((data_dir / "manifest.json").read_text())
artifact_data = joblib.load(artifact)
trained_symbols = set(artifact_data.get("asset_profiles", {}))
if trained_symbols:
skipped_symbols = [
item["symbol"]
for item in manifest["symbols"]
if item["symbol"] not in trained_symbols
]
prediction_items = [
item for item in manifest["symbols"] if item["symbol"] in trained_symbols
]
else:
skipped_symbols = []
prediction_items = manifest["symbols"]
if skipped_symbols:
print(
f"[latest-predict] skipped {len(skipped_symbols)} symbols without stored training profiles",
flush=True,
)
rows: list[dict[str, object]] = []
total = len(manifest["symbols"])
for index, item in enumerate(manifest["symbols"], 1):
total = len(prediction_items)
for index, item in enumerate(prediction_items, 1):
csv_path = data_dir / item["path"]
frame = pd.read_csv(csv_path).sort_values("timestamp").drop_duplicates("timestamp")
latest = frame.iloc[-1]
@@ -128,6 +148,7 @@ def build_predictions(data_dir: Path, artifact: Path, output_dir: Path) -> dict[
summary = {
"model": str(artifact.resolve()),
"symbols": len(rows),
"skipped_symbols": skipped_symbols,
"eligible_predictions": sum(row["drawdown_point_pct"] is not None for row in rows),
"latest_bar_start_utc": rows[0]["latest_bar_start_utc"] if rows else None,
"csv": str(output_csv.resolve()),