05/23 Phase 7
This commit is contained in:
+45
-1
@@ -5,14 +5,16 @@ Prediction generator screen.
|
||||
Pick a strategy + game + ticket count → generate → save to DB.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter import ttk, filedialog, messagebox
|
||||
import logging
|
||||
|
||||
from db.models import get_all_games, get_game_by_name, insert_prediction
|
||||
from core.predictor import (
|
||||
hot_numbers, due_numbers, weighted_random, monte_carlo, positional_pick,
|
||||
)
|
||||
from core.exporter import export_predictions_excel, export_predictions_csv, ensure_exports_dir
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -121,6 +123,14 @@ class PredictorScreen(ttk.Frame):
|
||||
bottom, text="Clear", command=self._clear
|
||||
).pack(side="right", padx=(0, 4))
|
||||
|
||||
ttk.Button(
|
||||
bottom, text="Export CSV", command=self._export_csv, state="normal"
|
||||
).pack(side="right", padx=(0, 4))
|
||||
|
||||
ttk.Button(
|
||||
bottom, text="Export Excel", command=self._export_excel, state="normal"
|
||||
).pack(side="right", padx=(0, 4))
|
||||
|
||||
# ── Callbacks ─────────────────────────────────────────────────────────────
|
||||
|
||||
def refresh(self):
|
||||
@@ -198,3 +208,37 @@ class PredictorScreen(ttk.Frame):
|
||||
self._tree.delete(*self._tree.get_children())
|
||||
self._save_btn.config(state="disabled")
|
||||
self._status_var.set("")
|
||||
|
||||
def _export_excel(self):
|
||||
ensure_exports_dir()
|
||||
fp = filedialog.asksaveasfilename(
|
||||
title="Export predictions",
|
||||
defaultextension=".xlsx",
|
||||
filetypes=[("Excel workbook", "*.xlsx")],
|
||||
initialfile=f"predictions_{__import__('datetime').datetime.now().strftime('%Y%m%d')}.xlsx",
|
||||
)
|
||||
if not fp:
|
||||
return
|
||||
try:
|
||||
game_id = self._game_id
|
||||
export_predictions_excel(fp, game_id=game_id)
|
||||
self._status_var.set(f"Exported → {os.path.basename(fp)}")
|
||||
except Exception as e:
|
||||
messagebox.showerror("Export failed", str(e))
|
||||
|
||||
def _export_csv(self):
|
||||
ensure_exports_dir()
|
||||
fp = filedialog.asksaveasfilename(
|
||||
title="Export predictions",
|
||||
defaultextension=".csv",
|
||||
filetypes=[("CSV file", "*.csv")],
|
||||
initialfile=f"predictions_{__import__('datetime').datetime.now().strftime('%Y%m%d')}.csv",
|
||||
)
|
||||
if not fp:
|
||||
return
|
||||
try:
|
||||
game_id = self._game_id
|
||||
export_predictions_csv(fp, game_id=game_id)
|
||||
self._status_var.set(f"Exported → {os.path.basename(fp)}")
|
||||
except Exception as e:
|
||||
messagebox.showerror("Export failed", str(e))
|
||||
|
||||
Reference in New Issue
Block a user