Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
1b49b17
1
Parent(s): be69d1e
Automated Deploy: 98827e691fefaeca9bbd5f42f571eede3241eb48
Browse files
AI-coach-agent/docs/SWING_REPORT_API.md
CHANGED
|
@@ -231,7 +231,9 @@ A measurement's score depends on how far its value sits outside the on-target in
|
|
| 231 |
|---|---|
|
| 232 |
| Inside P25 to P75 (`d = 0`) | 100 |
|
| 233 |
| Between P25/P75 and P10/P90 (`d <= w`) | `100 - 30 * d / w`, which reaches 70 at P10 or P90 |
|
| 234 |
-
| Beyond P10/P90 (`d > w`) | `70 - 70 * (d - w) / (2 *
|
|
|
|
|
|
|
| 235 |
|
| 236 |
Scores are rounded to whole numbers (half up). A value outside P25 to P75 never scores more than 99, and a value outside P10 to P90 never scores more than 69, so the rating read from the score always matches where the value sits. Group and overall means follow the same rule: 100 only when every score is 100.
|
| 237 |
- **Measurement score:** as above. It is null when the measurement is not rated.
|
|
|
|
| 231 |
|---|---|
|
| 232 |
| Inside P25 to P75 (`d = 0`) | 100 |
|
| 233 |
| Between P25/P75 and P10/P90 (`d <= w`) | `100 - 30 * d / w`, which reaches 70 at P10 or P90 |
|
| 234 |
+
| Beyond P10/P90 (`d > w`) | `70 - 70 * (d - w) / (2 * t)`, with a floor of 0, where `t = max(w, 0.45 * (P75 - P25))` |
|
| 235 |
+
|
| 236 |
+
`t` keeps the fall-off from collapsing when P10 is almost equal to P25 (or P90 to P75): without it a value two degrees off target scored 0. `0.45 * (P75 - P25)` is the P75 to P90 gap of a normal distribution with the same P25 to P75, so bands of ordinary shape are unchanged.
|
| 237 |
|
| 238 |
Scores are rounded to whole numbers (half up). A value outside P25 to P75 never scores more than 99, and a value outside P10 to P90 never scores more than 69, so the rating read from the score always matches where the value sits. Group and overall means follow the same rule: 100 only when every score is 100.
|
| 239 |
- **Measurement score:** as above. It is null when the measurement is not rated.
|
AI-coach-agent/src/ai_coach/swing_report/scoring.py
CHANGED
|
@@ -3,6 +3,11 @@
|
|
| 3 |
A value inside P25..P75 scores 100. Between P25/P75 and P10/P90 it loses up to 30 points linearly; beyond P10/P90 it
|
| 4 |
loses the remaining 70 over two more band widths. Scores are rounded half-up, and clamped so that the rating, which is
|
| 5 |
read from the score, always matches where the value sits: 100 only inside P25..P75, 70..99 only inside P10..P90.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
from __future__ import annotations
|
|
@@ -13,6 +18,9 @@ from collections.abc import Iterable
|
|
| 13 |
ON_TARGET, SATISFACTORY, OFF_TARGET, NOT_RATED = "on_target", "satisfactory", "off_target", "not_rated"
|
| 14 |
RATING_LABELS = {ON_TARGET: "On Target", SATISFACTORY: "Satisfactory", OFF_TARGET: "Off Target"}
|
| 15 |
SATISFACTORY_FLOOR = 70
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def round_half_up(x: float) -> int:
|
|
@@ -34,11 +42,12 @@ def raw_score(value: float, on_lower: float, on_upper: float, sat_lower: float,
|
|
| 34 |
return 100.0
|
| 35 |
d = value - on_upper if side == "above" else on_lower - value
|
| 36 |
w = sat_upper - on_upper if side == "above" else on_lower - sat_lower
|
| 37 |
-
if
|
| 38 |
-
return 0.0
|
| 39 |
-
if d <= w:
|
| 40 |
return 100.0 - 30.0 * d / w
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def score(value: float, on_lower: float, on_upper: float, sat_lower: float, sat_upper: float) -> int:
|
|
|
|
| 3 |
A value inside P25..P75 scores 100. Between P25/P75 and P10/P90 it loses up to 30 points linearly; beyond P10/P90 it
|
| 4 |
loses the remaining 70 over two more band widths. Scores are rounded half-up, and clamped so that the rating, which is
|
| 5 |
read from the score, always matches where the value sits: 100 only inside P25..P75, 70..99 only inside P10..P90.
|
| 6 |
+
|
| 7 |
+
The band width beyond P10/P90 has a floor. Some reference groups have P10 almost equal to P25 (a gap of a fraction
|
| 8 |
+
of a degree), which made the score fall from 70 to 0 within that fraction: a value two degrees off target scored 0
|
| 9 |
+
and pulled its group and the overall score down. The floor is the gap a normal distribution with the same P25..P75
|
| 10 |
+
would have, so only unusually narrow bands change.
|
| 11 |
"""
|
| 12 |
|
| 13 |
from __future__ import annotations
|
|
|
|
| 18 |
ON_TARGET, SATISFACTORY, OFF_TARGET, NOT_RATED = "on_target", "satisfactory", "off_target", "not_rated"
|
| 19 |
RATING_LABELS = {ON_TARGET: "On Target", SATISFACTORY: "Satisfactory", OFF_TARGET: "Off Target"}
|
| 20 |
SATISFACTORY_FLOOR = 70
|
| 21 |
+
# (z90 - z75) / (z75 - z25) for a normal distribution = (1.2816 - 0.6745) / 1.3490: the P75..P90 gap as a share of
|
| 22 |
+
# the P25..P75 width.
|
| 23 |
+
NORMAL_TAIL_SHARE = 0.45
|
| 24 |
|
| 25 |
|
| 26 |
def round_half_up(x: float) -> int:
|
|
|
|
| 42 |
return 100.0
|
| 43 |
d = value - on_upper if side == "above" else on_lower - value
|
| 44 |
w = sat_upper - on_upper if side == "above" else on_lower - sat_lower
|
| 45 |
+
if 0 < d <= w:
|
|
|
|
|
|
|
| 46 |
return 100.0 - 30.0 * d / w
|
| 47 |
+
tail = max(w, NORMAL_TAIL_SHARE * (on_upper - on_lower)) # see the module docstring
|
| 48 |
+
if tail <= 0: # P25 = P75 = P10/P90: there is no width to measure the miss against
|
| 49 |
+
return 0.0
|
| 50 |
+
return max(0.0, 70.0 - 70.0 * (d - max(w, 0.0)) / (2.0 * tail))
|
| 51 |
|
| 52 |
|
| 53 |
def score(value: float, on_lower: float, on_upper: float, sat_lower: float, sat_upper: float) -> int:
|
AI-coach-agent/tests/test_swing_report_scoring.py
CHANGED
|
@@ -51,9 +51,22 @@ def test_side():
|
|
| 51 |
assert side_of(-10, -25.3, -8.5) is None
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def test_degenerate_band():
|
| 55 |
-
|
| 56 |
-
assert score(
|
|
|
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
def test_mean_score():
|
|
|
|
| 51 |
assert side_of(-10, -25.3, -8.5) is None
|
| 52 |
|
| 53 |
|
| 54 |
+
def test_narrow_band_does_not_collapse_to_zero():
|
| 55 |
+
# P10 almost equals P25 (real case: torso inclination at contact, on target 23.757..28.781, P10 23.44).
|
| 56 |
+
band = (23.757, 28.781, 23.44, 31.166)
|
| 57 |
+
assert score(23.5, *band) == 76 # inside P10..P25: unchanged
|
| 58 |
+
assert score(23.44, *band) == 70 # at P10: unchanged
|
| 59 |
+
assert score(21.7, *band) == 43 # two degrees under target used to score 0
|
| 60 |
+
assert score(18.9, *band) == 0 # still 0 once it is two floored band widths past P10
|
| 61 |
+
# A band of normal shape is not affected by the floor.
|
| 62 |
+
assert score(55.0, 20.0, 40.0, 10.0, 50.0) == 53
|
| 63 |
+
|
| 64 |
+
|
| 65 |
def test_degenerate_band():
|
| 66 |
+
# P10 = P25 and P75 = P90: the fall-off uses the floor (0.45 of the on-target width) instead of dropping to 0.
|
| 67 |
+
assert score(5.0, 0.0, 4.0, 0.0, 4.0) == 51 and score(7.6, 0.0, 4.0, 0.0, 4.0) == 0
|
| 68 |
+
assert score(5.0, 4.0, 4.0, 4.0, 4.0) == 0 # no width at all
|
| 69 |
+
assert score(4.0, 0.0, 4.0, 0.0, 4.0) == 100
|
| 70 |
|
| 71 |
|
| 72 |
def test_mean_score():
|