feat(lotto): calibrate_winner + backfill (멱등·청크)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,49 @@ def calibrate_winner_compute(draws, target_draw_no, winning6,
|
||||
return {"scores": scores, "percentile": percentile, "cache_draws": len(pit)}
|
||||
|
||||
|
||||
MIN_HISTORY = 30 # point-in-time 캐시 최소 회차 (이 미만은 캘리브레이션 skip)
|
||||
|
||||
|
||||
def _db():
|
||||
from . import db as _db_mod
|
||||
return _db_mod
|
||||
|
||||
|
||||
def calibrate_winner(draw_no: int, sample_m: int = 2000) -> Dict[str, Any]:
|
||||
"""DB 진입점: 회차 1개 캘리브레이션 후 저장 (멱등)."""
|
||||
db = _db()
|
||||
draws = db.get_all_draw_numbers()
|
||||
row = db.get_draw(draw_no)
|
||||
if row is None:
|
||||
return {"ok": False, "reason": "no_draw"}
|
||||
pit = point_in_time_draws(draws, draw_no)
|
||||
if len(pit) < MIN_HISTORY:
|
||||
return {"ok": False, "reason": "insufficient_history"}
|
||||
winning6 = [row["n1"], row["n2"], row["n3"], row["n4"], row["n5"], row["n6"]]
|
||||
res = calibrate_winner_compute(draws, draw_no, winning6, sample_m=sample_m)
|
||||
db.save_winner_calibration(
|
||||
draw_no=draw_no, winning=winning6, scores=res["scores"],
|
||||
percentile=res["percentile"], my_pick_avg=None,
|
||||
cache_draws=res["cache_draws"],
|
||||
)
|
||||
return {"ok": True, "draw_no": draw_no, **res}
|
||||
|
||||
|
||||
def backfill_calibration(batch: int = 50, sample_m: int = 2000) -> Dict[str, Any]:
|
||||
"""미처리 회차만 batch개 캘리브레이션 (멱등·재개 가능)."""
|
||||
db = _db()
|
||||
draws = db.get_all_draw_numbers()
|
||||
done = db.get_calibrated_draw_nos()
|
||||
todo = [d for d, _ in draws if d not in done and d > MIN_HISTORY]
|
||||
todo.sort()
|
||||
n = 0
|
||||
for draw_no in todo[:batch]:
|
||||
r = calibrate_winner(draw_no, sample_m=sample_m)
|
||||
if r.get("ok"):
|
||||
n += 1
|
||||
return {"calibrated": n, "remaining": max(0, len(todo) - batch)}
|
||||
|
||||
|
||||
def coverage_tickets(k: int, seed: Optional[int] = None) -> List[List[int]]:
|
||||
"""greedy 커버리지 — 아직 덜 쓰인 번호를 우선 배치해 번호를 넓게 분산.
|
||||
(휠링/보장설계는 향후. 현재는 distinct + 번호 사용 균등화)"""
|
||||
|
||||
Reference in New Issue
Block a user