05/23 Phase 7
This commit is contained in:
+23
-1
@@ -7,8 +7,9 @@ Analysis screen — three Matplotlib charts embedded in a ttk.Notebook.
|
||||
• Gap — draws since each number last appeared
|
||||
"""
|
||||
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from tkinter import ttk, filedialog, messagebox
|
||||
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
@@ -18,6 +19,7 @@ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolb
|
||||
|
||||
from db.models import get_all_games, get_game_by_id, get_game_by_name
|
||||
from core.analyzer import frequency_analysis, gap_analysis, positional_frequency
|
||||
from core.exporter import export_frequency_excel, ensure_exports_dir
|
||||
|
||||
_LAST_N_OPTIONS = {
|
||||
"All draws": None,
|
||||
@@ -60,6 +62,7 @@ class AnalysisScreen(ttk.Frame):
|
||||
last_n_cb.bind("<<ComboboxSelected>>", lambda _: self._redraw_frequency())
|
||||
|
||||
ttk.Button(bar, text="↻ Refresh", command=self.refresh).pack(side="right")
|
||||
ttk.Button(bar, text="Export Frequency", command=self._export_frequency).pack(side="right", padx=(0, 4))
|
||||
|
||||
# Notebook with three chart tabs
|
||||
nb = ttk.Notebook(self)
|
||||
@@ -141,6 +144,25 @@ class AnalysisScreen(ttk.Frame):
|
||||
_draw_gap(ax, self._game_id)
|
||||
self._gap_canvas.draw()
|
||||
|
||||
def _export_frequency(self):
|
||||
if self._game_id is None:
|
||||
messagebox.showinfo("Export", "Select a game first.")
|
||||
return
|
||||
ensure_exports_dir()
|
||||
fp = filedialog.asksaveasfilename(
|
||||
title="Export frequency analysis",
|
||||
defaultextension=".xlsx",
|
||||
filetypes=[("Excel workbook", "*.xlsx")],
|
||||
initialfile=f"frequency_{__import__('datetime').datetime.now().strftime('%Y%m%d')}.xlsx",
|
||||
)
|
||||
if not fp:
|
||||
return
|
||||
try:
|
||||
last_n = _LAST_N_OPTIONS.get(self._last_n_var.get())
|
||||
export_frequency_excel(fp, self._game_id, last_n=last_n)
|
||||
except Exception as e:
|
||||
messagebox.showerror("Export failed", str(e))
|
||||
|
||||
|
||||
# ── Pure chart-drawing functions (no Tkinter, just axes) ─────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user