diff --git a/deploy/profile-scripts/batch_reassess.py b/deploy/profile-scripts/batch_reassess.py index 0b765df3..80bc84d3 100644 --- a/deploy/profile-scripts/batch_reassess.py +++ b/deploy/profile-scripts/batch_reassess.py @@ -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) diff --git a/deploy/profile-scripts/capital_flow_collector.py b/deploy/profile-scripts/capital_flow_collector.py index 355f20b6..679ccafb 100644 --- a/deploy/profile-scripts/capital_flow_collector.py +++ b/deploy/profile-scripts/capital_flow_collector.py @@ -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,