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>
This commit is contained in:
Rolf
2026-03-22 11:16:26 +01:00
parent 59a82eb4ad
commit 1daf6a99c4
2 changed files with 72 additions and 1 deletions
+28 -1
View File
@@ -280,6 +280,32 @@ async def game_summary(game_id: str, request: Request, user: dict = Depends(get_
if row["stroke_index"] is not None:
hole_stroke_indices[row["hole_number"]] = row["stroke_index"]
# Playing handicap per player: HI × (slope / 113) + (course_rating course_par)
course_par = sum(hole_pars.get(h, 0) for h in holes if h in hole_pars)
playing_handicaps: dict[str, int | None] = {}
for p in players:
hc = p.get("handicap_snapshot")
slope = p.get("slope")
rating = p.get("tee_rating")
if hc is not None and slope and rating and course_par:
playing_handicaps[p["id"]] = round(hc * (slope / 113) + (rating - course_par))
else:
playing_handicaps[p["id"]] = None
# Strokes received per player per hole (requires stroke index data on course)
strokes_per_hole: dict[str, dict[int, int]] = {}
played_with_si = {h: hole_stroke_indices[h] for h in holes if h in hole_stroke_indices}
if played_with_si:
n_si = len(played_with_si)
for p in players:
ph = playing_handicaps.get(p["id"])
if ph is not None and ph > 0:
base, extra = divmod(ph, n_si)
strokes_per_hole[p["id"]] = {
h: base + (1 if played_with_si[h] <= extra else 0)
for h in holes if h in played_with_si
}
skins_won, skins_hole_results, unclaimed = None, None, 0
if game["format"] == "skins":
carryover = bool(game["carryover"])
@@ -291,8 +317,9 @@ async def game_summary(game_id: str, request: Request, user: dict = Depends(get_
return templates.TemplateResponse("games/summary.html", {
"request": request, "user": user, "game": dict(game),
"players": players, "scores": scores, "totals": totals,
"holes": holes, "hole_pars": hole_pars,
"holes": holes, "hole_pars": hole_pars, "hole_stroke_indices": hole_stroke_indices,
"results": results,
"playing_handicaps": playing_handicaps, "strokes_per_hole": strokes_per_hole,
"skins_won": skins_won, "skins_hole_results": skins_hole_results, "unclaimed": unclaimed,
"carryover": bool(game["carryover"]),
})