github-actions[bot] commited on
Commit
659d1d9
·
1 Parent(s): af23af0

Automated Deploy: 0a12cc2b74651190f56408d4885da0f57257bac3

Browse files
AI-coach-agent/src/ai_coach/pitch_report/v1_1/coaching.py CHANGED
@@ -85,6 +85,11 @@ inconsistency flags uncertainty from tracking OR smoothing, not a confirmed trac
85
  attached to its own measurement; do not combine different missing-data causes into one explanation for all results.
86
  A model-estimated distance cannot establish an overlong stride. A single separation angle cannot establish early
87
  opening. Knee straightening is not a measurement of force or an effective block. Torso lean is not balance.
 
 
 
 
 
88
  The rotation headings use an arbitrary coordinate basis: target/catcher direction and 'open/closed' positions were
89
  NOT measured. Describe relative pelvis/shoulder movement only; never say either turned toward the target from
90
  these headings. Do not warn of over-rotation, early opening, or prescribe keeping the chest/shoulders closed.
@@ -147,6 +152,42 @@ REASON_MEANINGS = {
147
  ),
148
  }
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  def _with_reason_meanings(data):
152
  data["reason_meanings"] = {r: REASON_MEANINGS[r] for r in data.get("reasons", []) if r in REASON_MEANINGS}
@@ -169,6 +210,7 @@ def facts_for(p, rubric):
169
  }
170
  for m in p.measurements:
171
  data = _with_reason_meanings(m.model_dump(mode="json"))
 
172
  if m.metric_id == "lead_knee_extension_to_release":
173
  interval = m.value_interval
174
  data["direction_supported"] = (
@@ -180,7 +222,13 @@ def facts_for(p, rubric):
180
  )
181
  facts["measurement:" + m.metric_id] = data
182
  for key, e in p.events:
183
- facts["event:" + key] = _with_reason_meanings(e.model_dump(mode="json"))
 
 
 
 
 
 
184
  for item in rubric["criteria"]:
185
  facts["criterion:" + item["criterion_id"]] = item
186
  if p.delivery_evidence:
@@ -192,6 +240,7 @@ def facts_for(p, rubric):
192
  # Do not let phase summaries bypass scalar event reliability gates.
193
  for motion in phase_data["motion"]:
194
  _with_reason_meanings(motion)
 
195
  if motion["change"] is None:
196
  motion.update(start_value=None, end_value=None, minimum=None, maximum=None)
197
  facts["phase:" + phase.phase] = phase_data
@@ -285,6 +334,52 @@ def _quality_reason_issues(prose, facts):
285
  r"\b(?:could not|cannot|can't) (?:be (?:calculated|computed)|calculate|compute)\b(?! reliably)", clause, re.I
286
  ):
287
  problems.append("withheld_estimate_not_calculation_failure")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  return problems
289
 
290
 
@@ -322,6 +417,7 @@ def _check_content(summary, cards, facts):
322
  problems.extend(_knee_direction_issues(c.observation, cited_facts))
323
  problems.extend(_quality_reason_issues(" ".join((c.observation, c.why_it_matters, c.next_step, c.check)), cited_facts))
324
  prose = " ".join([summary] + [getattr(c, k) for c in cards for k in ("observation", "why_it_matters", "next_step", "check")])
 
325
  quantities = re.sub(r"\b[23][dD]\b", "", prose)
326
  quantities = re.sub(r"\b(?:two|three) (?:frames|marks|moments|images|checks|steps)\b", "", quantities, flags=re.I)
327
  if re.search(r"\d", quantities):
 
85
  attached to its own measurement; do not combine different missing-data causes into one explanation for all results.
86
  A model-estimated distance cannot establish an overlong stride. A single separation angle cannot establish early
87
  opening. Knee straightening is not a measurement of force or an effective block. Torso lean is not balance.
88
+ Read each measurement's interpretation and each event's definition literally. Torso inclination is total angle
89
+ away from upright; it does not distinguish forward, backward, or sideways tilt. Describe only its magnitude or
90
+ supported increase/decrease, including in the summary, explanations and review actions. Foot strike means the
91
+ marked first visible front-foot touch, not a completely grounded foot or full-sole contact. Review that first
92
+ touch; do not ask for the whole foot to be grounded at that frame. Ankle spacing is not distance travelled.
93
  The rotation headings use an arbitrary coordinate basis: target/catcher direction and 'open/closed' positions were
94
  NOT measured. Describe relative pelvis/shoulder movement only; never say either turned toward the target from
95
  these headings. Do not warn of over-rotation, early opening, or prescribe keeping the chest/shoulders closed.
 
152
  ),
153
  }
154
 
155
+ MEASUREMENT_INTERPRETATIONS = {
156
+ "torso_angle_from_vertical": (
157
+ "Unsigned magnitude of the hip-to-shoulder line's angle away from upright. "
158
+ "Does not distinguish forward, backward or sideways tilt; only magnitude is measured."
159
+ ),
160
+ "capture_time_difference": "Elapsed documented recording time between the marks, not exported playback duration.",
161
+ "horizontal_ankle_to_ankle_distance": (
162
+ "Call this ankle spacing: horizontal spacing between ankle centres at the marked moment, not stride travel, "
163
+ "step length, specifically lateral stance width or full-foot contact."
164
+ ),
165
+ "180_minus_3d_joint_angle": (
166
+ "Joint bend at one marked moment; zero means straight. A single angle does not show a change, force or speed."
167
+ ),
168
+ "signed_horizontal_shoulder_minus_hip_heading": (
169
+ "Relative horizontal shoulder-minus-hip heading; no target direction, open/closed position "
170
+ "or rotation quality is measured."
171
+ ),
172
+ "change_in_3d_joint_angle": (
173
+ "Front-knee joint-angle change from marked foot strike to release; positive means straightening. "
174
+ "Use direction_supported for a movement claim; no bracing, force or block effectiveness is measured."
175
+ ),
176
+ "absolute_net_horizontal_rotation": (
177
+ "Magnitude of net shoulder-heading change within the defined early finish window, not total turn or rotation speed."
178
+ ),
179
+ }
180
+ CURVE_INTERPRETATIONS = {
181
+ "torso_inclination": MEASUREMENT_INTERPRETATIONS["torso_angle_from_vertical"],
182
+ "front_knee_flexion": "Front-knee bend angle; decreasing flexion means straightening, not force or an effective block.",
183
+ "throwing_elbow_flexion": "Throwing-elbow bend angle, not joint load, arm speed or injury risk.",
184
+ "hip_shoulder_separation": MEASUREMENT_INTERPRETATIONS["signed_horizontal_shoulder_minus_hip_heading"],
185
+ "pelvis_heading": "Horizontal hip heading in an arbitrary basis; no target direction or open/closed position is measured.",
186
+ "shoulder_heading": (
187
+ "Horizontal chest heading in an arbitrary basis; no target direction or open/closed position is measured."
188
+ ),
189
+ }
190
+
191
 
192
  def _with_reason_meanings(data):
193
  data["reason_meanings"] = {r: REASON_MEANINGS[r] for r in data.get("reasons", []) if r in REASON_MEANINGS}
 
210
  }
211
  for m in p.measurements:
212
  data = _with_reason_meanings(m.model_dump(mode="json"))
213
+ data["interpretation"] = MEASUREMENT_INTERPRETATIONS[m.reference]
214
  if m.metric_id == "lead_knee_extension_to_release":
215
  interval = m.value_interval
216
  data["direction_supported"] = (
 
222
  )
223
  facts["measurement:" + m.metric_id] = data
224
  for key, e in p.events:
225
+ event = _with_reason_meanings(e.model_dump(mode="json"))
226
+ if key == "foot_strike":
227
+ event["definition"] = (
228
+ "Approximate caller-marked first visible front-foot touch at the end of the stride. "
229
+ "Not full-sole contact, a completely grounded foot, continuous contact, or measured ground force."
230
+ )
231
+ facts["event:" + key] = event
232
  for item in rubric["criteria"]:
233
  facts["criterion:" + item["criterion_id"]] = item
234
  if p.delivery_evidence:
 
240
  # Do not let phase summaries bypass scalar event reliability gates.
241
  for motion in phase_data["motion"]:
242
  _with_reason_meanings(motion)
243
+ motion["interpretation"] = CURVE_INTERPRETATIONS[motion["curve_id"]]
244
  if motion["change"] is None:
245
  motion.update(start_value=None, end_value=None, minimum=None, maximum=None)
246
  facts["phase:" + phase.phase] = phase_data
 
334
  r"\b(?:could not|cannot|can't) (?:be (?:calculated|computed)|calculate|compute)\b(?! reliably)", clause, re.I
335
  ):
336
  problems.append("withheld_estimate_not_calculation_failure")
337
+ relevant = [
338
+ facts[k]
339
+ for k in ("measurement:lead_knee_extension_to_release", "measurement:throwing_elbow_flexion_at_release")
340
+ if k in facts and "reasons" in facts[k]
341
+ ]
342
+ if len(relevant) == 2 and any("event_angle_unstable" not in f["reasons"] for f in relevant):
343
+ for clause in re.split(r"[.;!?]|\b(?:while|whereas)\b", prose, flags=re.I):
344
+ combined = re.search(r"\b(?:these|both) (?:estimates|measurements|angles|results)\b", clause, re.I)
345
+ combined = combined or (
346
+ re.search(r"\b(?:front|lead) (?:knee|leg)\b", clause, re.I) and re.search(r"\belbow\b", clause, re.I)
347
+ )
348
+ sensitivity = re.search(
349
+ r"(?:neighbor\w*|adjacent|event mark).{0,100}too much|event (?:timing|angle) sensitivity", clause, re.I
350
+ )
351
+ if combined and sensitivity:
352
+ problems.append("shared_event_sensitivity_cause_not_supported")
353
+ return problems
354
+
355
+
356
+ def _definition_issues(prose):
357
+ problems = []
358
+ if re.search(
359
+ r"\b(?:lateral|sideways) (?:ankle|stance) (?:spacing|width)\b"
360
+ r"|\b(?:estimated|measured) stride (?:length|distance)\b",
361
+ prose,
362
+ re.I,
363
+ ):
364
+ problems.append("ankle_spacing_does_not_measure_stride_travel_or_lateral_width")
365
+ directional_torso = (
366
+ r"\b(?:forward|backward|lateral|sideways) (?:torso|chest|trunk) (?:tilt|lean|motion|movement|inclination)\b"
367
+ r"|\b(?:torso|chest|trunk)(?: (?:inclination|tilt|lean|motion|movement|leans?|tilts?|moves?|is|was|estimated)){0,4} "
368
+ r"(?:forward|backward|laterally|sideways)\b"
369
+ )
370
+ for match in re.finditer(directional_torso, prose, re.I):
371
+ before = prose[max(0, match.start() - 60) : match.start()]
372
+ if not re.search(r"(?:does not|cannot) (?:measure|establish|show|confirm|determine) $", before, re.I):
373
+ problems.append("torso_inclination_does_not_measure_direction")
374
+ plant = (
375
+ r"\b(?:fully|completely|entirely) (?:grounded|planted|flat|in contact)\b"
376
+ r"|\b(?:whole|entire|full) (?:front |lead )?foot\b.{0,35}\b(?:ground|contact|plant)\w*\b"
377
+ r"|\b(?:front|lead) foot (?:is |be |stays? |remains? )?flat\b"
378
+ )
379
+ for match in re.finditer(plant, prose, re.I):
380
+ before = prose[max(0, match.start() - 60) : match.start()]
381
+ if not re.search(r"(?:not|does not require|does not mean) (?:a |an |the )?$", before, re.I):
382
+ problems.append("foot_strike_is_first_touch_not_full_foot_plant")
383
  return problems
384
 
385
 
 
417
  problems.extend(_knee_direction_issues(c.observation, cited_facts))
418
  problems.extend(_quality_reason_issues(" ".join((c.observation, c.why_it_matters, c.next_step, c.check)), cited_facts))
419
  prose = " ".join([summary] + [getattr(c, k) for c in cards for k in ("observation", "why_it_matters", "next_step", "check")])
420
+ problems.extend(_definition_issues(prose))
421
  quantities = re.sub(r"\b[23][dD]\b", "", prose)
422
  quantities = re.sub(r"\b(?:two|three) (?:frames|marks|moments|images|checks|steps)\b", "", quantities, flags=re.I)
423
  if re.search(r"\d", quantities):
AI-coach-agent/tests/test_pitching_coaching.py CHANGED
@@ -576,3 +576,100 @@ def test_recording_action_cannot_promise_stable_tracking_from_mark_sensitivity()
576
  [],
577
  sensitivity_facts(),
578
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  [],
577
  sensitivity_facts(),
578
  )
579
+
580
+
581
+ @pytest.mark.parametrize("field", ["summary", "observation", "why_it_matters", "next_step", "check"])
582
+ @pytest.mark.parametrize("claim", ["Your forward torso tilt into release is estimated.", "Torso forward motion increases."])
583
+ def test_total_torso_inclination_never_becomes_direction_in_any_prose_field(field, claim):
584
+ from ai_coach.pitch_report.v1_1.coaching import Draft, check_draft
585
+
586
+ candidate = draft()
587
+ if field == "summary":
588
+ candidate[field] = claim
589
+ else:
590
+ candidate["cards"][0][field] = claim
591
+ assert "torso_inclination_does_not_measure_direction" in check_draft(
592
+ Draft.model_validate(candidate), {"measurement:lead_knee_extension_to_release": {"value": 30}}
593
+ )
594
+
595
+
596
+ def test_supported_torso_magnitude_change_does_not_require_forward_direction():
597
+ from ai_coach.pitch_report.v1_1.coaching import Draft, check_draft
598
+
599
+ candidate = draft()
600
+ candidate["summary"] = "Your estimated total torso tilt increases between the marked plant and release."
601
+ candidate["cards"][0].update(
602
+ observation="Between foot strike and ball release, your torso inclination increases toward release.",
603
+ why_it_matters="This describes the total angle away from upright without establishing tilt direction.",
604
+ next_step="Review the marked moments alongside the estimated total torso tilt.",
605
+ check="Check how the magnitude changes between those marked moments.",
606
+ evidence_ids=["phase:plant_to_release"],
607
+ )
608
+ assert not check_draft(
609
+ Draft.model_validate(candidate),
610
+ {"phase:plant_to_release": {"motion": [{"curve_id": "torso_inclination", "change": 12.0}]}},
611
+ )
612
+
613
+
614
+ @pytest.mark.parametrize("field", ["summary", "observation", "why_it_matters", "next_step", "check"])
615
+ def test_first_touch_event_never_requires_full_foot_contact_in_any_prose_field(field):
616
+ from ai_coach.pitch_report.v1_1.coaching import Draft, check_draft
617
+
618
+ candidate = draft()
619
+ claim = "Inspect whether your front foot is completely grounded at the marked plant frame."
620
+ if field == "summary":
621
+ candidate[field] = claim
622
+ else:
623
+ candidate["cards"][0][field] = claim
624
+ assert "foot_strike_is_first_touch_not_full_foot_plant" in check_draft(
625
+ Draft.model_validate(candidate), {"measurement:lead_knee_extension_to_release": {"value": 30}}
626
+ )
627
+
628
+
629
+ def test_first_visible_touch_review_remains_supported():
630
+ from ai_coach.pitch_report.v1_1.coaching import _check_content
631
+
632
+ assert not _check_content(
633
+ "Inspect the first visible front-foot touch at the marked plant frame. "
634
+ "The event does not require a completely grounded foot.",
635
+ [],
636
+ sensitivity_facts(),
637
+ )
638
+
639
+
640
+ def test_combined_knee_elbow_cause_must_be_supported_for_each_measurement():
641
+ from ai_coach.pitch_report.v1_1.coaching import _check_content
642
+
643
+ # The step-back elbow carries temporal/sensitivity-unresolved reasons;
644
+ # the knee alone carries event_angle_unstable.
645
+ facts = sensitivity_facts()
646
+ elbow = facts["measurement:throwing_elbow_flexion_at_release"]
647
+ elbow["reasons"].append("angle_sensitivity_unresolved")
648
+ cause = (
649
+ "A braced front leg is a standard rocker drill focus, but changing an event mark to a neighboring "
650
+ "frame shifts these estimates too much to report reliably."
651
+ )
652
+ assert "shared_event_sensitivity_cause_not_supported" in _check_content(cause, [], facts)
653
+ elbow["reasons"] = ["event_angle_unstable"]
654
+ assert "shared_event_sensitivity_cause_not_supported" not in _check_content(cause, [], facts)
655
+
656
+
657
+ def test_metric_and_event_facts_define_scope_explicitly():
658
+ facts = sensitivity_facts()
659
+ assert "Does not distinguish forward" in facts["measurement:torso_inclination_at_release"]["interpretation"]
660
+ assert "not stride travel" in facts["measurement:ankle_span_at_foot_strike_cm"]["interpretation"]
661
+ assert "first visible front-foot touch" in facts["event:foot_strike"]["definition"]
662
+ assert "Not full-sole contact" in facts["event:foot_strike"]["definition"]
663
+
664
+
665
+ @pytest.mark.parametrize(
666
+ "claim",
667
+ [
668
+ "Your lateral stance width is available as an estimate.",
669
+ "Your estimated stride length describes your plant position.",
670
+ ],
671
+ )
672
+ def test_horizontal_ankle_spacing_is_not_lateral_width_or_travel(claim):
673
+ from ai_coach.pitch_report.v1_1.coaching import _check_content
674
+
675
+ assert "ankle_spacing_does_not_measure_stride_travel_or_lateral_width" in _check_content(claim, [], sensitivity_facts())
baseball_batting/api.py CHANGED
@@ -78,7 +78,7 @@ def create_app(settings=None, service=None):
78
  service.start()
79
  try: yield
80
  finally: service.stop()
81
- app = FastAPI(title="Baseball Motion Engine and Coach", version="1.21.6", lifespan=lifespan,
82
  description="GPU batting/load timing with separate bat keypoint and baseball models. Single-view visual contact; physical miss/shift require synchronized calibrated views. Accuracy validation pending.")
83
  app.state.service = service
84
  app.add_middleware(UploadGuard, settings=settings, service=service)
 
78
  service.start()
79
  try: yield
80
  finally: service.stop()
81
+ app = FastAPI(title="Baseball Motion Engine and Coach", version="1.21.7", lifespan=lifespan,
82
  description="GPU batting/load timing with separate bat keypoint and baseball models. Single-view visual contact; physical miss/shift require synchronized calibrated views. Accuracy validation pending.")
83
  app.state.service = service
84
  app.add_middleware(UploadGuard, settings=settings, service=service)
docs/PITCHING_VALIDATION.md CHANGED
@@ -20,7 +20,9 @@ Release 1.21.5 source `c6740dc30c6da8c1add9680c0c571ec78bec8366` passed [source
20
 
21
  Both original videos then completed fresh SAM3D analysis and real Gemini coaching through the backend. Step-back job `1d24f619590e4d40a76ce485c30d0b88` and rocker job `ac33677dd38543d2846271c421fcf26b` passed input hashes, implementation/artifact hashes, whole-motion replay, immutable JSON forwarding, idempotence, saved-report and API-audit checks. Both coach payloads and reports have null visual evidence; all numeric performance scores are null. The step-back returned a supported subset after rejecting other cards; the rocker returned four cards after bounded repair.
22
 
23
- Manual evidence review supported the retained movement descriptions but found two wording problems: the step-back summary attributed event-mark sensitivity to unstable tracking, and the rocker suggested generic file metadata could confirm capture speed. These are not clean content-acceptance results. The 1.21.6 follow-up passed 747 coach tests (one skipped, twelve live tests excluded) and all 32 targeted engine pitching tests. It adds explicit reason meanings and rejects those causal/provenance claims. It also distinguishes a withheld estimate from an impossible calculation and a nominal unavailable knee measurement from an affirmative movement claim. The fresh ML results remain unchanged; final coaching-only refresh results will be recorded after deployment. A green deployment is not a content-accuracy result.
 
 
24
 
25
  ## Historical validation record
26
 
 
20
 
21
  Both original videos then completed fresh SAM3D analysis and real Gemini coaching through the backend. Step-back job `1d24f619590e4d40a76ce485c30d0b88` and rocker job `ac33677dd38543d2846271c421fcf26b` passed input hashes, implementation/artifact hashes, whole-motion replay, immutable JSON forwarding, idempotence, saved-report and API-audit checks. Both coach payloads and reports have null visual evidence; all numeric performance scores are null. The step-back returned a supported subset after rejecting other cards; the rocker returned four cards after bounded repair.
22
 
23
+ Manual evidence review supported the retained movement descriptions but found two wording problems: the step-back summary attributed event-mark sensitivity to unstable tracking, and the rocker suggested generic file metadata could confirm capture speed. These are not clean content-acceptance results. The 1.21.6 follow-up passed 747 coach tests (one skipped, twelve live tests excluded) and all 32 targeted engine pitching tests. It adds explicit reason meanings and rejects those causal/provenance claims. It also distinguishes a withheld estimate from an impossible calculation and a nominal unavailable knee measurement from an affirmative movement claim. Coaching-only refresh under source `08eecdabd85d69c2641e9d7d7685e50a72849863` preserved measurements, motion, IDs, analysis timestamps and quota, with matching saved reports and refresh audits. The step-back passed scoped evidence review. The rocker's original timing wording was corrected, but its new summary introduced unsupported “forward” torso tilt from an unsigned inclination metric, and its contact check asked for a completely grounded foot instead of first visible touch. These failures are preserved separately; automated critique alone did not catch them.
24
+
25
+ The 1.21.7 follow-up passed 768 coach tests (one skipped, twelve live tests excluded) and all 32 targeted engine pitching tests. It supplies explicit metric-reference and event definitions and rejects these mismatches across all returned prose. Final deployment and refreshed-report results will be recorded after verification. The fresh ML calculations remain unchanged. A green deployment is not a content-accuracy result.
26
 
27
  ## Historical validation record
28