fix(lotto-lab): 코드 리뷰 이슈 수정 — update_purchase JSON 직렬화, EMA 피드백 루프 연결
- update_purchase에서 numbers/is_real 타입 변환 추가 (런타임 에러 방지) - purchase_manager에서 evolve_after_check 호출하여 EMA 피드백 루프 활성화 - checker.py 중복 recalculate_weights 호출 제거 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,10 +66,7 @@ def check_results_for_draw(drw_no: int) -> int:
|
||||
# ── 구매 이력 체크 연동 ──────────────────────────────────────
|
||||
try:
|
||||
from .purchase_manager import check_purchases_for_draw as _check_purchases
|
||||
purchase_count = _check_purchases(drw_no)
|
||||
if purchase_count > 0:
|
||||
from .strategy_evolver import recalculate_weights
|
||||
recalculate_weights()
|
||||
_check_purchases(drw_no) # 내부에서 evolve_after_check → recalculate_weights 호출
|
||||
except ImportError:
|
||||
pass # purchase_manager 미설치 시 무시 (하위호환)
|
||||
|
||||
|
||||
@@ -880,12 +880,18 @@ def get_purchases(draw_no: int = None, days: int = None,
|
||||
|
||||
|
||||
def update_purchase(purchase_id: int, data: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
||||
import json as _json
|
||||
allowed = {"draw_no", "amount", "sets", "prize", "note", "numbers", "is_real", "source_strategy"}
|
||||
updates = {k: v for k, v in data.items() if k in allowed}
|
||||
if not updates:
|
||||
with _conn() as conn:
|
||||
row = conn.execute("SELECT * FROM purchase_history WHERE id = ?", (purchase_id,)).fetchone()
|
||||
return _purchase_row_to_dict(row) if row else None
|
||||
# SQLite에 전달 전 타입 변환
|
||||
if "numbers" in updates:
|
||||
updates["numbers"] = _json.dumps(updates["numbers"], ensure_ascii=False)
|
||||
if "is_real" in updates:
|
||||
updates["is_real"] = 1 if updates["is_real"] else 0
|
||||
set_clause = ", ".join(f"{k} = ?" for k in updates)
|
||||
with _conn() as conn:
|
||||
cur = conn.execute(
|
||||
|
||||
@@ -63,8 +63,10 @@ def check_purchases_for_draw(drw_no: int) -> int:
|
||||
"max_correct": 0,
|
||||
"prize_total": 0,
|
||||
"scores": [],
|
||||
"_results": [],
|
||||
}
|
||||
agg = strategy_agg[strat]
|
||||
agg["_results"].extend(results)
|
||||
for r in results:
|
||||
agg["sets_count"] += 1
|
||||
agg["total_correct"] += r["correct"]
|
||||
@@ -86,5 +88,12 @@ def check_purchases_for_draw(drw_no: int) -> int:
|
||||
avg_score=round(avg_score, 4),
|
||||
)
|
||||
|
||||
# EMA 피드백 루프: 전략 가중치 진화
|
||||
try:
|
||||
from .strategy_evolver import evolve_after_check
|
||||
evolve_after_check(strat, drw_no, agg["_results"])
|
||||
except Exception:
|
||||
logger.debug(f"[purchase_manager] evolve_after_check 건너뜀: {strat}")
|
||||
|
||||
logger.info(f"[purchase_manager] {drw_no}회차 구매 {count}건 체크 완료")
|
||||
return count
|
||||
|
||||
Reference in New Issue
Block a user