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 %} +