fix: 九维分析改为结构化叙事格式(①②③...)

This commit is contained in:
知微
2026-07-09 20:59:41 +08:00
parent 93dd2f8732
commit e18dbfff6e
+41 -19
View File
@@ -19,15 +19,11 @@ def _build_full_analysis(code, entry, result):
return ""
lines = []
name = entry.get("name", code)
price = result.get("price", entry.get("price", 0))
price = result.get("price") or entry.get("price", 0)
# 技术面
tech = result.get("tech_snapshot") or entry.get("tech_snapshot", "")
# 行业
sector = result.get("sector_context") or entry.get("sector_context", "")
# 信号
signal = result.get("timing_signal") or entry.get("timing_signal", "")
# 类别
category = result.get("stock_category") or entry.get("stock_category", "")
el = result.get("entry_low") or entry.get("entry_low", 0)
@@ -35,21 +31,38 @@ def _build_full_analysis(code, entry, result):
sl = result.get("stop_loss") or entry.get("stop_loss", 0)
tp = result.get("take_profit") or entry.get("take_profit", 0)
rr = result.get("rr_ratio") or entry.get("rr_ratio", 0)
lines.append(f"{name}({code}) — 九维分析")
lines.append("")
if sector: lines.append(f"🏭 行业背景: {sector}")
if tech: lines.append(f"📊 技术分析: {tech}")
if category: lines.append(f"📌 分类: {category}")
lines.append(f"📈 信号: {signal}")
if price: lines.append(f"💵 当前价: {price}")
if el or eh: lines.append(f"🎯 买入区: {el}~{eh}")
if sl: lines.append(f"🛑 止损: {sl}")
if tp: lines.append(f"✅ 止盈: {tp}")
if rr: lines.append(f"📊 RR: {rr:.2f}")
act = result.get("action", "")
if act: lines.append(f"📋 策略: {act}")
# 从tech_snapshot提取关键数据
ma5 = ma10 = ma20 = ma60 = "?"
import re
ma_match = re.search(r'MA5=([\d.]+).*?MA10=([\d.]+).*?MA20=([\d.]+).*?MA60=([\d.]+)', tech)
if ma_match:
ma5, ma10, ma20, ma60 = ma_match.groups()
lines.append(f"{name}({code}) 九维全析】")
lines.append("")
lines.append(f"① 大盘×技术面:价格{price}MA5={ma5} MA10={ma10} MA20={ma20} MA60={ma60}")
if el and eh:
lines.append(f"② 大盘×买入区:当前价{'在买入区' if el <= price <= eh else ('低于买入区' if price < el else '高于买入区')}{el}~{eh}")
lines.append(f"③ 大盘×资金流:信号={signal},分类={category}")
if sector:
lines.append(f"④ 行业×基本面:{sector}")
if tech:
# 提取形态和量价
shape_m = re.search(r'形态:([^\s]+)', tech)
vol_m = re.search(r'量价:([^\s]+)', tech)
shape = shape_m.group(1) if shape_m else "?"
vol = vol_m.group(1) if vol_m else "?"
lines.append(f"⑤ 个股×技术面:{shape} | {vol}")
sr_m = re.search(r'强撑:([\d.]+).*?弱撑:([\d.]+).*?弱压:([\d.]+).*?强压:([\d.]+)', tech)
if sr_m:
lines.append(f"⑥ 个股×支撑阻力:强撑{sr_m.group(1)}→弱撑{sr_m.group(2)}→弱压{sr_m.group(3)}→强压{sr_m.group(4)}")
if sl and tp:
lines.append(f"⑦ 个股×风报比:止损{sl} 止盈{tp} RR={rr:.1f}")
if act:
lines.append(f"⑧ 策略判定:{act[:100]}")
lines.append(f"⑨ 综合结论:{signal},建议{'关注买入' if '买入' in signal else '持有观望' if signal == '持有' else '观望等待'}")
return "\n".join(lines)
@@ -216,6 +229,15 @@ def main():
if _fa and _fa[0]: print(f" ✅ full_analysis已写入({len(_fa[0])}字)")
else: print(f" ⚠️ full_analysis为空")
_v.close()
# 用代码构建完整九维分析
_full_analysis_text = _build_full_analysis(code, entry, result)
# 保存到DB
_fa_conn = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
_fa_conn.execute("UPDATE holding_strategies SET full_analysis=? WHERE code=? AND status='active'", (_full_analysis_text, code))
_fa_conn.commit()
_fa_conn.close()
print(f" ✅ 完整九维分析已保存({len(_full_analysis_text)}字)")
print(f" [DB] holding_strategies 已更新: {code}")
except Exception as _dbe:
print(f" [DB FAIL] holding_strategies 写入失败: {_dbe}", file=sys.stderr)