feat: strategy-staleness-check auto-creates TODOs for STRATEGY_STALE stocks
This commit is contained in:
@@ -10,11 +10,12 @@
|
|||||||
输出两份:JSON报告(给系统) + 人类可读摘要(stdout for cron)
|
输出两份:JSON报告(给系统) + 人类可读摘要(stdout for cron)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json, sys, os, re, urllib.request
|
import json, sys, os, re, urllib.request, sqlite3
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from mo_data import read_decisions, read_portfolio
|
from mo_data import read_decisions, read_portfolio
|
||||||
from mo_data import read_decisions, read_portfolio
|
|
||||||
|
|
||||||
|
DB_PATH = '/home/hmo/web-dashboard/data/mofin.db'
|
||||||
OUTPUT_PATH = "/home/hmo/web-dashboard/data/strategy_staleness_report.json"
|
OUTPUT_PATH = "/home/hmo/web-dashboard/data/strategy_staleness_report.json"
|
||||||
|
|
||||||
WARN_DAYS = 14 # 超过14天未更新→警告
|
WARN_DAYS = 14 # 超过14天未更新→警告
|
||||||
@@ -195,6 +196,27 @@ def main():
|
|||||||
if position_pct > 80:
|
if position_pct > 80:
|
||||||
portfolio_flags.append(f"[PORTFOLIO_FULL] 总仓位{position_pct}%(现金{cash:.0f}元),买入建议受限")
|
portfolio_flags.append(f"[PORTFOLIO_FULL] 总仓位{position_pct}%(现金{cash:.0f}元),买入建议受限")
|
||||||
|
|
||||||
|
# 写 TODO — 过期策略自动建修复任务
|
||||||
|
stale_items = [s for s in flagged if any("[STRATEGY_STALE]" in f for f in s.get("flags", []))]
|
||||||
|
if stale_items:
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
for s in stale_items:
|
||||||
|
code = s["code"]
|
||||||
|
existing = conn.execute("SELECT id FROM todos WHERE title LIKE ? AND status IN ('pending','in_progress')", (f"%{code}%",)).fetchone()
|
||||||
|
if existing:
|
||||||
|
continue
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO todos (title, description, status, priority, source, fix_action) VALUES (?,?,?,?,?,?)",
|
||||||
|
(f"[STRATEGY_STALE] {s['name']}({code}) 需重评",
|
||||||
|
f"策略过期: {'; '.join(s['flags'])} | 上次更新{s['age_days']}天前 | 区间{s['entry_zone']}",
|
||||||
|
"pending", "high", "staleness_check",
|
||||||
|
f"cd /home/hmo/MoFin && python3 scripts/per_stock_reassess.py {code}",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
print(f" TODO: 为 {len(stale_items)} 个过期策略创建修复任务")
|
||||||
|
|
||||||
# Write report
|
# Write report
|
||||||
os.makedirs(os.path.dirname(OUTPUT_PATH), exist_ok=True)
|
os.makedirs(os.path.dirname(OUTPUT_PATH), exist_ok=True)
|
||||||
report = {
|
report = {
|
||||||
|
|||||||
Reference in New Issue
Block a user