debug: 温区缓存临时日志(验证后移除)
This commit is contained in:
@@ -52,17 +52,22 @@ def _compute_regime_winrates_cached(pt, _approx_univ):
|
||||
from flask import request as _req
|
||||
|
||||
# 缓存键
|
||||
import time as _tt
|
||||
_t0 = _tt.time()
|
||||
_cache_key = None
|
||||
try:
|
||||
_cc = _sq.connect(str(DATA_DIR / "mofin.db"), timeout=5)
|
||||
_ver_s = _cc.execute("SELECT MAX(created_at) FROM strategy_research").fetchone()[0]
|
||||
_cc.close()
|
||||
_cache_key = (pt or "2y") + "|" + str(_ver_s)
|
||||
except Exception:
|
||||
except Exception as _e:
|
||||
print(f"[REGIME_CACHE] key_err: {_e}", flush=True)
|
||||
_cache_key = None
|
||||
if _cache_key and _regime_winrates_cache.get("key") == _cache_key \
|
||||
and (pt or "2y") in (_regime_winrates_cache.get("slots") or {}):
|
||||
print(f"[REGIME_CACHE] HIT pt={pt} key={_cache_key} cost={round(_tt.time()-_t0,3)}s", flush=True)
|
||||
return _regime_winrates_cache["slots"][pt or "2y"]
|
||||
print(f"[REGIME_CACHE] MISS pt={pt} key={_cache_key} cached_key={_regime_winrates_cache.get('key')} slots={list((_regime_winrates_cache.get('slots') or {}).keys())}", flush=True)
|
||||
|
||||
_pt_chain = {'1m': '1y', '6m': '1y', '1y': '1y', '2y': '2y', '5y': '5y', '10y': '10y'}
|
||||
_pt_use = _pt_chain.get(pt or '2y', '2y')
|
||||
@@ -172,6 +177,7 @@ def _compute_regime_winrates_cached(pt, _approx_univ):
|
||||
(_regime_winrates_cache.setdefault("slots", {}))[pt or "2y"] = _regime_winrates
|
||||
except Exception:
|
||||
pass
|
||||
print(f"[REGIME_CACHE] DONE pt={pt} cost={round(_tt.time()-_t0,1)}s strategies={len(_regime_winrates)}", flush=True)
|
||||
return _regime_winrates
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user