feat: macro_context/market数据全部DB优先,JSON回退
- 建 macro_context_log 表,macro_context_collector.py 双写 - strategy_lifecycle.py load_macro_context() 优先DB - strategy_tree.py detect_scenario() 优先DB - stale_push_wlin.py load_macro_line() 优先DB - xiaoguo_signal_consumer.py 大盘判断优先DB - stock_profile.py load_macro() 优先DB - system_audit.py 管道审计改查DB market_snapshots - JSON保留作fallback,确保过渡期不中断
This commit is contained in:
+23
-8
@@ -70,15 +70,30 @@ def detect_scenario():
|
||||
confidence = 0.5
|
||||
|
||||
try:
|
||||
macro = json.load(open(MACRO_PATH))
|
||||
market = json.load(open(MARKET_PATH))
|
||||
# 优先 DB
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
db = sqlite3.connect(str(Path(__file__).parent / "data" / "mofin.db"))
|
||||
mrow = db.execute(
|
||||
"SELECT indices, structure, sector_mood FROM macro_context_log "
|
||||
"WHERE has_valid_data=1 ORDER BY created_at DESC LIMIT 1"
|
||||
).fetchone()
|
||||
db.close()
|
||||
if mrow:
|
||||
structure = json.loads(mrow[1]) if mrow[1] else {}
|
||||
overall = structure.get("overall", "").lower()
|
||||
mood = (mrow[2] or "").lower() if len(mrow) > 2 else ""
|
||||
else:
|
||||
raise ValueError("no db data")
|
||||
except Exception:
|
||||
return {"id": scenario_id, "label": "默认-弱势震荡", "confidence": 0.3, "portfolio_action": "观望"}
|
||||
|
||||
mood = market.get("mood", "").lower()
|
||||
# Try to get trend from macro_context
|
||||
structure = macro.get("structure", {})
|
||||
overall = structure.get("overall", "").lower()
|
||||
try:
|
||||
macro = json.load(open(MACRO_PATH))
|
||||
market = json.load(open(MARKET_PATH))
|
||||
mood = market.get("mood", "").lower()
|
||||
structure = macro.get("structure", {})
|
||||
overall = structure.get("overall", "").lower()
|
||||
except Exception:
|
||||
return {"id": "weak_consolidation", "label": "默认-弱势震荡", "confidence": 0.3, "portfolio_action": "观望"}
|
||||
trend_desc = structure.get("description", "").lower()
|
||||
|
||||
# Check for sharp decline
|
||||
|
||||
Reference in New Issue
Block a user