refactor: retire price_events.json completely — DB is the only store
User directive: no JSON, retire it fully, fix all related code. Changes: - price_monitor.py: record_event writes DB only; removed EVENTS_PATH/ load_events/save_events entirely - strategy_feedback.py: price events read from DB only (removed JSON fallback) - system_health_check.py: removed price_events.json from file-check list, DB-only event stats (was showing 0/0 due to wrong-DB resolution) - mo_config.py: removed dead price_events_path property (no callers) - mofin_health.py: price_events freshness reads DB table (authoritative now) - mofin_db.py: DATA_DIR/DB_PATH now ABSOLUTE (/home/hmo/MoFin/data) — was relative __file__.parent, so each hardlinked copy of mofin_db.py resolved to a DIFFERENT database (canonical vs web-dashboard vs profile-local third DB with 0 rows of everything except market_snapshots). This fragmentation was the real cause of health checks reading empty tables. - Unified all 4 mofin_db copies (root/scripts/deploy/profile) via hardlink - price_events.json archived to trashbox (fully backfilled: 6353 rows in DB) Verified: - record_event lands in DB only, JSON not recreated - system_health_check: 历史事件 6353 / 今日事件 2965 (was 0/0) - strategy_feedback + price_monitor full runs clean
This commit is contained in:
@@ -9,7 +9,6 @@ from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
DATA_DIR = Path("/home/hmo/web-dashboard/data")
|
||||
EVENTS_PATH = DATA_DIR / "price_events.json"
|
||||
EVALUATION_PATH = DATA_DIR / "evaluation.json"
|
||||
ACCURACY_PATH = DATA_DIR / "accuracy_stats.json"
|
||||
CRON_JOBS = "/home/hmo/.hermes/profiles/position-analyst/cron/jobs.json"
|
||||
@@ -104,10 +103,9 @@ def run():
|
||||
lines.append(check(False, "MoFin DB 数据读取失败"))
|
||||
warn_count += 3
|
||||
|
||||
# 仍为 JSON 文件的检查
|
||||
# 仍为 JSON 文件的检查(price_events 已迁移到 DB 表,不在此列)
|
||||
files = {
|
||||
"market.json": DATA_DIR / "market.json",
|
||||
"price_events.json": EVENTS_PATH,
|
||||
"evaluation.json": EVALUATION_PATH,
|
||||
"accuracy_stats.json": ACCURACY_PATH,
|
||||
}
|
||||
@@ -121,7 +119,7 @@ def run():
|
||||
else:
|
||||
ok_count += 1
|
||||
|
||||
# 4. 价格事件统计
|
||||
# 4. 价格事件统计(只读 DB price_events 表,JSON 已退役)
|
||||
lines.append("")
|
||||
lines.append("【价格事件】")
|
||||
try:
|
||||
@@ -130,10 +128,12 @@ def run():
|
||||
ev_list = query_price_events(conn, limit=50000)
|
||||
today_events = query_price_events_by_date(conn, now.strftime("%Y-%m-%d"))
|
||||
conn.close()
|
||||
except Exception:
|
||||
events = load_json(EVENTS_PATH, {"events": []})
|
||||
ev_list = events.get("events", [])
|
||||
today_events = [e for e in ev_list if e.get("date") == now.strftime("%Y-%m-%d")]
|
||||
except Exception as e:
|
||||
ev_list = []
|
||||
today_events = []
|
||||
lines.append(check(False, f"DB价格事件读取失败: {str(e)[:60]}"))
|
||||
issues.append(f"price_events DB读取失败: {str(e)[:60]}")
|
||||
warn_count += 1
|
||||
lines.append(check(len(ev_list) > 0, f"历史事件: {len(ev_list)}条"))
|
||||
lines.append(check(len(today_events) > 0, f"今日事件: {len(today_events)}条"))
|
||||
if len(ev_list) == 0:
|
||||
|
||||
Reference in New Issue
Block a user