feat(alert): 异常浮窗数据源改为broadcast_messages的system_error类(24h,统一消息源)
This commit is contained in:
@@ -239,6 +239,37 @@ def index():
|
||||
return resp
|
||||
|
||||
|
||||
def _get_recent_error_alerts(hours=24, limit=10):
|
||||
"""从 broadcast_messages 读取24小时内的 system_error 类消息作为异常浮窗数据源。
|
||||
统一消息源:broadcast 是唯一消息源,异常浮窗=其中的 system_error 类展示。"""
|
||||
import sqlite3 as _sq
|
||||
from datetime import datetime, timedelta
|
||||
try:
|
||||
conn = _sq.connect("/home/hmo/MoFin/data/mofin.db", timeout=30)
|
||||
conn.row_factory = _sq.Row
|
||||
since = (datetime.now() - timedelta(hours=hours)).isoformat()
|
||||
rows = conn.execute(
|
||||
"SELECT ts, title, content, source, category FROM broadcast_messages "
|
||||
"WHERE category='system_error' AND ts >= ? ORDER BY ts DESC LIMIT ?",
|
||||
(since, limit)).fetchall()
|
||||
conn.close()
|
||||
result = []
|
||||
for r in rows:
|
||||
ts = r["ts"] or ""
|
||||
result.append({
|
||||
"ts": 0,
|
||||
"ts_str": ts[:19].replace("T", " "),
|
||||
"level": "error",
|
||||
"source": r["source"] or "system",
|
||||
"title": r["title"] or "",
|
||||
"detail": r["content"] or "",
|
||||
"code": "",
|
||||
})
|
||||
return result
|
||||
except Exception:
|
||||
return _load_json(DATA_DIR / "alerts.json", [])[:limit]
|
||||
|
||||
|
||||
@app.route("/api/watch")
|
||||
def get_watch():
|
||||
"""盯盘:所有有效策略(持仓+自选),服务端排序"""
|
||||
@@ -1063,7 +1094,8 @@ def api_overview():
|
||||
"total_assets": total_assets, "stock_value": stock_value,
|
||||
"cash": cash, "position_pct": position_pct, "total_pnl": total_pnl,
|
||||
"top_movers": top_movers, "market": market,
|
||||
"alerts": _load_json(DATA_DIR / "alerts.json", [])[:10],
|
||||
# 异常浮窗数据源:broadcast_messages 的 system_error 类(24小时内)
|
||||
"alerts": _get_recent_error_alerts(24),
|
||||
# 2026-08-13 温区自适应:概览页横幅数据源
|
||||
"regime_weights": _load_json(DATA_DIR / "strategy_weights.json", None),
|
||||
"updated_at": summary.get("updated_at", ""),
|
||||
|
||||
Reference in New Issue
Block a user