refactor: CLI binaries use shared fxcache::discover_and_load()
Replace 40-line inline fxcache discovery block in train_baseline_rl.rs with a single call to ml::fxcache::discover_and_load(). precompute_features.rs already uses correct symbol/data_source args — no changes needed there. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -542,51 +542,18 @@ fn run_training(args: &Args) -> Result<Vec<RlTrainingResult>> {
|
||||
info!("Step 1/5: Loading data...");
|
||||
let data_load_start = std::time::Instant::now();
|
||||
|
||||
// Auto-discover fxcache: CLI arg > env var > sibling feature-cache/ dir
|
||||
let fxcache_dir = args.feature_cache_dir.as_ref()
|
||||
.map(PathBuf::from)
|
||||
.filter(|p| p.exists())
|
||||
.or_else(|| std::env::var("FOXHUNT_FEATURE_CACHE_DIR").ok().map(PathBuf::from))
|
||||
.or_else(|| {
|
||||
let symbol_dir = args.data_dir.join(&args.symbol);
|
||||
let mut dir = symbol_dir.as_path();
|
||||
loop {
|
||||
if let Some(parent) = dir.parent() {
|
||||
let candidate = parent.join("feature-cache");
|
||||
if candidate.exists() { return Some(candidate); }
|
||||
if parent == dir { break; }
|
||||
dir = parent;
|
||||
} else { break; }
|
||||
}
|
||||
None
|
||||
});
|
||||
let cache_dir_override = args.feature_cache_dir.as_ref().map(|s| std::path::PathBuf::from(s));
|
||||
let mbp10 = args.mbp10_data_dir.as_ref().filter(|p| p.exists());
|
||||
let trades = args.trades_data_dir.as_ref().filter(|p| p.exists());
|
||||
|
||||
// Try loading from fxcache
|
||||
let fxcache_data = fxcache_dir.and_then(|cache_dir| {
|
||||
// Key must match precompute_features: data_dir (not symbol_dir)
|
||||
let default_mbp10 = PathBuf::from("test_data/futures-baseline-mbp10");
|
||||
let default_trades = PathBuf::from("test_data/futures-baseline-trades");
|
||||
let mbp10 = args.mbp10_data_dir.as_deref().unwrap_or(&default_mbp10);
|
||||
let trades = args.trades_data_dir.as_deref().unwrap_or(&default_trades);
|
||||
let mbp10: Option<&Path> = if mbp10.exists() { Some(mbp10) } else { None };
|
||||
let trades: Option<&Path> = if trades.exists() { Some(trades) } else { None };
|
||||
|
||||
let key_hex = ml::feature_cache::calculate_dbn_cache_key_full(
|
||||
&args.data_dir, mbp10, trades, &args.symbol, "ohlcv",
|
||||
).ok()?;
|
||||
let key: [u8; 32] = hex::decode(&key_hex).ok()?.try_into().ok()?;
|
||||
let path = ml::fxcache::find_fxcache(&cache_dir, &key)?;
|
||||
match ml::fxcache::load_fxcache(&path) {
|
||||
Ok(data) => {
|
||||
info!("fxcache hit: {} bars from {:?}", data.bar_count, path);
|
||||
Some(data)
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("fxcache load failed: {e}");
|
||||
None
|
||||
}
|
||||
}
|
||||
});
|
||||
let fxcache_data = ml::fxcache::discover_and_load(
|
||||
&args.data_dir,
|
||||
&args.symbol,
|
||||
mbp10.map(|p| p.as_path()),
|
||||
trades.map(|p| p.as_path()),
|
||||
"ohlcv",
|
||||
cache_dir_override.as_deref(),
|
||||
);
|
||||
|
||||
// Load data into fxcache-compatible arrays: features, targets, timestamps, ofi
|
||||
let fxcache = if let Some(cached) = fxcache_data {
|
||||
|
||||
Reference in New Issue
Block a user