Commit Graph

14 Commits

Author SHA1 Message Date
Rolf 0be6e908e6 Refactor and optimize: deduplicate, batch queries, fix bugs
- Remove unused DATABASE_PATH import from games.py
- Extract _new_game_context(db) helper to deduplicate GET/POST error path
- Extract _parse_hole_form() helper to deduplicate hole validation in create/edit course
- Batch N+1 player handicap and tee queries in create_game into two IN() queries
- Fix hole count import bug: use max() across all tees instead of first match
- Fix migration exception handling: re-raise unless "duplicate column name"
- Cache calcSkins() result in _skinsCache; invalidate on score/skip changes
- Collapse two identical Next buttons into one in new_game.html
- Fix stale skinDoubleBackNine checkbox: reset on mode change, use x-model

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:52:45 +01:00
Rolf d81d6a2d3c Fix AttributeError: sqlite3.Row has no .get() method
Replace game.get("side_skins_enabled", 0) with game["side_skins_enabled"]
in game_page and game_summary — both columns have NOT NULL DEFAULT so
direct key access is safe after migration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:40:54 +01:00
Rolf 3e98f5ae54 Import gender tees + front/back split ratings; front/back/9 hole selection
Course import now fetches both male and female tees, each with their own
per-tee stroke indices extracted from the holes array. Front and back 9
slope/rating are stored per tee for more accurate WHS handicap calculation.

New game creation replaces the 9/18 radio with a course-aware selector:
18-hole courses offer 18 holes, Front 9, or Back 9; 9-hole courses auto-
select. start_hole is stored on the game and used throughout scoring,
handicap calculation, and scorecard rendering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:37:20 +01:00
Rolf 5432734240 Add Skins as a side game for Bingo Bango Bongo
Players can now opt into a Skins side game when creating a BBB round.
The side game uses the same skins settings (carryover, net/gross, skin
value, double back nine). The scorecard gains a third Skins tab during
play and on the summary; the BBB leaderboard continues to rank by BBB
points.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 22:09:16 +01:00
Rolf c298c473f4 Fix 9-hole course handicap formula to use HI÷2 per WHS spec
Dedicated 9-hole courses have 9-hole ratings and pars, so the WHS
formula is: round((HI÷2) × (slope/113) + (rating − par)).
The previous code used the full HI, giving roughly double the correct
result (e.g. 22 instead of 11 on Augwil White Male for HI 18).

The three cases are now handled correctly:
- Dedicated 9-hole course: HI÷2 with 9-hole ratings
- 9 holes on 18-hole course: full HI with 18-hole ratings, result halved
- Full 18 holes: full HI with 18-hole ratings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:51:49 +01:00
Rolf 26c3280a92 Fix 9-hole handicap calculation when back-nine holes are missing from DB
When only front-nine holes are entered in course_holes (common setup),
course_par_full summed to ~36 instead of ~72, inflating the 9-hole
playing handicap by roughly 2x before halving. Fix by using
course_par_played×2 as the 18-hole par estimate in both the backend
create_game and the new_game confirmation preview.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:31:10 +01:00
Rolf 2c0717948a Add straight up / net handicap option for skins games
When creating a skins game, players can now choose between straight up
(gross scores) or net scoring (strokes subtracted per hole based on
playing handicap and stroke index). Net mode is stored on the game and
applied in both the live scorecard and the summary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:16:10 +01:00
Rolf 6317422316 Add skin value and back-nine doubling to skins games
Players can now set a monetary value per skin when starting a skins game.
For 18-hole games, an option to double the value on holes 10–18 is available.
The value is stored at game creation and displayed throughout the live game
and summary (leaderboard, scorecard, and totals).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 20:56:13 +01:00
Rolf 8601584099 Add playing handicap, 6-digit login code, and game UX improvements
- Playing handicap: computed at game creation (WHS formula), stored on
  game_players alongside per-hole strokes allocation; displayed on game
  summary with HC card and / markers on scorecard (only when SI defined);
  live game shows +N per player card when SI exists, HC total otherwise;
  new game confirmation previews computed HC per player

- Login: 6-digit code sent alongside magic link in every auth email;
  check_email page has auto-advancing digit inputs with paste support;
  new POST /auth/verify-code route handles code verification

- Game view: Score/Card toggle fixed with position:fixed to always show
  above nav bar on mobile; swipe on score view changes holes, swipe on
  scorecard switches tabs; dirty tracking prevents saving unmodified holes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 20:37:08 +01:00
Rolf c658c970ac Deduplicate handicap calculation into _playing_data helper
Extracts playing_handicaps + strokes_per_hole into a single helper
used by both game_page and game_summary, instead of duplicating
the logic in each route.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 11:43:03 +01:00
Rolf 1daf6a99c4 Add playing handicap and stroke allocation to game summary
- Calculate course handicap per player (WHS formula) in game_summary
- Show Playing Handicaps card with HI, HC, and tee per player
- Mark stroke-receiving holes with accent dots in strokes and skins scorecards
- Add HC footer row to strokes scorecard

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 11:16:26 +01:00
Rolf b03e515f75 Add game confirmation step before starting
New step 3 shows a summary of all selections (format, carryover,
course, holes, players with HCP and tee) before submitting.
Also includes handicap in player query and tee tracking in Alpine state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 10:54:31 +01:00
Rolf c51c872c33 Add Skins format, GolfCourseAPI import, and UX improvements
- Add Skins game format with optional carryover, mirroring BBB scoring pattern
- Add GolfCourseAPI integration for course search and import (httpx)
- Unwrap {"course": {}} API response envelope on import
- Add searchable course combobox and player filter to new game form
- Redirect to summary page after finishing a game
- Fix auth to allow registered users without a pending invitation
- Fix hardcoded BBB format in create_game; store carryover flag in DB
- Add game summary/scorecard view for completed games
- Add live games social stream to dashboard
- Add course name + subtitle to recent game cards
- Reorder nav: Home → Games → Admin → Profile

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 09:18:04 +01:00
Rolf 3a1da1482c Add full SkinsPins application
- FastAPI + SQLite + Alpine.js + HTMX PWA for Bingo Bango Bongo golf scoring
- Passwordless magic link auth with email (aiosmtplib) and admin invite system
- Real-time score entry via WebSocket with drag-and-drop player ordering
- Course management with per-hole par and stroke index
- Scorecard with golf score markers (birdie, eagle, bogey, etc.)
- Two-step new game form with tee selection per player
- Dashboard with stats, live games social stream, and recent game history
- Game summary view (read-only scorecard with leaderboard)
- User profile pages with win stats
- PWA install support with generated PNG icons
- Admin panel for users, courses, games, and invitations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 10:16:46 +01:00