LottoSight — Project Documentation
App Overview
Name: LottoSight
Type: Desktop Application
Framework: Python + Tkinter
Database: SQLite (local, zero-config)
Purpose: Analyze historical lottery drawing data and predict next winning numbers using multiple statistical strategies.
Tech Stack
| Component |
Technology |
| UI |
Tkinter + ttk |
| Charts |
Matplotlib (embedded in Tkinter) |
| Database |
SQLite via sqlite3 |
| Data Fetch |
requests + BeautifulSoup |
| Analysis |
collections, statistics, numpy |
| Scheduler |
APScheduler |
| Export |
openpyxl |
| Packaging |
PyInstaller |
Supported Games
| Game |
Main Balls |
Pool |
Bonus Ball |
Pool |
| Powerball |
5 |
1–69 |
1 |
1–26 |
| Mega Millions |
5 |
1–70 |
1 |
1–25 |
| Custom |
config |
config |
optional |
config |
Data Sources
| Source |
Game |
Coverage |
Method |
| NY Open Data API |
Powerball |
2010–present |
REST API |
| NY Open Data API |
Mega Millions |
2002–present |
REST API |
| Texas Lottery CSV |
Mega Millions |
2003–present |
CSV download |
API Endpoints
- Powerball (NY):
https://data.ny.gov/resource/d6yy-54nr.json
- Mega Millions (NY):
https://data.ny.gov/resource/5xaw-6ayf.json
- Mega Millions (TX):
https://www.texaslottery.com/export/sites/lottery/Games/Mega_Millions/Winning_Numbers/download.html
File Structure
Database Schema
Table: games
| Column |
Type |
Description |
| id |
INTEGER |
Primary key |
| name |
TEXT |
Game name (e.g. Powerball) |
| main_count |
INTEGER |
Number of main balls |
| main_max |
INTEGER |
Max value for main balls |
| bonus_count |
INTEGER |
Number of bonus balls (0 if none) |
| bonus_max |
INTEGER |
Max value for bonus ball |
| active |
INTEGER |
1 = active, 0 = disabled |
Table: draws
| Column |
Type |
Description |
| id |
INTEGER |
Primary key |
| game_id |
INTEGER |
Foreign key → games.id |
| draw_date |
TEXT |
ISO date string (YYYY-MM-DD) |
| numbers |
TEXT |
Comma-separated main numbers |
| bonus |
TEXT |
Bonus ball number(s) |
| multiplier |
TEXT |
Power Play / Megaplier (nullable) |
| source |
TEXT |
Data source identifier |
| created_at |
TEXT |
Record insert timestamp |
Table: predictions
| Column |
Type |
Description |
| id |
INTEGER |
Primary key |
| game_id |
INTEGER |
Foreign key → games.id |
| strategy |
TEXT |
Strategy name used |
| numbers |
TEXT |
Predicted main numbers |
| bonus |
TEXT |
Predicted bonus number |
| created_at |
TEXT |
Prediction timestamp |
Table: fetch_log
| Column |
Type |
Description |
| id |
INTEGER |
Primary key |
| source |
TEXT |
Source name |
| fetched_at |
TEXT |
Timestamp of fetch |
| added |
INTEGER |
New records inserted |
| skipped |
INTEGER |
Duplicate records skipped |
| status |
TEXT |
success / error |
| message |
TEXT |
Error message or notes |
Fetch System
Auto-Fetch
- Triggers on app launch (background thread)
- Repeats every 24 hours via APScheduler
- Runs in background — does not block UI
Manual Fetch
- Button in Toolbar (always visible, all screens)
- Button in Settings screen
- Shows "Fetching…" state while running
Duplicate Handling
- Compare incoming records by
draw_date + game_id
- Skip if already exists in DB
- Report result in status bar:
X added, Y skipped
Status Bar Format
Analysis Features
| Feature |
Description |
| Frequency analysis |
Hot/cold numbers by total draw count |
| Gap/skip analysis |
How many draws since each number last appeared |
| Positional frequency |
Which numbers appear most in each draw position |
| Pair/triplet patterns |
Number combinations that appear together often |
| Odd/even ratio |
Ratio of odd vs even numbers per draw |
| Sum range analysis |
Distribution of total sums across all draws |
| Delta patterns |
Differences between consecutive numbers in a draw |
Prediction Strategies
| # |
Strategy |
Description |
| 1 |
Hot Numbers |
Top N most frequent numbers in last X draws |
| 2 |
Due Numbers |
Numbers overdue based on expected frequency gap |
| 3 |
Weighted Random |
numpy random choice weighted by historical frequency |
| 4 |
Monte Carlo |
10,000 simulations, pick most common result |
| 5 |
Positional |
Most frequent number per draw position |
UI Screens
| Screen |
Description |
| Dashboard |
Summary stats, last draw result, quick actions |
| History |
Searchable/sortable draw history table |
| Analysis |
Charts — frequency bar, heatmap, gap chart |
| Predictor |
Pick strategy → generate ticket numbers |
| Settings |
Game config, data sources, fetch interval, manual fetch |
Logging
All actions are logged to console and optionally to a log file:
[FETCH] — auto/manual fetch events
[DB] — insert, skip, error events
[PREDICT] — prediction generated
[EXPORT] — export actions
[ERROR] — any exception with traceback
Build Phases & To-Do
✅ Phase 0 — Planning
✅ Phase 1 — Database Setup
✅ Phase 2 — Fetch System
✅ Phase 3 — History Browser
✅ Phase 4 — Analysis Engine + Charts
🔲 Phase 5 — Prediction Engine
🔲 Phase 6 — Settings Screen
🔲 Phase 7 — Export + Polish
🔲 Phase 8 — Packaging
Notes
- SQLite DB file stored at:
lottosight/data/lottosight.db
- Exports land in:
lottosight/exports/
- All fetch operations run in background threads to keep UI responsive
- NY Open Data API supports
$limit and $offset params for pagination
- Texas Lottery CSV requires parsing — columns vary, needs header detection
- Powerball matrix changed Oct 7, 2015 (5/69+1/26) — pre-2015 data has different pool sizes, flag in DB or filter