05/23 Phase 22

This commit is contained in:
2026-05-23 17:36:33 -04:00
parent edd2ed5660
commit 59789f3cfe
10 changed files with 358 additions and 23 deletions
+32
View File
@@ -167,10 +167,42 @@ class LottoSightApp(tk.Tk):
def _on_fetch_done(self, results: list):
self._fetch_btn.config(state="normal", text="Fetch Now")
self._statusbar.update_fetch_results(results)
total_added = sum(r.get("added", 0) for r in results)
if total_added > 0:
self._check_predictions_vs_latest()
# Refresh the current screen if it can show new data
if self._current_screen and hasattr(self._current_screen, "refresh"):
self._current_screen.refresh()
def _check_predictions_vs_latest(self):
"""Compare all saved predictions against the most recent draw per game."""
from db.models import get_predictions, get_last_draw
preds = get_predictions(limit=100_000)
if not preds:
return
best = 0
hit_count = 0
for pred in preds:
draw = get_last_draw(pred["game_id"])
if not draw:
continue
pred_nums = {int(n) for n in pred["numbers"].split(",") if n.strip().isdigit()}
draw_nums = {int(n) for n in draw["numbers"].split(",") if n.strip().isdigit()}
matches = len(pred_nums & draw_nums)
bonus_hit = (
pred.get("bonus") and draw.get("bonus")
and str(pred["bonus"]) == str(draw["bonus"])
)
if matches >= 2 or bonus_hit:
hit_count += 1
best = max(best, matches)
if hit_count > 0:
self._statusbar.append_match_alert(
f"{hit_count} saved prediction(s) matched ≥2 numbers (best: {best}/main)"
)
# ── Lifecycle ─────────────────────────────────────────────────────────────
def on_close(self):