fix: sina分钟线列映射 + 推荐接口DB回退(重启后仍可见)

This commit is contained in:
lookt
2026-09-16 07:23:47 +08:00
parent 08efc52ff8
commit db98f6f084
2 changed files with 25 additions and 3 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ class KlineFetcher:
df.columns = [str(c).lower() for c in df.columns] df.columns = [str(c).lower() for c in df.columns]
cmap = {} cmap = {}
for c in df.columns: for c in df.columns:
if c in ('时间', 'bar_time', 'date', '日期'): if c in ('时间', 'bar_time', 'date', '日期', 'day'):
cmap[c] = 'bar_time' cmap[c] = 'bar_time'
elif c in ('开盘', 'open'): elif c in ('开盘', 'open'):
cmap[c] = 'open' cmap[c] = 'open'
+22
View File
@@ -107,8 +107,30 @@ async def recent_events(_request):
async def quant_recommendations(_request): async def quant_recommendations(_request):
q = _request.app['quant'] q = _request.app['quant']
if q.last_ranking:
return web.json_response({'ts': q.last_scored_at, return web.json_response({'ts': q.last_scored_at,
'list': (q.last_ranking or [])[:50]}) 'list': (q.last_ranking or [])[:50]})
# 重启后内存为空:回退数据库最近一批推荐
import sqlite3
db = str(ROOT / 'data' / 'a_stock.db')
try:
conn = sqlite3.connect(db, check_same_thread=False)
latest_ts = conn.execute(
"SELECT ts FROM quant_recommendation ORDER BY id DESC LIMIT 1").fetchone()
rows = []
if latest_ts:
rows = conn.execute(
"SELECT code,name,price,score,stars,buy_low,buy_high,"
"expected_return_pct,reason FROM quant_recommendation "
"WHERE ts=? ORDER BY score DESC LIMIT 50", (latest_ts[0],)).fetchall()
conn.close()
except Exception:
rows = []
items = [{'code': r[0], 'name': r[1] or r[0], 'price': r[2], 'score': r[3],
'stars': r[4], 'buy_low': r[5], 'buy_high': r[6],
'expected_return_pct': r[7], 'reason': r[8]} for r in rows]
return web.json_response({'ts': latest_ts[0] if rows else None, 'list': items,
'source': 'db'})
async def quant_weights(_request): async def quant_weights(_request):