feat: auto sick tag in archive from journal mood issues
内照明心同步时匹配实例复盘情绪标签,自动标注犯病并锁定标签;中控不再手动选犯病。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -468,7 +468,23 @@ def _trade_row_to_dict(row: sqlite3.Row, overlay: dict | None = None) -> dict[st
|
||||
if key in d and d[key] not in (None, ""):
|
||||
out[key] = d[key]
|
||||
ov = overlay or {}
|
||||
out["behavior_tag"] = ov.get("behavior_tag") or ""
|
||||
from lib.trade.account_risk_lib import parse_mood_issues
|
||||
|
||||
journal_issues = parse_mood_issues(
|
||||
out.get("journal_mood_issues") or payload.get("journal_mood_issues")
|
||||
)
|
||||
tag_from_journal = bool(
|
||||
out.get("journal_mood_sick")
|
||||
or payload.get("journal_mood_sick")
|
||||
or journal_issues
|
||||
)
|
||||
tag = (ov.get("behavior_tag") or "").strip().lower()
|
||||
if tag_from_journal:
|
||||
tag = "sick"
|
||||
out["behavior_tag"] = tag
|
||||
out["behavior_tag_from_journal"] = tag_from_journal
|
||||
if journal_issues:
|
||||
out["journal_mood_issues"] = journal_issues
|
||||
out["note"] = ov.get("note") or ""
|
||||
out["trade_id"] = out.get("trade_id") or out.get("id")
|
||||
ex_col = str(d.get("exchange_key") or "").strip().lower()
|
||||
@@ -551,6 +567,31 @@ def upsert_trade_overlay(
|
||||
return {"exchange_key": ex_k, "trade_id": tid, "behavior_tag": tag, "note": note_text}
|
||||
|
||||
|
||||
def apply_journal_behavior_overlays(
|
||||
exchange_key: str,
|
||||
trades: list[dict[str, Any]],
|
||||
*,
|
||||
db_path: Path | None = None,
|
||||
) -> int:
|
||||
"""复盘情绪标签 → 写入 trade_overlay.behavior_tag=sick(仅正 trade_id)。"""
|
||||
ex_k = (exchange_key or "").strip().lower()
|
||||
if not ex_k:
|
||||
return 0
|
||||
n = 0
|
||||
for t in trades or []:
|
||||
if not isinstance(t, dict) or not t.get("journal_mood_sick"):
|
||||
continue
|
||||
try:
|
||||
tid = int(t.get("id"))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if tid <= 0:
|
||||
continue
|
||||
upsert_trade_overlay(ex_k, tid, behavior_tag="sick", db_path=db_path)
|
||||
n += 1
|
||||
return n
|
||||
|
||||
|
||||
def list_symbol_rows(
|
||||
*,
|
||||
exchange_key: str = "",
|
||||
@@ -1154,6 +1195,7 @@ def sync_exchange_symbol_archives(
|
||||
"""同步单所:交易缓存 + 各币种 K 线种子/增量。"""
|
||||
ex_k = (exchange_key or "").strip().lower()
|
||||
cache_stats = upsert_trades_cache(ex_k, trades, db_path=db_path, prune_missing=True)
|
||||
apply_journal_behavior_overlays(ex_k, trades, db_path=db_path)
|
||||
|
||||
by_sym: dict[str, int] = {}
|
||||
for t in trades or []:
|
||||
|
||||
Reference in New Issue
Block a user