From 11212c4afdc30f0317c6add6c1ec941bab09914e Mon Sep 17 00:00:00 2001 From: gahusb Date: Sun, 31 May 2026 18:02:01 +0900 Subject: [PATCH] =?UTF-8?q?fix(agent-office):=20=EC=9D=BC=EC=9A=94=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20=EA=B2=AC=EA=B3=A0=ED=99=94=20(dead=20impo?= =?UTF-8?q?rt=20=EC=A0=9C=EA=B1=B0=C2=B7send=20=EA=B0=80=EB=93=9C=C2=B7?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20payload=20=EB=B0=A9=EC=96=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- agent-office/app/agents/lotto.py | 2 +- agent-office/app/notifiers/telegram_lotto.py | 26 ++++++++++++-------- agent-office/app/service_proxy.py | 7 ------ agent-office/tests/test_sunday_review.py | 15 +++++++++++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/agent-office/app/agents/lotto.py b/agent-office/app/agents/lotto.py index 44cd595..66d17ca 100644 --- a/agent-office/app/agents/lotto.py +++ b/agent-office/app/agents/lotto.py @@ -159,7 +159,7 @@ class LottoAgent(BaseAgent): async def run_sunday_review(self) -> dict: """일 09:00 — 최신 회차 forward+calibration 보장 후 회고 텔레그램.""" - from ..service_proxy import lotto_latest_draw, lotto_backtest_review, lotto_backtest_run_forward + from ..service_proxy import lotto_latest_draw, lotto_backtest_review from ..notifiers.telegram_lotto import send_sunday_review from ..db import create_task, update_task_status, add_log diff --git a/agent-office/app/notifiers/telegram_lotto.py b/agent-office/app/notifiers/telegram_lotto.py index 2d69796..b1ff050 100644 --- a/agent-office/app/notifiers/telegram_lotto.py +++ b/agent-office/app/notifiers/telegram_lotto.py @@ -232,7 +232,7 @@ async def send_evolution_report(eval_result: Dict[str, Any], current_base: List[ def format_sunday_review(payload: Dict[str, Any]) -> str: """일요 회고 브리핑 텍스트 (HTML parse_mode).""" wa = payload.get("winner_analysis") or {} - draw_no = payload.get("draw_no") + draw_no = payload.get("draw_no") or "?" pct = wa.get("percentile") pct_txt = f"{pct*100:.0f}%" if pct is not None else "—" lines = [f"🔍 로또 #{draw_no} 일요 회고", ""] @@ -243,18 +243,24 @@ def format_sunday_review(payload: Dict[str, Any]) -> str: f"· 갭 {wa.get('score_gap',0):.2f} · 공동출현 {wa.get('score_cooccur',0):.2f} " f"· 다양성 {wa.get('score_diversity',0):.2f}") lines.append("") - lines.append("📊 이번 회차 가상구매 성적") - for f in payload.get("forward", []): - p = f["prizes"] - name = {"engine_w": f"엔진({f['label']})", "random_null": "무작위", "coverage": "커버리지"}.get( - f["strategy"], f["strategy"]) - lines.append(f" {name}: 최고 {f['best_match']}일치 / " - f"4등 {p['4th']} · 5등 {p['5th']}") + if payload.get("forward"): + lines.append("📊 이번 회차 가상구매 성적") + for f in payload.get("forward", []): + p = f.get("prizes") or {} + name = {"engine_w": f"엔진({f.get('label','')})", "random_null": "무작위", "coverage": "커버리지"}.get( + f.get("strategy", ""), f.get("strategy", "?")) + lines.append(f" {name}: 최고 {f.get('best_match','?')}일치 / " + f"4등 {p.get('4th', 0)} · 5등 {p.get('5th', 0)}") + else: + lines.append("📊 이번 회차 가상구매 성적: 데이터 없음 (아직 집계 전)") lines.append("") lines.append("ℹ️ 무작위 대비 우위가 통계적으로 의미있을 때만 가중치가 진화합니다.") return "\n".join(lines) async def send_sunday_review(payload: Dict[str, Any]) -> None: - from ..telegram.messaging import send_raw - await send_raw(format_sunday_review(payload)) + text = format_sunday_review(payload) + try: + await send_raw(text) + except Exception as e: + logger.warning(f"[telegram_lotto] sunday review send failed: {e}") diff --git a/agent-office/app/service_proxy.py b/agent-office/app/service_proxy.py index 1690a71..30408f5 100644 --- a/agent-office/app/service_proxy.py +++ b/agent-office/app/service_proxy.py @@ -406,13 +406,6 @@ async def lotto_backtest_review(draw_no: int) -> Dict[str, Any]: return resp.json() -async def lotto_backtest_run_forward(draw_no: int) -> Dict[str, Any]: - from .config import LOTTO_BACKEND_URL - resp = await _client.post(f"{LOTTO_BACKEND_URL}/api/lotto/backtest/run-forward", - params={"draw_no": draw_no}) - resp.raise_for_status() - return resp.json() - from .config import AGENT_CONTAINER_MAP diff --git a/agent-office/tests/test_sunday_review.py b/agent-office/tests/test_sunday_review.py index 7d29ed6..e971911 100644 --- a/agent-office/tests/test_sunday_review.py +++ b/agent-office/tests/test_sunday_review.py @@ -21,3 +21,18 @@ def test_format_sunday_review_text(): assert "1170" in txt assert "%" in txt # percentile 표기 assert "engine" in txt.lower() or "엔진" in txt + + +def test_format_sunday_review_no_calibration(): + payload = {"draw_no": 1171, "winner_analysis": None, "forward": []} + txt = tl.format_sunday_review(payload) + assert "1171" in txt + assert "%" not in txt # no percentile section when calibration absent + assert "데이터 없음" in txt + + +def test_format_sunday_review_missing_prizes_no_crash(): + payload = {"draw_no": 1171, "winner_analysis": None, + "forward": [{"strategy": "engine_w", "label": "w1", "best_match": 3}]} # no 'prizes' + txt = tl.format_sunday_review(payload) # must NOT raise + assert "1171" in txt