diff --git a/app/routers/games.py b/app/routers/games.py index 1422a6a..8d8346e 100644 --- a/app/routers/games.py +++ b/app/routers/games.py @@ -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"]), }) diff --git a/app/templates/games/summary.html b/app/templates/games/summary.html index 8d8ed4f..1405dcb 100644 --- a/app/templates/games/summary.html +++ b/app/templates/games/summary.html @@ -48,6 +48,37 @@ {% endif %} + {# Playing handicaps #} + {% if playing_handicaps %} +
+
Playing Handicaps
+ {% for p in players %} +
+ + {% if p.avatar and p.avatar.startswith('/') %} + + {% else %} + {{ p.avatar or '๐Ÿ‘ค' }} + {% endif %} + + {{ p.name }} + {% if p.handicap_snapshot is not none %} + HI {{ p.handicap_snapshot }} + {% endif %} + {% set ph = playing_handicaps.get(p.id) %} + {% if ph is not none %} + HC {{ ph }} + {% else %} + HC โ€” + {% endif %} + {% if p.tee_name %} + {{ p.tee_name }} + {% endif %} +
+ {% endfor %} +
+ {% endif %} + {# Scorecard toggle #}
@@ -85,6 +116,7 @@ {% set s = scores.get(h, {}).get(p.id, {}) %} {% set strokes = s.strokes if s else 0 %} {% set par = hole_pars.get(h, 0) %} + {% set sr = strokes_per_hole.get(p.id, {}).get(h, 0) %} {% if strokes %} {% if par %} @@ -108,6 +140,7 @@ {% else %} โ€” {% endif %} + {% if sr > 0 %}{{ 'ยท' * sr }}{% endif %} {% endfor %} @@ -126,6 +159,15 @@ {{ stroke_total.val or 'โ€”' }} {% endfor %} + {% if playing_handicaps %} + + HC + {% if hole_pars %}{% endif %} + {% for p in players %} + {{ playing_handicaps.get(p.id, 'โ€”') if playing_handicaps.get(p.id) is not none else 'โ€”' }} + {% endfor %} + + {% endif %} @@ -198,6 +240,7 @@ {% set s = scores.get(h, {}).get(p.id, {}) %} {% set strokes = s.strokes if s else 0 %} {% set par = hole_pars.get(h, 0) %} + {% set sr = strokes_per_hole.get(p.id, {}).get(h, 0) %} {% if strokes %} {% set is_winner = hr and hr.winner == p.id %} @@ -211,6 +254,7 @@ {% else %}{{ strokes }}{% endif %} {% else %}{{ strokes }}{% endif %} {% else %}โ€”{% endif %} + {% if sr > 0 %}{{ 'ยท' * sr }}{% endif %} {% endfor %}