Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
36df53b
1
Parent(s): 1c5e162
Automated Deploy: cd556fd391f212447ab1aa05dc0222fb74904345
Browse files
AI-coach-agent/src/ai_coach/swing_report/text.py
CHANGED
|
@@ -213,9 +213,10 @@ def _parse(raw: str, rules: dict[str, str | None], facts: dict) -> dict[str, str
|
|
| 213 |
|
| 214 |
def semantic_problems(text: str, key: str, facts: dict) -> list[str]:
|
| 215 |
"""Reject known scope/rating/uncertainty violations before wording reaches a player."""
|
| 216 |
-
rows = {m["metric_id"]: m for m in facts.get("measurements", [])}
|
| 217 |
group = next((g for g in facts.get("groups", []) if key == "group:" + g["group"]), None)
|
| 218 |
ids = group["metric_ids"] if group else ([key.split(":", 1)[1]] if key.startswith(("result:", "tip:")) else list(rows))
|
|
|
|
| 219 |
selected = [rows[k] for k in ids if k in rows]
|
| 220 |
problems = []
|
| 221 |
t = text.lower()
|
|
@@ -348,8 +349,10 @@ def model_facts(report: dict[str, Any], findings: dict[str, str | None], subject
|
|
| 348 |
"meaning": m["what_it_means"], "tip_wanted": m["metric_id"] in tips_wanted}
|
| 349 |
for m in report["measurements"] if m["rating"] != "not_rated"
|
| 350 |
]
|
|
|
|
| 351 |
groups = [
|
| 352 |
-
{"group": g["group"], "name": "Measured movements", "rating": g["rating"],
|
|
|
|
| 353 |
"approximate": g["score_is_tentative"]}
|
| 354 |
for g in report["groups"] if g["group"] in groups_wanted
|
| 355 |
]
|
|
|
|
| 213 |
|
| 214 |
def semantic_problems(text: str, key: str, facts: dict) -> list[str]:
|
| 215 |
"""Reject known scope/rating/uncertainty violations before wording reaches a player."""
|
| 216 |
+
rows = {m["metric_id"]: m for m in facts.get("measurements", []) if m.get("rating") != "not_rated"}
|
| 217 |
group = next((g for g in facts.get("groups", []) if key == "group:" + g["group"]), None)
|
| 218 |
ids = group["metric_ids"] if group else ([key.split(":", 1)[1]] if key.startswith(("result:", "tip:")) else list(rows))
|
| 219 |
+
ids = [key for key in ids if key in rows]
|
| 220 |
selected = [rows[k] for k in ids if k in rows]
|
| 221 |
problems = []
|
| 222 |
t = text.lower()
|
|
|
|
| 349 |
"meaning": m["what_it_means"], "tip_wanted": m["metric_id"] in tips_wanted}
|
| 350 |
for m in report["measurements"] if m["rating"] != "not_rated"
|
| 351 |
]
|
| 352 |
+
measured_ids = {m["metric_id"] for m in measurements}
|
| 353 |
groups = [
|
| 354 |
+
{"group": g["group"], "name": "Measured movements", "rating": g["rating"],
|
| 355 |
+
"metric_ids": [key for key in g["metric_ids"] if key in measured_ids],
|
| 356 |
"approximate": g["score_is_tentative"]}
|
| 357 |
for g in report["groups"] if g["group"] in groups_wanted
|
| 358 |
]
|
AI-coach-agent/tests/test_swing_report_evidence_scope.py
CHANGED
|
@@ -30,6 +30,15 @@ def test_early_shoulder_turn_does_not_validate_entire_finish():
|
|
| 30 |
'group:contact_follow_through', f)
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def test_unknown_context_never_calls_model_for_free_form_technique_advice():
|
| 34 |
def forbidden(*_):
|
| 35 |
raise AssertionError('No model advice is justified for an unknown drill.')
|
|
|
|
| 30 |
'group:contact_follow_through', f)
|
| 31 |
|
| 32 |
|
| 33 |
+
def test_unrated_metric_name_cannot_authorize_a_follow_through_claim():
|
| 34 |
+
f = facts()
|
| 35 |
+
f['groups'][0]['metric_ids'].append('shoulder_rotation_after_contact')
|
| 36 |
+
text = 'Your estimated early shoulder turn during follow-through is in the typical range.'
|
| 37 |
+
assert 'unmeasured_follow_through' in semantic_problems(text, 'group:contact_follow_through', f)
|
| 38 |
+
f['measurements'].append({'metric_id': 'shoulder_rotation_after_contact', 'rating': 'not_rated'})
|
| 39 |
+
assert 'unmeasured_follow_through' in semantic_problems(text, 'group:contact_follow_through', f)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
def test_unknown_context_never_calls_model_for_free_form_technique_advice():
|
| 43 |
def forbidden(*_):
|
| 44 |
raise AssertionError('No model advice is justified for an unknown drill.')
|
AI-coach-agent/tests/test_swing_report_report.py
CHANGED
|
@@ -11,7 +11,7 @@ from ai_coach.config import Settings
|
|
| 11 |
from ai_coach.schemas import Usage
|
| 12 |
from ai_coach.swing_report import AthleteContext, InvalidPayload, build_report
|
| 13 |
from ai_coach.swing_report import repository as repo
|
| 14 |
-
from ai_coach.swing_report.text import check_text
|
| 15 |
|
| 16 |
from .test_swing_report_validation import payload, with_contact
|
| 17 |
|
|
@@ -129,6 +129,9 @@ def test_partially_measured_group_does_not_claim_complete_coverage():
|
|
| 129 |
assert g["score"] == 100 # missing separation is excluded, not counted as zero
|
| 130 |
assert "only part of this phase" in g["summary"]
|
| 131 |
assert "partial_measurement_coverage" in {n["code"] for n in r["data_quality"]}
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
def test_invalid_payload_raises_with_paths():
|
|
|
|
| 11 |
from ai_coach.schemas import Usage
|
| 12 |
from ai_coach.swing_report import AthleteContext, InvalidPayload, build_report
|
| 13 |
from ai_coach.swing_report import repository as repo
|
| 14 |
+
from ai_coach.swing_report.text import check_text, model_facts
|
| 15 |
|
| 16 |
from .test_swing_report_validation import payload, with_contact
|
| 17 |
|
|
|
|
| 129 |
assert g["score"] == 100 # missing separation is excluded, not counted as zero
|
| 130 |
assert "only part of this phase" in g["summary"]
|
| 131 |
assert "partial_measurement_coverage" in {n["code"] for n in r["data_quality"]}
|
| 132 |
+
facts = model_facts(r, {m['metric_id']: m['result_text'] for m in r['measurements']},
|
| 133 |
+
{g['group']: g['display_name'] for g in r['groups']}, set(), ['stride'])
|
| 134 |
+
assert facts['groups'][0]['metric_ids'] == ['stride_relative_length']
|
| 135 |
|
| 136 |
|
| 137 |
def test_invalid_payload_raises_with_paths():
|