refactor: 归档策略进化模块+新建评估页面+API
- 归档 evolution/ + meta_growth/meta_watchdog/ab_research_daily - docs/evolution-archive-readme.md: 归档说明(旧模块功能+替代方案) - server.py: 新增 /api/research/effectiveness + effectiveness/summary + recommendation_log + execution_log - static/effectiveness.html: 新评估页面(概览/详细评估/推荐记录/执行记录) - 策略进化改为人驱动闭环(评估→用户决策→调整)
This commit is contained in:
@@ -2409,4 +2409,102 @@ def api_docs_read():
|
||||
if __name__ == "__main__":
|
||||
port = int(os.environ.get("PORT", 8899))
|
||||
print(f"🚀 MoFin Dashboard → http://0.0.0.0:{port}")
|
||||
app.run(host="0.0.0.0", port=port, debug=False)
|
||||
app.run(host="0.0.0.0", port=port, debug=False)
|
||||
|
||||
# ── 策略评估 API ────────────────────────────────────────
|
||||
@app.route("/api/research/effectiveness")
|
||||
def api_research_effectiveness():
|
||||
"""策略到期评估结果查询
|
||||
|
||||
GET /api/research/effectiveness → 全部评估记录
|
||||
GET /api/research/effectiveness?code=600262 → 指定股票
|
||||
GET /api/research/effectiveness?source=v_next → 指定策略来源
|
||||
"""
|
||||
import sqlite3
|
||||
code = request.args.get("code", "")
|
||||
source = request.args.get("source", "")
|
||||
|
||||
db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=30)
|
||||
db.row_factory = sqlite3.Row
|
||||
|
||||
query = "SELECT * FROM strategy_effectiveness WHERE 1=1"
|
||||
params = []
|
||||
if code:
|
||||
query += " AND code=?"
|
||||
params.append(code)
|
||||
if source:
|
||||
query += " AND strategy_source=?"
|
||||
params.append(source)
|
||||
query += " ORDER BY created_at DESC LIMIT 100"
|
||||
|
||||
rows = db.execute(query, params).fetchall()
|
||||
db.close()
|
||||
|
||||
return jsonify([dict(r) for r in rows])
|
||||
|
||||
|
||||
@app.route("/api/research/effectiveness/summary")
|
||||
def api_research_effectiveness_summary():
|
||||
"""策略评估汇总:按策略来源分组统计"""
|
||||
import sqlite3
|
||||
db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=30)
|
||||
db.row_factory = sqlite3.Row
|
||||
|
||||
summary = db.execute("""
|
||||
SELECT strategy_source,
|
||||
COUNT(*) as total,
|
||||
SUM(CASE WHEN buy_zone_accuracy='effective' THEN 1 ELSE 0 END) as buy_effective,
|
||||
SUM(CASE WHEN stop_loss_accuracy='effective' THEN 1 ELSE 0 END) as sl_effective,
|
||||
SUM(CASE WHEN take_profit_accuracy='effective' THEN 1 ELSE 0 END) as tp_effective,
|
||||
AVG(CASE WHEN time_accuracy='on_time' THEN 1.0 WHEN time_accuracy='slightly_late' THEN 0.7 ELSE 0.3 END) as time_score
|
||||
FROM strategy_effectiveness
|
||||
GROUP BY strategy_source
|
||||
ORDER BY total DESC
|
||||
""").fetchall()
|
||||
db.close()
|
||||
|
||||
return jsonify([dict(r) for r in summary])
|
||||
|
||||
|
||||
@app.route("/api/research/recommendation_log")
|
||||
def api_research_recommendation_log():
|
||||
"""推荐历史查询"""
|
||||
import sqlite3
|
||||
code = request.args.get("code", "")
|
||||
limit = int(request.args.get("limit", "50"))
|
||||
|
||||
db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=30)
|
||||
db.row_factory = sqlite3.Row
|
||||
|
||||
query = "SELECT * FROM recommendation_log WHERE 1=1"
|
||||
params = []
|
||||
if code:
|
||||
query += " AND code=?"
|
||||
params.append(code)
|
||||
query += f" ORDER BY recommend_time DESC LIMIT {limit}"
|
||||
|
||||
rows = db.execute(query, params).fetchall()
|
||||
db.close()
|
||||
return jsonify([dict(r) for r in rows])
|
||||
|
||||
|
||||
@app.route("/api/research/execution_log")
|
||||
def api_research_execution_log():
|
||||
"""执行历史查询"""
|
||||
import sqlite3
|
||||
code = request.args.get("code", "")
|
||||
limit = int(request.args.get("limit", "50"))
|
||||
|
||||
db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=30)
|
||||
db.row_factory = sqlite3.Row
|
||||
|
||||
query = "SELECT * FROM execution_log WHERE 1=1"
|
||||
params = []
|
||||
if code:
|
||||
query += " AND code=?"
|
||||
params.append(code)
|
||||
query += f" ORDER BY execute_time DESC LIMIT {limit}"
|
||||
|
||||
rows = db.execute(query, params).fetchall()
|
||||
db.close()
|
||||
return jsonify([dict(r) for r in rows])
|
||||
|
||||
Reference in New Issue
Block a user