fix: 资金流聚合输出net_flow/main_force/retail_flow/trend(12维资金面恒0根因) + sector_context污染时行业名兜底
This commit is contained in:
@@ -124,6 +124,18 @@ def collect_data(code):
|
||||
except:
|
||||
data["price"] = 0
|
||||
|
||||
# 行业上下文修正:sector_context 被"大盘上涨比"污染或为空时,用 stock_sectors 的行业名兜底
|
||||
_sector_ctx = data.get('sector_context', '') or ''
|
||||
if (not _sector_ctx) or _sector_ctx.startswith('大盘上涨比') or len(_sector_ctx) < 4:
|
||||
try:
|
||||
_sdb = sqlite3.connect(DB)
|
||||
_sr = _sdb.execute("SELECT sector FROM stock_sectors WHERE code=? LIMIT 1", (code,)).fetchone()
|
||||
_sdb.close()
|
||||
if _sr and _sr[0]:
|
||||
_sector_ctx = f"行业{_sr[0]}"
|
||||
except Exception:
|
||||
pass
|
||||
data['sector_context'] = _sector_ctx
|
||||
# 大盘
|
||||
try:
|
||||
conn = sqlite3.connect(DB)
|
||||
|
||||
@@ -167,7 +167,16 @@ def main():
|
||||
def fetch_one(code):
|
||||
flow = fetch_flow(code, days=5)
|
||||
if flow:
|
||||
analysis = analyze_flow(flow)
|
||||
analysis = analyze_flow(flow) or {}
|
||||
# 聚合成 build_prompt 需要的字段(此前只有 alerts/pattern,12维资金面恒为0)
|
||||
net = round(sum(d["main_net"] for d in flow) / 1e4, 1)
|
||||
main_f = round(sum(d["super_large"] for d in flow) / 1e4, 1)
|
||||
retail = round(sum(d["medium"] + d["small"] for d in flow) / 1e4, 1)
|
||||
analysis["net_flow"] = net
|
||||
analysis["main_force"] = main_f
|
||||
analysis["retail_flow"] = retail
|
||||
analysis["trend"] = analysis.get("pattern") or \
|
||||
("主力流入" if main_f > 0 else ("主力流出" if main_f < 0 else "中性"))
|
||||
return (code, {
|
||||
"updated_at": datetime.now().strftime("%Y-%m-%d %H:%M"),
|
||||
"flow": flow,
|
||||
|
||||
Reference in New Issue
Block a user