fix: sina分钟线列映射 + 推荐接口DB回退(重启后仍可见)
This commit is contained in:
@@ -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'
|
||||||
|
|||||||
+24
-2
@@ -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']
|
||||||
return web.json_response({'ts': q.last_scored_at,
|
if q.last_ranking:
|
||||||
'list': (q.last_ranking or [])[:50]})
|
return web.json_response({'ts': q.last_scored_at,
|
||||||
|
'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):
|
||||||
|
|||||||
Reference in New Issue
Block a user