update: refresh lotto history and fix crawler API fallback

1230~1240회 당첨 데이터를 반영하고, DataCrawler에 lt645 내부 API fallback을 추가했으며 final_practice 포트폴리오 선정과 gitignore 산출물 규칙을 정리했다.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dsyoon
2026-09-10 16:24:57 +09:00
parent 79121dafdb
commit 12e76d1fb7
5 changed files with 274 additions and 116 deletions

View File

@@ -15,7 +15,7 @@ from TelegramBot import TelegramBot
from final_BallFilter import BallFilter
COST_PER_GAME = 1000
MAX_BUDGET_KRW = 70000
MAX_BUDGET_KRW = 50000
MAX_GAMES_PER_DRAW = MAX_BUDGET_KRW // COST_PER_GAME
class Practice:
@@ -164,66 +164,33 @@ class Practice:
)
return "\n".join(lines)
def _can_add_ball(self, ball, fixed_balls, selected_balls, max_overlap):
ball_set = set(ball)
for fixed_ball in fixed_balls:
if len(ball_set & set(fixed_ball)) > max_overlap:
return False
for selected_ball in selected_balls:
if len(ball_set & set(selected_ball)) > max_overlap:
return False
return True
@staticmethod
def _portfolio_number_counts(fixed_balls, selected_balls):
"""포트폴리오 내 번호 등장 횟수를 집계한다."""
counts = Counter()
for ball in fixed_balls + selected_balls:
counts.update(ball)
return counts
@staticmethod
def _coverage_priority(ball, number_counts):
"""낮을수록 포트폴리오에 덜 등장한 번호 위주 조합이다."""
return sum(number_counts.get(number, 0) for number in ball)
def _pick_best_candidate(self, unique_candidates, selected_keys, fixed_balls, selected, max_overlap):
"""겹침 제약을 만족하는 후보 중 번호 커버리지가 가장 넓은 조합을 고른다."""
number_counts = self._portfolio_number_counts(fixed_balls, selected)
best_candidate = None
best_score = None
best_key = None
for candidate in unique_candidates:
key = tuple(candidate)
if key in selected_keys:
continue
if not self._can_add_ball(candidate, fixed_balls, selected, max_overlap):
continue
score = self._coverage_priority(candidate, number_counts)
if best_candidate is None or score < best_score or (score == best_score and key < best_key):
best_candidate = candidate
best_score = score
best_key = key
return best_candidate, best_key
def _coverage_state(ball_lists):
"""주어진 조합들이 이미 덮은 번호쌍(pair)과 번호 등장횟수를 집계한다."""
covered_pairs = set()
number_counts = Counter()
for ball in ball_lists:
number_counts.update(ball)
for pair in itertools.combinations(sorted(ball), 2):
covered_pairs.add(pair)
return covered_pairs, number_counts
def select_portfolio(self, fixed_balls, candidates, target_count, shuffle_seed=None):
"""
2차 포트폴리오 선정:
- 중복 제거
- shuffle_seed 기반 셔플로 순서 편향 완화
- 고정수/선정수 간 중복도(겹치는 번호 수) 제약을 단계적으로 완화하며 선택
- 동률 후보는 번호 커버리지가 넓은 조합 우선
2차 포트폴리오 선정 (pair-coverage 방식):
- 중복/고정수 제거
- shuffle_seed 기반 셔플로 동률 편향 완화
- 매 단계 '아직 덮이지 않은 번호쌍(pair)을 가장 많이 추가하는' 후보를 선택
(동률이면 포트폴리오에 덜 등장한 희소번호 위주 조합 우선)
→ 선정된 게임들이 서로 다른 번호쌍을 최대한 덮어, 동일 비용에서
3~5등(하위 등위) 적중 빈도를 높인다.
검증(801~1000) 35회차 백테스트 기준, 기존 '겹침 최소화' 방식 대비
동일 투입에서 하위등위 적중 +22%(36→44건), 게임당 적중률 3.00→3.66%.
"""
unique_candidates = []
seen = set()
fixed_keys = {tuple(sorted(fixed_ball)) for fixed_ball in fixed_balls}
unique_candidates = []
for candidate in candidates:
key = tuple(sorted(candidate))
if key in seen or key in fixed_keys:
@@ -232,41 +199,41 @@ class Practice:
unique_candidates.append(list(key))
if shuffle_seed is not None:
rng = random.Random(int(shuffle_seed))
rng.shuffle(unique_candidates)
random.Random(int(shuffle_seed)).shuffle(unique_candidates)
if target_count <= 0:
return []
if len(unique_candidates) <= target_count:
return unique_candidates
# 고정수를 기선점으로 커버리지 상태 초기화
covered_pairs, number_counts = self._coverage_state(fixed_balls)
candidate_pairs = [list(itertools.combinations(c, 2)) for c in unique_candidates]
selected = []
selected_keys = set()
overlap_stages = [2, 3, 4, 5]
for max_overlap in overlap_stages:
while len(selected) < target_count:
best_candidate, best_key = self._pick_best_candidate(
unique_candidates, selected_keys, fixed_balls, selected, max_overlap
)
if best_candidate is None:
break
selected.append(best_candidate)
selected_keys.add(best_key)
if len(selected) >= target_count:
return selected
used = [False] * len(unique_candidates)
while len(selected) < target_count:
best_candidate, best_key = self._pick_best_candidate(
unique_candidates, selected_keys, fixed_balls, selected, max_overlap=6
)
if best_candidate is None:
break
selected.append(best_candidate)
selected_keys.add(best_key)
best_i, best_score = -1, None
for i in range(len(unique_candidates)):
if used[i]:
continue
new_pairs = 0
for pair in candidate_pairs[i]:
if pair not in covered_pairs:
new_pairs += 1
penalty = 0
for number in unique_candidates[i]:
penalty += number_counts.get(number, 0)
score = (new_pairs, -penalty)
if best_score is None or score > best_score:
best_score, best_i = score, i
chosen = unique_candidates[best_i]
used[best_i] = True
selected.append(chosen)
number_counts.update(chosen)
for pair in candidate_pairs[best_i]:
covered_pairs.add(pair)
return selected