Spaces:
Running on T4
Running on T4
github-actions[bot] commited on
Commit ·
a8788e5
1
Parent(s): 659d1d9
Automated Deploy: cd4424ce2a68698c73b0041b0afa5d89d0c6a680
Browse files- AI-coach-agent/src/ai_coach/knowledge/pitch_v1_1_coaching.yaml +258 -0
- AI-coach-agent/src/ai_coach/pitch_report/v1_1/service.py +193 -129
- AI-coach-agent/tests/test_pitching_report.py +83 -14
- backend/app/integrations/pitching_reports.py +44 -0
- backend/app/main.py +14 -6
- backend/app/modules/coach/repository.py +2 -0
- backend/app/modules/coach/service.py +5 -0
- backend/app/modules/sessions/service.py +7 -2
- backend/app/modules/sessions/summary.py +9 -7
- backend/app/modules/swing_reports/controller.py +2 -2
- backend/app/modules/swing_reports/service.py +1 -6
- backend/docs/FRONTEND_INTEGRATION.md +7 -2
- backend/docs/openapi.json +989 -122
- backend/tests/integration/test_pitching_flow.py +4 -2
- backend/tests/integration/test_pitching_openapi.py +118 -0
- backend/tests/integration/test_pitching_report_provenance.py +185 -0
- docs/PITCHING_APP_INTEGRATION.md +100 -7
- docs/PITCHING_VALIDATION.md +10 -4
- tests/test_pitching_api.py +1 -1
AI-coach-agent/src/ai_coach/knowledge/pitch_v1_1_coaching.yaml
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Rules coaching for contract pitch-1.1 (pitch_report/v1_1). Agent-owned; text and drill choices need coach review.
|
| 2 |
+
#
|
| 3 |
+
# `above` / `below` mean the value is above or below the on-target interval in pitching_benchmarks.yaml.
|
| 4 |
+
# mirror_for_right: the reference sign flips with the throwing side (right-handers are negative), so the coaching side
|
| 5 |
+
# is flipped for right-handed pitchers and `above` always means "more of it".
|
| 6 |
+
# Text rules: plain words, no numbers, no good/bad judgements, no claims about speed, control or arm health.
|
| 7 |
+
version: "pitch-1.1-rules-1"
|
| 8 |
+
|
| 9 |
+
headline_focus: "{group} is the area to work on."
|
| 10 |
+
headline_all_on_target: Everything we could rate in this pitch is in the typical range.
|
| 11 |
+
headline_nothing_rated: We could not rate this pitch yet, but you can see what we measured below.
|
| 12 |
+
headline_not_comparable: This kind of drill is not compared with regular pitches, so your results are shown without a rating.
|
| 13 |
+
headline_tentative: These results are close estimates from your video.
|
| 14 |
+
hand_conflict_message: The video and your profile list different throwing arms. Check the side before using these results.
|
| 15 |
+
not_comparable_message: This drill or pitch changes how you throw on purpose. So we show your results, but we do not change your pitch.
|
| 16 |
+
|
| 17 |
+
general_focus:
|
| 18 |
+
display_name: General practice
|
| 19 |
+
coach_message: We could not rate this pitch yet. Keep building a smooth, steady delivery with this drill, and film
|
| 20 |
+
again from the side with your whole body in view.
|
| 21 |
+
practice_feel: Count your rhythm the same way on every delivery.
|
| 22 |
+
drill_id: pit_12
|
| 23 |
+
|
| 24 |
+
metrics:
|
| 25 |
+
torso_inclination_at_leg_lift:
|
| 26 |
+
in_range_text: Your upper body was set about like most pitchers at the top of your leg lift.
|
| 27 |
+
above:
|
| 28 |
+
result_text: Your upper body leaned more than most pitchers at the top of your leg lift.
|
| 29 |
+
headline: Your upper body leans a lot at the top of your leg lift.
|
| 30 |
+
coach_message: Your upper body leans more than most pitchers at the top of your leg lift. A taller balance
|
| 31 |
+
point makes it easier to move to the plate the same way each time.
|
| 32 |
+
coach_tip: Stand tall over your back leg at the top of your lift.
|
| 33 |
+
practice_feel: Lift, stand tall, and pause for a moment.
|
| 34 |
+
drill_id: pit_13
|
| 35 |
+
below:
|
| 36 |
+
result_text: Your upper body stayed more upright than most pitchers at the top of your leg lift.
|
| 37 |
+
headline: Your upper body stays very upright at the top of your leg lift.
|
| 38 |
+
coach_message: Your upper body is more upright than most pitchers at the top of your leg lift. That is fine
|
| 39 |
+
if you stay balanced, so keep your lift steady and repeatable.
|
| 40 |
+
coach_tip: Keep your balance point the same on every pitch.
|
| 41 |
+
practice_feel: Lift, pause, and feel balanced.
|
| 42 |
+
drill_id: pit_02
|
| 43 |
+
maintain:
|
| 44 |
+
coach_message: Your balance point at the top of your leg lift is set like most pitchers. Keep it steady so every
|
| 45 |
+
pitch starts the same way.
|
| 46 |
+
practice_feel: Lift, pause, and feel balanced.
|
| 47 |
+
drill_id: pit_13
|
| 48 |
+
|
| 49 |
+
leg_lift_to_foot_strike_ms:
|
| 50 |
+
in_range_text: Your move from leg lift to landing took about as long as most pitchers.
|
| 51 |
+
above:
|
| 52 |
+
result_text: Your move from leg lift to landing took longer than most pitchers.
|
| 53 |
+
headline: Your move from leg lift to landing is slower than most pitchers.
|
| 54 |
+
coach_message: You take longer than most pitchers to get from leg lift to landing. A steady rhythm toward the
|
| 55 |
+
plate helps you repeat your delivery.
|
| 56 |
+
coach_tip: Count a steady rhythm from lift to landing.
|
| 57 |
+
practice_feel: Lift, then move to the plate on the same count.
|
| 58 |
+
drill_id: pit_12
|
| 59 |
+
below:
|
| 60 |
+
result_text: Your move from leg lift to landing was quicker than most pitchers.
|
| 61 |
+
headline: Your move from leg lift to landing is quicker than most pitchers.
|
| 62 |
+
coach_message: You get from leg lift to landing faster than most pitchers. Finding your balance first can help
|
| 63 |
+
you land in the same spot each time.
|
| 64 |
+
coach_tip: Find your balance at the top before you move.
|
| 65 |
+
practice_feel: Stay back, then go.
|
| 66 |
+
drill_id: pit_13
|
| 67 |
+
maintain:
|
| 68 |
+
coach_message: Your rhythm from leg lift to landing is like most pitchers. Keep the same count on every pitch.
|
| 69 |
+
practice_feel: Count your rhythm the same way on every delivery.
|
| 70 |
+
drill_id: pit_12
|
| 71 |
+
|
| 72 |
+
ankle_span_at_foot_strike_cm:
|
| 73 |
+
in_range_text: Your stride is shown for reference.
|
| 74 |
+
above:
|
| 75 |
+
result_text: Your feet were spread wider than most pitchers when your front foot landed.
|
| 76 |
+
headline: Your stride is longer than most pitchers take.
|
| 77 |
+
coach_message: Your feet are spread wider than most pitchers when you land. Landing on a spot you can hold makes
|
| 78 |
+
your delivery easier to repeat.
|
| 79 |
+
coach_tip: Land on a spot you can hold for a moment.
|
| 80 |
+
practice_feel: Step out, land, and feel balanced.
|
| 81 |
+
drill_id: pit_03
|
| 82 |
+
below:
|
| 83 |
+
result_text: Your feet were closer together than most pitchers when your front foot landed.
|
| 84 |
+
headline: Your stride is shorter than most pitchers take.
|
| 85 |
+
coach_message: Your feet are closer together than most pitchers when you land. Reaching a little farther toward
|
| 86 |
+
the plate gives your body more room to turn.
|
| 87 |
+
coach_tip: Push off and reach your front foot toward the plate.
|
| 88 |
+
practice_feel: Push from your back leg and reach to a line.
|
| 89 |
+
drill_id: pit_01
|
| 90 |
+
maintain:
|
| 91 |
+
coach_message: Your stride is like most pitchers. Keep landing on the same spot each throw.
|
| 92 |
+
practice_feel: Land on the same spot every throw.
|
| 93 |
+
drill_id: pit_03
|
| 94 |
+
|
| 95 |
+
lead_knee_flexion_at_foot_strike:
|
| 96 |
+
in_range_text: Your front knee was bent about like most pitchers when your foot landed.
|
| 97 |
+
above:
|
| 98 |
+
result_text: Your front knee was more bent than most pitchers when your foot landed.
|
| 99 |
+
headline: Your front knee is deeply bent when your foot lands.
|
| 100 |
+
coach_message: Your front knee bends more than most pitchers when you land. Landing on a firmer front leg gives
|
| 101 |
+
your body something to turn over.
|
| 102 |
+
coach_tip: Land with a little bend, then brace your front leg.
|
| 103 |
+
practice_feel: Land, then brace your front leg.
|
| 104 |
+
drill_id: pit_04
|
| 105 |
+
below:
|
| 106 |
+
result_text: Your front leg was straighter than most pitchers when your foot landed.
|
| 107 |
+
headline: Your front leg is fairly straight when your foot lands.
|
| 108 |
+
coach_message: Your front leg is straighter than most pitchers when you land. A little bend at landing helps you
|
| 109 |
+
stay balanced as you turn.
|
| 110 |
+
coach_tip: Land soft with a little bend in your front knee.
|
| 111 |
+
practice_feel: Land soft, then firm up.
|
| 112 |
+
drill_id: pit_03
|
| 113 |
+
maintain:
|
| 114 |
+
coach_message: Your front knee is bent like most pitchers when you land. Keep landing the same way so your front
|
| 115 |
+
leg can firm up.
|
| 116 |
+
practice_feel: Land, then brace your front leg.
|
| 117 |
+
drill_id: pit_04
|
| 118 |
+
|
| 119 |
+
hip_shoulder_separation_at_foot_strike:
|
| 120 |
+
mirror_for_right: true
|
| 121 |
+
in_range_text: Your hips and chest were turned about like most pitchers when your foot landed.
|
| 122 |
+
above:
|
| 123 |
+
result_text: Your hips had turned farther ahead of your chest than most pitchers when your foot landed.
|
| 124 |
+
headline: Your hips are turned well ahead of your chest when your foot lands.
|
| 125 |
+
coach_message: At landing, your hips have turned much farther than your chest. A balanced landing helps you use
|
| 126 |
+
that turn smoothly.
|
| 127 |
+
coach_tip: Land, feel balanced, then let your chest turn.
|
| 128 |
+
practice_feel: Land balanced, then let your chest follow your hips.
|
| 129 |
+
drill_id: pit_03
|
| 130 |
+
below:
|
| 131 |
+
result_text: Your chest had turned more with your hips than most pitchers when your foot landed.
|
| 132 |
+
headline: Your chest turns with your hips by the time your foot lands.
|
| 133 |
+
coach_message: At landing, your chest has turned almost as far as your hips. Keeping your chest facing the side
|
| 134 |
+
until your foot is down lets your hips lead the turn.
|
| 135 |
+
coach_tip: Keep your chest facing the side until your front foot lands.
|
| 136 |
+
practice_feel: Hips turn first, chest stays sideways until you land.
|
| 137 |
+
drill_id: pit_14
|
| 138 |
+
maintain:
|
| 139 |
+
coach_message: Your hips and chest are set like most pitchers when you land. Keep letting your hips lead while
|
| 140 |
+
your chest stays sideways.
|
| 141 |
+
practice_feel: Hips first, chest later.
|
| 142 |
+
drill_id: pit_14
|
| 143 |
+
|
| 144 |
+
lead_knee_extension_to_release:
|
| 145 |
+
in_range_text: Your front leg firmed up about like most pitchers before you let go of the ball.
|
| 146 |
+
above:
|
| 147 |
+
result_text: Your front knee straightened more than most pitchers before you let go of the ball.
|
| 148 |
+
headline: Your front knee straightens a lot before you let go of the ball.
|
| 149 |
+
coach_message: Your front knee straightens more than most pitchers between landing and release. Landing with a
|
| 150 |
+
bit of bend you can hold keeps your balance through the throw.
|
| 151 |
+
coach_tip: Land with a little bend, then hold your front leg firm.
|
| 152 |
+
practice_feel: Land, hold a firm front leg, and stay balanced.
|
| 153 |
+
drill_id: pit_05
|
| 154 |
+
below:
|
| 155 |
+
result_text: Your front knee firmed up less than most pitchers before you let go of the ball.
|
| 156 |
+
headline: Your front knee keeps bending after your foot lands.
|
| 157 |
+
coach_message: Your front knee firms up less than most pitchers after landing. Bracing the front leg gives your
|
| 158 |
+
body something to turn over.
|
| 159 |
+
coach_tip: Press down and firm up your front leg as you land.
|
| 160 |
+
practice_feel: Land, then brace your front leg.
|
| 161 |
+
drill_id: pit_04
|
| 162 |
+
maintain:
|
| 163 |
+
coach_message: Your front leg firms up like most pitchers before release. Keep pressing into a firm front leg.
|
| 164 |
+
practice_feel: Land, then brace your front leg.
|
| 165 |
+
drill_id: pit_04
|
| 166 |
+
|
| 167 |
+
throwing_elbow_flexion_at_release:
|
| 168 |
+
in_range_text: Your throwing elbow was bent about like most pitchers when you let go of the ball.
|
| 169 |
+
above:
|
| 170 |
+
result_text: Your throwing elbow was more bent than most pitchers when you let go of the ball.
|
| 171 |
+
headline: Your throwing elbow is more bent than most pitchers at release.
|
| 172 |
+
coach_message: Your throwing elbow is more bent than most pitchers at release. Matching the same arm shape on
|
| 173 |
+
every throw is the first step to a steady delivery.
|
| 174 |
+
coach_tip: Check your arm shape in a mirror as you finish.
|
| 175 |
+
practice_feel: Same arm shape every time.
|
| 176 |
+
drill_id: pit_10
|
| 177 |
+
below:
|
| 178 |
+
result_text: Your throwing arm was straighter than most pitchers when you let go of the ball.
|
| 179 |
+
headline: Your throwing arm is straighter than most pitchers at release.
|
| 180 |
+
coach_message: Your throwing arm is straighter than most pitchers at release. Matching the same arm shape on
|
| 181 |
+
every throw is the first step to a steady delivery.
|
| 182 |
+
coach_tip: Check your arm shape in a mirror as you finish.
|
| 183 |
+
practice_feel: Same arm shape every time.
|
| 184 |
+
drill_id: pit_10
|
| 185 |
+
maintain:
|
| 186 |
+
coach_message: Your throwing elbow is bent like most pitchers at release. Keep repeating the same arm shape.
|
| 187 |
+
practice_feel: Same arm shape every time.
|
| 188 |
+
drill_id: pit_11
|
| 189 |
+
|
| 190 |
+
foot_strike_to_release_ms:
|
| 191 |
+
in_range_text: Your move from landing to release took about as long as most pitchers.
|
| 192 |
+
above:
|
| 193 |
+
result_text: Your move from landing to release took longer than most pitchers.
|
| 194 |
+
headline: Your move from landing to release is slower than most pitchers.
|
| 195 |
+
coach_message: You take longer than most pitchers to get from landing to release. Landing on a firm front leg
|
| 196 |
+
helps your body turn through in one smooth move.
|
| 197 |
+
coach_tip: Land, brace, and turn through in one move.
|
| 198 |
+
practice_feel: Land, then brace your front leg.
|
| 199 |
+
drill_id: pit_04
|
| 200 |
+
below:
|
| 201 |
+
result_text: Your move from landing to release was quicker than most pitchers.
|
| 202 |
+
headline: Your move from landing to release is quicker than most pitchers.
|
| 203 |
+
coach_message: You get from landing to release quicker than most pitchers. Keep your rhythm steady so your
|
| 204 |
+
delivery stays the same each time.
|
| 205 |
+
coach_tip: Keep the same rhythm on every pitch.
|
| 206 |
+
practice_feel: Same rhythm, every pitch.
|
| 207 |
+
drill_id: pit_12
|
| 208 |
+
maintain:
|
| 209 |
+
coach_message: Your move from landing to release is like most pitchers. Keep the same rhythm on every pitch.
|
| 210 |
+
practice_feel: Same rhythm, every pitch.
|
| 211 |
+
drill_id: pit_12
|
| 212 |
+
|
| 213 |
+
torso_inclination_at_release:
|
| 214 |
+
in_range_text: Your upper body moved forward about like most pitchers when you let go of the ball.
|
| 215 |
+
above:
|
| 216 |
+
result_text: Your upper body leaned farther than most pitchers when you let go of the ball.
|
| 217 |
+
headline: Your upper body leans far when you let go of the ball.
|
| 218 |
+
coach_message: Your upper body leans more than most pitchers at release. Keeping your head steady over the line
|
| 219 |
+
to the plate makes your finish easier to repeat.
|
| 220 |
+
coach_tip: Keep your head steady over the line to the plate.
|
| 221 |
+
practice_feel: Head and spine stay over the line through release.
|
| 222 |
+
drill_id: pit_08
|
| 223 |
+
below:
|
| 224 |
+
result_text: Your upper body stayed more upright than most pitchers when you let go of the ball.
|
| 225 |
+
headline: Your upper body stays upright when you let go of the ball.
|
| 226 |
+
coach_message: Your upper body stays more upright than most pitchers at release. Letting your chest move over
|
| 227 |
+
your front knee carries your body through the throw.
|
| 228 |
+
coach_tip: Let your chest move over your front knee as you let go.
|
| 229 |
+
practice_feel: Chest over your front knee at the finish.
|
| 230 |
+
drill_id: pit_06
|
| 231 |
+
maintain:
|
| 232 |
+
coach_message: Your upper body moves forward like most pitchers at release. Keep finishing with your chest over
|
| 233 |
+
your front knee.
|
| 234 |
+
practice_feel: Chest over your front knee at the finish.
|
| 235 |
+
drill_id: pit_07
|
| 236 |
+
|
| 237 |
+
shoulder_rotation_after_release:
|
| 238 |
+
in_range_text: Your shoulders kept turning about like most pitchers just after release.
|
| 239 |
+
above:
|
| 240 |
+
result_text: Your shoulders turned more than most pitchers just after release.
|
| 241 |
+
headline: Your shoulders keep turning a lot just after release.
|
| 242 |
+
coach_message: Your shoulders turn more than most pitchers right after release. A balanced finish out front
|
| 243 |
+
keeps your delivery under you.
|
| 244 |
+
coach_tip: Finish out front and hold your balance.
|
| 245 |
+
practice_feel: Finish out front and hold it.
|
| 246 |
+
drill_id: pit_07
|
| 247 |
+
below:
|
| 248 |
+
result_text: Your shoulders turned less than most pitchers just after release.
|
| 249 |
+
headline: Your shoulders stop turning soon after release.
|
| 250 |
+
coach_message: Your shoulders turn less than most pitchers right after release. Letting your body keep moving
|
| 251 |
+
toward the plate lets your arm finish across your body.
|
| 252 |
+
coach_tip: Let your throwing arm finish across your body.
|
| 253 |
+
practice_feel: Chest over your front knee at the finish.
|
| 254 |
+
drill_id: pit_06
|
| 255 |
+
maintain:
|
| 256 |
+
coach_message: Your shoulders turn like most pitchers right after release. Keep finishing out front.
|
| 257 |
+
practice_feel: Finish out front and hold it.
|
| 258 |
+
drill_id: pit_07
|
AI-coach-agent/src/ai_coach/pitch_report/v1_1/service.py
CHANGED
|
@@ -8,7 +8,9 @@ from pathlib import Path
|
|
| 8 |
import yaml
|
| 9 |
from pydantic import ValidationError
|
| 10 |
|
| 11 |
-
from ...
|
|
|
|
|
|
|
| 12 |
from ...swing_report.service import InvalidPayload
|
| 13 |
from .coaching import generate_coaching
|
| 14 |
from .contract import GROUPS, METRICS, PitchPayload
|
|
@@ -57,6 +59,35 @@ MEANINGS = {
|
|
| 57 |
}
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
@dataclass(frozen=True)
|
| 61 |
class AthleteContext:
|
| 62 |
throwing_hand: str | None = None
|
|
@@ -108,74 +139,112 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 108 |
p = p.model_copy(update={"measurements": safe_measurements})
|
| 109 |
athlete = athlete or AthleteContext()
|
| 110 |
registry = references()
|
|
|
|
| 111 |
context = p.context
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
comparable = (
|
| 116 |
context.drill_type == "standard"
|
| 117 |
-
and context.practice_type in
|
| 118 |
and context.pitch_type == "fastball"
|
| 119 |
and context.ball_type == "baseball"
|
| 120 |
-
and not conflict
|
| 121 |
)
|
| 122 |
notes = []
|
| 123 |
if not comparable:
|
| 124 |
-
notes.append(
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
"severity": "warning",
|
| 128 |
-
"text": (
|
| 129 |
-
"This drill or practice context does not match the normal-fastball reference. "
|
| 130 |
-
"Measurements are shown without a delivery grade or corrective diagnosis."
|
| 131 |
-
),
|
| 132 |
-
}
|
| 133 |
-
)
|
| 134 |
if conflict:
|
| 135 |
-
notes.append(
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
rows = []
|
|
|
|
|
|
|
|
|
|
| 143 |
for m in p.measurements:
|
| 144 |
spec = METRICS[m.metric_id]
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
if cell and cell["n_athletes"] <
|
| 148 |
cell = None
|
| 149 |
-
benchmark = None
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
if m.value is not None:
|
| 171 |
-
if
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
text =
|
| 175 |
else:
|
| 176 |
-
text =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
limitation = [{"code": r, "text": REASONS[r]} for r in dict.fromkeys(m.reasons)]
|
| 178 |
-
label = "Reference range" if result_score == 100 else "Outside central range" if result_score is not None else "Not rated"
|
| 179 |
rows.append(
|
| 180 |
{
|
| 181 |
"metric_id": m.metric_id,
|
|
@@ -186,14 +255,14 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 186 |
"unit": m.unit,
|
| 187 |
"display_value": None if m.value is None else f"{m.value:.1f} {m.unit}",
|
| 188 |
"score": result_score,
|
| 189 |
-
"rating":
|
| 190 |
-
"rating_label":
|
| 191 |
-
"rating_is_tentative":
|
| 192 |
"not_rated_reason": why,
|
| 193 |
"benchmark": benchmark,
|
| 194 |
"what_it_means": MEANINGS[m.metric_id],
|
| 195 |
"result_text": text,
|
| 196 |
-
"coach_tip":
|
| 197 |
"limitations": limitation,
|
| 198 |
"value_interval": None
|
| 199 |
if m.value_interval is None
|
|
@@ -201,6 +270,12 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 201 |
"score_interval": interval,
|
| 202 |
}
|
| 203 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
groups = []
|
| 205 |
for key, name in GROUPS.items():
|
| 206 |
members = [m for m in rows if m["group"] == key]
|
|
@@ -209,89 +284,85 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 209 |
present = [m for m in members if m["value"] is not None]
|
| 210 |
if not present:
|
| 211 |
reasons = list(dict.fromkeys(r["text"] for m in members for r in m["limitations"]))
|
| 212 |
-
summary = " ".join(reasons)
|
|
|
|
| 213 |
elif not rated:
|
| 214 |
-
summary = "
|
|
|
|
| 215 |
else:
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
summary
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
| 221 |
groups.append(
|
| 222 |
{
|
| 223 |
"group": key,
|
| 224 |
"display_name": name,
|
| 225 |
"score": value,
|
| 226 |
-
"score_is_tentative":
|
| 227 |
-
"rating":
|
| 228 |
-
"rating_label": "Not rated"
|
| 229 |
-
"not_rated_reason":
|
| 230 |
-
if value is not None
|
| 231 |
-
else "measurements_unavailable"
|
| 232 |
-
if not present
|
| 233 |
-
else "context_not_comparable"
|
| 234 |
-
if not comparable
|
| 235 |
-
else "model_accuracy_unvalidated"
|
| 236 |
-
if any(m["benchmark"] for m in members)
|
| 237 |
-
else "no_benchmark",
|
| 238 |
"summary": summary,
|
| 239 |
"metric_ids": [m["metric_id"] for m in members],
|
| 240 |
}
|
| 241 |
)
|
| 242 |
for reason in dict.fromkeys(r for m in p.measurements for r in m.reasons):
|
| 243 |
notes.append({"code": reason, "severity": "info", "text": REASONS[reason]})
|
| 244 |
-
if any(
|
| 245 |
-
notes.append(
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
overall = mean_score(g["score"] for g in groups)
|
|
|
|
|
|
|
|
|
|
| 272 |
report = {
|
| 273 |
"schema_version": "1.0",
|
| 274 |
"discipline": "pitching",
|
| 275 |
"analysis_id": p.analysis_id,
|
| 276 |
"analysis_revision": p.analysis_revision,
|
| 277 |
"overall_score": overall,
|
| 278 |
-
"overall_score_is_tentative":
|
| 279 |
-
"overview": {"headline":
|
| 280 |
"groups": groups,
|
| 281 |
"measurements": rows,
|
| 282 |
-
"focus_area":
|
| 283 |
-
"kind": "general",
|
| 284 |
-
"is_tentative": True,
|
| 285 |
-
"metric_id": None,
|
| 286 |
-
"group": None,
|
| 287 |
-
"display_name": "Review your delivery",
|
| 288 |
-
"rating": "not_rated",
|
| 289 |
-
"rating_label": "Not rated",
|
| 290 |
-
"coach_message": message,
|
| 291 |
-
"practice_feel": "Review the marked moments alongside your measurements.",
|
| 292 |
-
"drill": None,
|
| 293 |
-
"evidence_metric_ids": [],
|
| 294 |
-
},
|
| 295 |
"data_quality": notes,
|
| 296 |
"meta": {
|
| 297 |
"generated_at": datetime.now(UTC).isoformat(),
|
|
@@ -300,12 +371,12 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 300 |
"model": None,
|
| 301 |
"prompt_version": "pitching-evidence-1.0",
|
| 302 |
"cache_hit": False,
|
| 303 |
-
"fallback_reason":
|
| 304 |
"text_rejections": {},
|
| 305 |
"input_schema_version": p.schema_version,
|
| 306 |
"measurement_definitions_version": p.measurement_definitions_version,
|
| 307 |
"benchmark_registry_version": registry["version"],
|
| 308 |
-
"coaching_rules_version": "
|
| 309 |
},
|
| 310 |
}
|
| 311 |
rubric = evaluate_drill(p)
|
|
@@ -315,15 +386,8 @@ def build_report(payload, athlete=None, *, request_id=None, settings=None, gener
|
|
| 315 |
report["coaching"] = coaching
|
| 316 |
report["visual_evidence"] = None
|
| 317 |
report["meta"].update(metadata)
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
focus = next((c for c in coaching["cards"] if c["kind"] == "review"), coaching["cards"][0])
|
| 321 |
-
report["focus_area"]["coach_message"] = focus["observation"] + " " + focus["why_it_matters"]
|
| 322 |
-
report["focus_area"]["practice_feel"] = focus["next_step"] + " " + focus["check"]
|
| 323 |
-
report["focus_area"]["evidence_metric_ids"] = [
|
| 324 |
-
k.split(":", 1)[1] for k in focus["evidence_ids"] if k.startswith("measurement:")
|
| 325 |
-
]
|
| 326 |
-
else:
|
| 327 |
report["data_quality"].append(
|
| 328 |
{
|
| 329 |
"code": "ai_coaching_unavailable",
|
|
|
|
| 8 |
import yaml
|
| 9 |
from pydantic import ValidationError
|
| 10 |
|
| 11 |
+
from ... import knowledge as kb
|
| 12 |
+
from ...swing_report.repository import drill
|
| 13 |
+
from ...swing_report.scoring import NOT_RATED, ON_TARGET, RATING_LABELS, mean_score, rating_for, score, side_of
|
| 14 |
from ...swing_report.service import InvalidPayload
|
| 15 |
from .coaching import generate_coaching
|
| 16 |
from .contract import GROUPS, METRICS, PitchPayload
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
|
| 62 |
+
COMPARABLE_PRACTICE = ("bullpen", "flat_ground", "live_bp", "game")
|
| 63 |
+
MIN_ATHLETES = 10
|
| 64 |
+
PLAUSIBLE_SPANS = 2.0 # values beyond the P10-P90 band widened by this many band widths are tracking errors
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _note(code, severity, text):
|
| 68 |
+
return {"code": code, "severity": severity, "text": text}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def _position(value, benchmark):
|
| 72 |
+
b = benchmark["on_target"]
|
| 73 |
+
return "within" if b["lower"] <= value <= b["upper"] else "below" if value < b["lower"] else "above"
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _focus(kind, m, advice):
|
| 77 |
+
return {"kind": kind, "is_tentative": m["rating_is_tentative"], "metric_id": m["metric_id"], "group": m["group"],
|
| 78 |
+
"display_name": m["display_name"], "rating": m["rating"], "rating_label": m["rating_label"],
|
| 79 |
+
"coach_message": advice["coach_message"], "practice_feel": advice["practice_feel"],
|
| 80 |
+
"drill": drill(advice["drill_id"]), "evidence_metric_ids": [m["metric_id"]]}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
@cache
|
| 84 |
+
def coaching_rules():
|
| 85 |
+
data = yaml.safe_load(Path(kb.KNOWLEDGE_DIR, "pitch_v1_1_coaching.yaml").read_text(encoding="utf-8"))
|
| 86 |
+
if set(data["metrics"]) != set(METRICS):
|
| 87 |
+
raise ValueError("pitch_v1_1_coaching.yaml must cover exactly the pitch-1.1 metrics")
|
| 88 |
+
return data
|
| 89 |
+
|
| 90 |
+
|
| 91 |
@dataclass(frozen=True)
|
| 92 |
class AthleteContext:
|
| 93 |
throwing_hand: str | None = None
|
|
|
|
| 139 |
p = p.model_copy(update={"measurements": safe_measurements})
|
| 140 |
athlete = athlete or AthleteContext()
|
| 141 |
registry = references()
|
| 142 |
+
rules = coaching_rules()
|
| 143 |
context = p.context
|
| 144 |
+
conflict = bool(p.athlete.throwing_hand and athlete.throwing_hand and p.athlete.throwing_hand != athlete.throwing_hand)
|
| 145 |
+
# Payload side first (it is the side analysed), then the profile, then the opposite of the lead foot.
|
| 146 |
+
hand = p.athlete.throwing_hand or athlete.throwing_hand
|
| 147 |
+
hand_inferred = False
|
| 148 |
+
if hand is None and p.athlete.lead_foot:
|
| 149 |
+
hand, hand_inferred = ("left" if p.athlete.lead_foot == "right" else "right"), True
|
| 150 |
+
# Reference trials are normal fastballs thrown with a baseball off a mound or flat ground. Special drills, other
|
| 151 |
+
# pitches and training balls change the delivery on purpose, so they are described but never rated.
|
| 152 |
comparable = (
|
| 153 |
context.drill_type == "standard"
|
| 154 |
+
and context.practice_type in COMPARABLE_PRACTICE
|
| 155 |
and context.pitch_type == "fastball"
|
| 156 |
and context.ball_type == "baseball"
|
|
|
|
| 157 |
)
|
| 158 |
notes = []
|
| 159 |
if not comparable:
|
| 160 |
+
notes.append(_note("practice_context_unverified", "warning",
|
| 161 |
+
"This drill or pitch changes the delivery on purpose, so it is not compared with regular "
|
| 162 |
+
"fastballs. Your results are shown without a rating."))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
if conflict:
|
| 164 |
+
notes.append(_note("throwing_hand_conflict", "warning",
|
| 165 |
+
"The video and your profile list different throwing arms. Scores use the side from the "
|
| 166 |
+
"video, so check it first."))
|
| 167 |
+
if hand is None:
|
| 168 |
+
notes.append(_note("throwing_hand_unknown", "warning",
|
| 169 |
+
"We do not know which arm you throw with, so your results are not rated."))
|
| 170 |
+
elif hand_inferred:
|
| 171 |
+
notes.append(_note("throwing_hand_inferred", "info", "Your throwing side was worked out from your front foot."))
|
| 172 |
+
# OBP has college pitchers only (too few high-school or pro pitchers per hand), so every level uses college.
|
| 173 |
+
level_note = None
|
| 174 |
+
if athlete.level in (None, "unknown"):
|
| 175 |
+
level_note = _note("level_assumed", "info", "Your level is not set, so you are compared with college pitchers.")
|
| 176 |
+
elif athlete.level != "college":
|
| 177 |
+
level_note = _note("level_approximated", "info",
|
| 178 |
+
"We have no ranges for your level yet, so you are compared with college pitchers.")
|
| 179 |
rows = []
|
| 180 |
+
sides = {}
|
| 181 |
+
sensitive = set()
|
| 182 |
+
implausible = False
|
| 183 |
for m in p.measurements:
|
| 184 |
spec = METRICS[m.metric_id]
|
| 185 |
+
advice = rules["metrics"][m.metric_id]
|
| 186 |
+
cell = registry["metrics"].get(m.metric_id, {}).get("cells", {}).get(f"{hand}/college")
|
| 187 |
+
if cell and cell["n_athletes"] < MIN_ATHLETES:
|
| 188 |
cell = None
|
| 189 |
+
benchmark = result_score = interval = side = None
|
| 190 |
+
if m.value is None:
|
| 191 |
+
why = "measurement_unavailable"
|
| 192 |
+
elif not comparable:
|
| 193 |
+
why = "context_not_comparable"
|
| 194 |
+
elif hand is None:
|
| 195 |
+
why = "throwing_hand_unknown"
|
| 196 |
+
elif cell is None:
|
| 197 |
+
why = "no_benchmark"
|
| 198 |
+
else:
|
| 199 |
+
on, sat = cell["on_target"], cell["satisfactory"]
|
| 200 |
+
span = sat["upper"] - sat["lower"]
|
| 201 |
+
if not sat["lower"] - PLAUSIBLE_SPANS * span <= m.value <= sat["upper"] + PLAUSIBLE_SPANS * span:
|
| 202 |
+
# Far beyond every reference pitch: a tracking or scale problem, not a technique finding.
|
| 203 |
+
why, implausible = "implausible_value", True
|
| 204 |
+
else:
|
| 205 |
+
why = None
|
| 206 |
+
benchmark = {
|
| 207 |
+
"benchmark_id": f"pitch-1.1.{m.metric_id}.{hand}.college",
|
| 208 |
+
"version": registry["version"],
|
| 209 |
+
"population": cell["population"],
|
| 210 |
+
"on_target": on,
|
| 211 |
+
"satisfactory": sat,
|
| 212 |
+
"unit": m.unit,
|
| 213 |
+
"source_reference": registry["source_reference"],
|
| 214 |
+
}
|
| 215 |
+
grade = (on["lower"], on["upper"], sat["lower"], sat["upper"])
|
| 216 |
+
result_score = score(m.value, *grade)
|
| 217 |
+
if m.value_interval is not None:
|
| 218 |
+
low, high = m.value_interval.lower, m.value_interval.upper
|
| 219 |
+
candidates = [low, high, m.value, *(v for v in grade if low <= v <= high)]
|
| 220 |
+
scores = [score(v, *grade) for v in candidates]
|
| 221 |
+
interval = {"lower": min(scores), "upper": max(scores)}
|
| 222 |
+
if interval["upper"] - interval["lower"] >= 20 or rating_for(interval["lower"]) != rating_for(
|
| 223 |
+
interval["upper"]):
|
| 224 |
+
sensitive.add(m.metric_id)
|
| 225 |
+
side = side_of(m.value, on["lower"], on["upper"])
|
| 226 |
+
if side and advice.get("mirror_for_right") and hand == "right":
|
| 227 |
+
side = "below" if side == "above" else "above"
|
| 228 |
+
sides[m.metric_id] = side
|
| 229 |
+
rating = rating_for(result_score)
|
| 230 |
+
tentative = result_score is not None and m.status == "limited"
|
| 231 |
+
text = tip = None
|
| 232 |
if m.value is not None:
|
| 233 |
+
if result_score is None:
|
| 234 |
+
text = f"Your {spec[1].lower()} is shown for reference, without a rating."
|
| 235 |
+
elif rating == ON_TARGET or side is None:
|
| 236 |
+
text = advice["in_range_text"]
|
| 237 |
else:
|
| 238 |
+
text = advice[side]["result_text"]
|
| 239 |
+
tip = advice[side]["coach_tip"]
|
| 240 |
+
if result_score is not None and m.metric_id in sensitive:
|
| 241 |
+
tip = None
|
| 242 |
+
text = f"Your estimated {spec[1].lower()} was {_position(m.value, benchmark)} the reference range."
|
| 243 |
+
elif tentative:
|
| 244 |
+
text = "This result is approximate. " + text
|
| 245 |
+
if conflict:
|
| 246 |
+
tip = None
|
| 247 |
limitation = [{"code": r, "text": REASONS[r]} for r in dict.fromkeys(m.reasons)]
|
|
|
|
| 248 |
rows.append(
|
| 249 |
{
|
| 250 |
"metric_id": m.metric_id,
|
|
|
|
| 255 |
"unit": m.unit,
|
| 256 |
"display_value": None if m.value is None else f"{m.value:.1f} {m.unit}",
|
| 257 |
"score": result_score,
|
| 258 |
+
"rating": rating,
|
| 259 |
+
"rating_label": RATING_LABELS.get(rating, "Not rated"),
|
| 260 |
+
"rating_is_tentative": tentative,
|
| 261 |
"not_rated_reason": why,
|
| 262 |
"benchmark": benchmark,
|
| 263 |
"what_it_means": MEANINGS[m.metric_id],
|
| 264 |
"result_text": text,
|
| 265 |
+
"coach_tip": tip,
|
| 266 |
"limitations": limitation,
|
| 267 |
"value_interval": None
|
| 268 |
if m.value_interval is None
|
|
|
|
| 270 |
"score_interval": interval,
|
| 271 |
}
|
| 272 |
)
|
| 273 |
+
if level_note and any(m["score"] is not None for m in rows):
|
| 274 |
+
notes.append(level_note)
|
| 275 |
+
if implausible:
|
| 276 |
+
notes.append(_note("implausible_value", "warning",
|
| 277 |
+
"Some results were far outside what we see in real pitches, so they look like tracking "
|
| 278 |
+
"errors and are not rated."))
|
| 279 |
groups = []
|
| 280 |
for key, name in GROUPS.items():
|
| 281 |
members = [m for m in rows if m["group"] == key]
|
|
|
|
| 284 |
present = [m for m in members if m["value"] is not None]
|
| 285 |
if not present:
|
| 286 |
reasons = list(dict.fromkeys(r["text"] for m in members for r in m["limitations"]))
|
| 287 |
+
summary = " ".join(reasons) or "We could not measure this part of the pitch in this video."
|
| 288 |
+
reason = "measurements_unavailable"
|
| 289 |
elif not rated:
|
| 290 |
+
summary = "These results are shown for reference, without a rating."
|
| 291 |
+
reason = next((m["not_rated_reason"] for m in present if m["not_rated_reason"]), "no_rated_measurements")
|
| 292 |
else:
|
| 293 |
+
reason = None
|
| 294 |
+
worst = min(rated, key=lambda m: m["score"])
|
| 295 |
+
summary = worst["result_text"] if worst["rating"] != ON_TARGET else (
|
| 296 |
+
"Everything we measured in this part of your pitch is in the typical range.")
|
| 297 |
+
if len(rated) < len(members):
|
| 298 |
+
summary += " This score covers only part of this phase."
|
| 299 |
+
rating = rating_for(value)
|
| 300 |
groups.append(
|
| 301 |
{
|
| 302 |
"group": key,
|
| 303 |
"display_name": name,
|
| 304 |
"score": value,
|
| 305 |
+
"score_is_tentative": any(m["rating_is_tentative"] for m in rated),
|
| 306 |
+
"rating": rating,
|
| 307 |
+
"rating_label": RATING_LABELS.get(rating, "Not rated"),
|
| 308 |
+
"not_rated_reason": reason,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
"summary": summary,
|
| 310 |
"metric_ids": [m["metric_id"] for m in members],
|
| 311 |
}
|
| 312 |
)
|
| 313 |
for reason in dict.fromkeys(r for m in p.measurements for r in m.reasons):
|
| 314 |
notes.append({"code": reason, "severity": "info", "text": REASONS[reason]})
|
| 315 |
+
if any(g["score"] is None for g in groups) and any(g["score"] is not None for g in groups):
|
| 316 |
+
notes.append(_note("partial_group_coverage", "warning",
|
| 317 |
+
"The overall score uses only the parts of the pitch we could score. Missing results do not "
|
| 318 |
+
"count as zero."))
|
| 319 |
+
if sensitive:
|
| 320 |
+
notes.append(_note("event_sensitive_scores", "warning",
|
| 321 |
+
"Some ratings change when a marked moment moves by one frame, so those results are shown "
|
| 322 |
+
"without practice advice."))
|
| 323 |
+
|
| 324 |
+
eligible = [] if conflict else [m for m in rows if m["score"] is not None and m["metric_id"] not in sensitive]
|
| 325 |
+
needs_work = sorted((m for m in eligible if m["rating"] != ON_TARGET), key=lambda m: m["score"])
|
| 326 |
+
on_target = [m for m in eligible if m["rating"] == ON_TARGET]
|
| 327 |
+
group_names = GROUPS
|
| 328 |
+
if needs_work:
|
| 329 |
+
m = needs_work[0]
|
| 330 |
+
advice = rules["metrics"][m["metric_id"]][sides[m["metric_id"]]]
|
| 331 |
+
focus = _focus("fix", m, advice)
|
| 332 |
+
headline = rules["headline_focus"].format(group=group_names[m["group"]]) + " " + advice["headline"]
|
| 333 |
+
elif on_target:
|
| 334 |
+
m = on_target[0]
|
| 335 |
+
focus = _focus("maintain", m, rules["metrics"][m["metric_id"]]["maintain"])
|
| 336 |
+
headline = rules["headline_all_on_target"]
|
| 337 |
+
else:
|
| 338 |
+
general = rules["general_focus"]
|
| 339 |
+
focus = {"kind": "general", "is_tentative": False, "metric_id": None, "group": None,
|
| 340 |
+
"display_name": general["display_name"], "rating": NOT_RATED, "rating_label": "Not rated",
|
| 341 |
+
"coach_message": general["coach_message"], "practice_feel": general["practice_feel"],
|
| 342 |
+
"drill": drill(general["drill_id"]), "evidence_metric_ids": []}
|
| 343 |
+
headline = rules["headline_nothing_rated"]
|
| 344 |
+
if not comparable and any(m["value"] is not None for m in rows):
|
| 345 |
+
headline = rules["headline_not_comparable"]
|
| 346 |
+
focus["coach_message"] = rules["not_comparable_message"]
|
| 347 |
+
if conflict:
|
| 348 |
+
focus["coach_message"] = rules["hand_conflict_message"]
|
| 349 |
+
if focus["is_tentative"]:
|
| 350 |
+
focus["coach_message"] = "This result is an estimate. " + focus["coach_message"]
|
| 351 |
overall = mean_score(g["score"] for g in groups)
|
| 352 |
+
overall_tentative = any(g["score_is_tentative"] for g in groups if g["score"] is not None)
|
| 353 |
+
if overall_tentative and focus["kind"] != "general":
|
| 354 |
+
headline += " " + rules["headline_tentative"]
|
| 355 |
report = {
|
| 356 |
"schema_version": "1.0",
|
| 357 |
"discipline": "pitching",
|
| 358 |
"analysis_id": p.analysis_id,
|
| 359 |
"analysis_revision": p.analysis_revision,
|
| 360 |
"overall_score": overall,
|
| 361 |
+
"overall_score_is_tentative": overall_tentative,
|
| 362 |
+
"overview": {"headline": headline},
|
| 363 |
"groups": groups,
|
| 364 |
"measurements": rows,
|
| 365 |
+
"focus_area": focus,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
"data_quality": notes,
|
| 367 |
"meta": {
|
| 368 |
"generated_at": datetime.now(UTC).isoformat(),
|
|
|
|
| 371 |
"model": None,
|
| 372 |
"prompt_version": "pitching-evidence-1.0",
|
| 373 |
"cache_hit": False,
|
| 374 |
+
"fallback_reason": None,
|
| 375 |
"text_rejections": {},
|
| 376 |
"input_schema_version": p.schema_version,
|
| 377 |
"measurement_definitions_version": p.measurement_definitions_version,
|
| 378 |
"benchmark_registry_version": registry["version"],
|
| 379 |
+
"coaching_rules_version": str(rules["version"]),
|
| 380 |
},
|
| 381 |
}
|
| 382 |
rubric = evaluate_drill(p)
|
|
|
|
| 386 |
report["coaching"] = coaching
|
| 387 |
report["visual_evidence"] = None
|
| 388 |
report["meta"].update(metadata)
|
| 389 |
+
# The AI cards are their own section; the headline and focus keep the short, rated rules text with a drill.
|
| 390 |
+
if coaching["status"] != "generated":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
report["data_quality"].append(
|
| 392 |
{
|
| 393 |
"code": "ai_coaching_unavailable",
|
AI-coach-agent/tests/test_pitching_report.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
import pytest
|
| 4 |
|
|
@@ -64,7 +64,6 @@ def payload():
|
|
| 64 |
"context",
|
| 65 |
[
|
| 66 |
{"practice_type": "unknown"},
|
| 67 |
-
{"practice_type": "flat_ground"},
|
| 68 |
{"drill_type": "step_back"},
|
| 69 |
{"drill_type": "rocker"},
|
| 70 |
{"drill_type": "unknown"},
|
|
@@ -81,29 +80,99 @@ def test_nonmatching_context_keeps_measurements_without_normal_delivery_grades(c
|
|
| 81 |
PitchReport.model_validate(r)
|
| 82 |
assert r["overall_score"] is None and all(g["score"] is None for g in r["groups"])
|
| 83 |
assert all(m["value"] is not None and m["score"] is None and m["coach_tip"] is None for m in r["measurements"])
|
| 84 |
-
assert r["focus_area"]["drill"]
|
| 85 |
assert any(n["code"] == "practice_context_unverified" for n in r["data_quality"])
|
| 86 |
|
| 87 |
|
| 88 |
-
def
|
|
|
|
| 89 |
p = payload()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
r = build_report(p, AthleteContext(throwing_hand="right", level="college"))
|
| 91 |
-
|
| 92 |
-
assert
|
| 93 |
-
assert
|
| 94 |
-
referenced = [m for m in r["measurements"] if m["benchmark"]]
|
| 95 |
-
assert referenced and all(m["not_rated_reason"] == "model_accuracy_unvalidated" for m in referenced)
|
| 96 |
-
assert all(m["coach_tip"] is None for m in r["measurements"])
|
| 97 |
span = next(m for m in r["measurements"] if m["unit"] == "cm")
|
| 98 |
assert span["score"] is None and span["not_rated_reason"] == "no_benchmark"
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
def test_wrong_profile_throwing_hand_cannot_select_another_side_or_enable_advice():
|
| 104 |
-
r = build_report(
|
| 105 |
-
assert r["overall_score"] is None
|
| 106 |
assert any(n["code"] == "throwing_hand_conflict" for n in r["data_quality"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
@pytest.mark.parametrize(
|
|
|
|
| 1 |
+
"""Pitch-1.1 reports: regular fastballs are rated against OBP; special drills and pitches are only described."""
|
| 2 |
|
| 3 |
import pytest
|
| 4 |
|
|
|
|
| 64 |
"context",
|
| 65 |
[
|
| 66 |
{"practice_type": "unknown"},
|
|
|
|
| 67 |
{"drill_type": "step_back"},
|
| 68 |
{"drill_type": "rocker"},
|
| 69 |
{"drill_type": "unknown"},
|
|
|
|
| 80 |
PitchReport.model_validate(r)
|
| 81 |
assert r["overall_score"] is None and all(g["score"] is None for g in r["groups"])
|
| 82 |
assert all(m["value"] is not None and m["score"] is None and m["coach_tip"] is None for m in r["measurements"])
|
| 83 |
+
assert r["focus_area"]["kind"] == "general" and r["focus_area"]["drill"]["drill_id"] == "pit_12"
|
| 84 |
assert any(n["code"] == "practice_context_unverified" for n in r["data_quality"])
|
| 85 |
|
| 86 |
|
| 87 |
+
def rated_payload():
|
| 88 |
+
"""A right-handed college fastball at the middle of every OBP reference range."""
|
| 89 |
p = payload()
|
| 90 |
+
# Event times at the middle of the OBP timing ranges (frames at 60 fps), so the timing metrics are typical too.
|
| 91 |
+
for key, frame in [("leg_lift", 20), ("foot_strike", 57), ("release", 66), ("early_follow_through", 72)]:
|
| 92 |
+
p["events"][key].update(source_frame_index=frame, video_time_s=frame / 60, capture_time_s=frame / 60)
|
| 93 |
+
cells = references()["metrics"]
|
| 94 |
+
for m in p["measurements"]:
|
| 95 |
+
cell = cells[m["metric_id"]]["cells"].get("right/college")
|
| 96 |
+
if m["unit"] == "ms":
|
| 97 |
+
ids = m["event_ids"]
|
| 98 |
+
m["value"] = 1000 * (p["events"][ids[-1]]["capture_time_s"] - p["events"][ids[0]]["capture_time_s"])
|
| 99 |
+
m["value_interval"] = {"lower": m["value"] - 1, "upper": m["value"] + 1, "source": "adjacent_event_frames"}
|
| 100 |
+
elif cell:
|
| 101 |
+
mid = (cell["on_target"]["lower"] + cell["on_target"]["upper"]) / 2
|
| 102 |
+
m["value"] = mid
|
| 103 |
+
m["value_interval"] = {"lower": mid - 0.1, "upper": mid + 0.1, "source": "adjacent_event_frames"}
|
| 104 |
+
return p
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@pytest.mark.parametrize("practice", ["bullpen", "flat_ground", "live_bp", "game"])
|
| 108 |
+
def test_regular_fastball_is_rated_with_a_drill(practice):
|
| 109 |
+
p = rated_payload()
|
| 110 |
+
p["context"]["practice_type"] = practice
|
| 111 |
r = build_report(p, AthleteContext(throwing_hand="right", level="college"))
|
| 112 |
+
PitchReport.model_validate(r)
|
| 113 |
+
assert r["overall_score"] == 100 and r["overall_score_is_tentative"] is True
|
| 114 |
+
assert r["focus_area"]["kind"] == "maintain" and r["focus_area"]["drill"] is not None
|
|
|
|
|
|
|
|
|
|
| 115 |
span = next(m for m in r["measurements"] if m["unit"] == "cm")
|
| 116 |
assert span["score"] is None and span["not_rated_reason"] == "no_benchmark"
|
| 117 |
+
assert len(r["overview"]["headline"].split()) <= 30
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def test_off_target_result_becomes_the_focus_with_its_drill():
|
| 121 |
+
p = rated_payload()
|
| 122 |
+
sep = next(m for m in p["measurements"] if m["metric_id"] == "hip_shoulder_separation_at_foot_strike")
|
| 123 |
+
sep.update(value=-25.0, value_interval={"lower": -25.5, "upper": -24.5, "source": "adjacent_event_frames"})
|
| 124 |
+
r = build_report(p, AthleteContext(throwing_hand="right", level="college"))
|
| 125 |
+
row = next(m for m in r["measurements"] if m["metric_id"] == sep["metric_id"])
|
| 126 |
+
# Right-handers have a negative reference, so a smaller magnitude is less separation (mirrored side).
|
| 127 |
+
assert row["rating"] == "off_target" and row["coach_tip"]
|
| 128 |
+
assert r["focus_area"]["metric_id"] == sep["metric_id"] and r["focus_area"]["drill"]["drill_id"] == "pit_14"
|
| 129 |
+
assert r["overview"]["headline"].startswith("Stride and Plant is the area to work on.")
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
@pytest.mark.parametrize(("level", "note"), [(None, "level_assumed"), ("high_school", "level_approximated"),
|
| 133 |
+
("youth", "level_approximated"), ("adult", "level_approximated")])
|
| 134 |
+
def test_every_level_uses_college_with_a_note(level, note):
|
| 135 |
+
r = build_report(rated_payload(), AthleteContext(level=level))
|
| 136 |
+
assert r["overall_score"] == 100
|
| 137 |
+
assert note in {n["code"] for n in r["data_quality"]}
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def test_frame_sensitive_and_implausible_results_are_not_coached():
|
| 141 |
+
p = rated_payload()
|
| 142 |
+
knee = next(m for m in p["measurements"] if m["metric_id"] == "lead_knee_flexion_at_foot_strike")
|
| 143 |
+
knee.update(value=60.0, value_interval={"lower": 50.0, "upper": 70.0, "source": "adjacent_event_frames"})
|
| 144 |
+
lean = next(m for m in p["measurements"] if m["metric_id"] == "torso_inclination_at_release")
|
| 145 |
+
lean.update(value=170.0, value_interval={"lower": 169.0, "upper": 171.0, "source": "adjacent_event_frames"})
|
| 146 |
+
r = build_report(p, AthleteContext(level="college"))
|
| 147 |
+
rows = {m["metric_id"]: m for m in r["measurements"]}
|
| 148 |
+
assert rows[knee["metric_id"]]["coach_tip"] is None and r["focus_area"]["metric_id"] != knee["metric_id"]
|
| 149 |
+
assert rows[lean["metric_id"]]["not_rated_reason"] == "implausible_value"
|
| 150 |
+
assert {"event_sensitive_scores", "implausible_value"} <= {n["code"] for n in r["data_quality"]}
|
| 151 |
|
| 152 |
|
| 153 |
def test_wrong_profile_throwing_hand_cannot_select_another_side_or_enable_advice():
|
| 154 |
+
r = build_report(rated_payload(), AthleteContext(throwing_hand="left", level="college"))
|
|
|
|
| 155 |
assert any(n["code"] == "throwing_hand_conflict" for n in r["data_quality"])
|
| 156 |
+
assert all(m["coach_tip"] is None for m in r["measurements"])
|
| 157 |
+
assert r["focus_area"]["kind"] == "general"
|
| 158 |
+
# The payload side is the side analysed, so its reference is used.
|
| 159 |
+
assert all(m["benchmark"]["benchmark_id"].endswith(".right.college") for m in r["measurements"] if m["benchmark"])
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def test_rules_text_passes_guardrails():
|
| 163 |
+
from ai_coach.pitch_report.v1_1.service import coaching_rules
|
| 164 |
+
from ai_coach.swing_report.text import check_text
|
| 165 |
+
|
| 166 |
+
rules = coaching_rules()
|
| 167 |
+
for key, value in rules.items():
|
| 168 |
+
if isinstance(value, str) and key != "version":
|
| 169 |
+
assert check_text(value.replace("{group}", "Stride and Plant"), "coach_message") == [], key
|
| 170 |
+
for metric in rules["metrics"].values():
|
| 171 |
+
assert check_text(metric["in_range_text"], "result") == []
|
| 172 |
+
for side in ("above", "below", "maintain"):
|
| 173 |
+
for key, text in metric[side].items():
|
| 174 |
+
if key != "drill_id":
|
| 175 |
+
assert check_text(text, "coach_message") == [], text
|
| 176 |
|
| 177 |
|
| 178 |
@pytest.mark.parametrize(
|
backend/app/integrations/pitching_reports.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-safe projections and current coaching provenance for saved pitch-1.1 reports."""
|
| 2 |
+
|
| 3 |
+
from copy import deepcopy
|
| 4 |
+
|
| 5 |
+
from ai_coach.pitch_report.v1_1.coaching import VERSION, Coaching
|
| 6 |
+
|
| 7 |
+
REFRESH_REQUIRED = "coaching_refresh_required"
|
| 8 |
+
REFRESH_MESSAGE = "Refresh coaching before using feedback for this delivery. Saved measurements remain estimates."
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def obsolete_pitch_coaching(report: dict) -> bool:
|
| 12 |
+
return (
|
| 13 |
+
(report.get("meta") or {}).get("prompt_version") != VERSION
|
| 14 |
+
or (report.get("coaching") or {}).get("evidence_mode") != "ml_measurements_and_motion"
|
| 15 |
+
or report.get("visual_evidence") is not None
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def report_for_read(mode: str, report: dict | None, measurement_payload: dict | None) -> dict | None:
|
| 20 |
+
schema = (measurement_payload or {}).get("schema_version") or ((report or {}).get("meta") or {}).get(
|
| 21 |
+
"input_schema_version"
|
| 22 |
+
)
|
| 23 |
+
if mode != "p" or schema != "pitch-1.1" or report is None or not obsolete_pitch_coaching(report):
|
| 24 |
+
return report
|
| 25 |
+
safe = deepcopy(report)
|
| 26 |
+
safe.update(
|
| 27 |
+
overall_score=None, overall_score_is_tentative=False,
|
| 28 |
+
overview={"headline": REFRESH_MESSAGE}, focus_area=None, drill_evaluation=None, visual_evidence=None,
|
| 29 |
+
coaching=Coaching(status="unavailable", reason=REFRESH_REQUIRED).model_dump(mode="json"),
|
| 30 |
+
)
|
| 31 |
+
for group in safe.get("groups", []):
|
| 32 |
+
group.update(score=None, score_is_tentative=False, rating="not_rated", rating_label="Not rated",
|
| 33 |
+
not_rated_reason=REFRESH_REQUIRED, summary=REFRESH_MESSAGE)
|
| 34 |
+
for measurement in safe.get("measurements", []):
|
| 35 |
+
measurement.update(score=None, score_interval=None, rating="not_rated", rating_label="Not rated",
|
| 36 |
+
rating_is_tentative=False, not_rated_reason=REFRESH_REQUIRED, benchmark=None,
|
| 37 |
+
result_text=None, coach_tip=None)
|
| 38 |
+
safe.setdefault("meta", {}).update(text_source="rules", model=None, cache_hit=False,
|
| 39 |
+
fallback_reason=REFRESH_REQUIRED, text_rejections={})
|
| 40 |
+
safe["meta"]["prompt_version"] = safe["meta"].get("prompt_version") or "unknown"
|
| 41 |
+
superseded = {REFRESH_REQUIRED, "partial_measurement_coverage", "event_sensitive_scores", "ai_coaching_unavailable"}
|
| 42 |
+
safe["data_quality"] = [note for note in safe.get("data_quality", []) if note.get("code") not in superseded]
|
| 43 |
+
safe["data_quality"].append({"code": REFRESH_REQUIRED, "severity": "warning", "text": REFRESH_MESSAGE})
|
| 44 |
+
return safe
|
backend/app/main.py
CHANGED
|
@@ -5,6 +5,7 @@ import uuid
|
|
| 5 |
|
| 6 |
from ai_coach.config import get_settings as get_coach_settings
|
| 7 |
from ai_coach.pitch_report.schemas import PitchAnalysisPayload
|
|
|
|
| 8 |
from ai_coach.swing_report.schemas import SwingAnalysisPayload, SwingReport
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.openapi.utils import get_openapi
|
|
@@ -96,8 +97,8 @@ ERROR_SCHEMA = {
|
|
| 96 |
}
|
| 97 |
|
| 98 |
|
| 99 |
-
REQUEST_MODELS = {"/v1/sessions/{session_id}/swing-report": "SwingAnalysisPayload",
|
| 100 |
-
"/v1/sessions/{session_id}/pitch-report": "PitchAnalysisPayload"}
|
| 101 |
|
| 102 |
|
| 103 |
def _openapi(app: FastAPI) -> dict:
|
|
@@ -112,6 +113,11 @@ def _openapi(app: FastAPI) -> dict:
|
|
| 112 |
_, contract = models_json_schema([(SwingAnalysisPayload, "validation"), (PitchAnalysisPayload, "validation"),
|
| 113 |
(SwingReport, "serialization")], ref_template="#/components/schemas/{model}")
|
| 114 |
schemas.update(contract.get("$defs", {}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
error_ref = {"description": "Error", "content": {"application/json": {
|
| 116 |
"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}}
|
| 117 |
for path, operations in spec["paths"].items():
|
|
@@ -120,13 +126,15 @@ def _openapi(app: FastAPI) -> dict:
|
|
| 120 |
responses.pop("422", None)
|
| 121 |
responses.setdefault("400", error_ref)
|
| 122 |
responses.setdefault("default", error_ref)
|
| 123 |
-
|
| 124 |
-
if
|
|
|
|
| 125 |
operation["requestBody"] = {"required": True, "content": {"application/json": {
|
| 126 |
-
"schema": {"
|
| 127 |
session_out = schemas.get("SessionOut", {}).get("properties", {})
|
| 128 |
if "report" in session_out:
|
| 129 |
-
session_out["report"] = {"anyOf": [{"$ref": "#/components/schemas/SwingReport"},
|
|
|
|
| 130 |
"description": "Null while status is pending"}
|
| 131 |
app.openapi_schema = spec
|
| 132 |
return spec
|
|
|
|
| 5 |
|
| 6 |
from ai_coach.config import get_settings as get_coach_settings
|
| 7 |
from ai_coach.pitch_report.schemas import PitchAnalysisPayload
|
| 8 |
+
from ai_coach.pitch_report.v1_1.contract import PitchPayload
|
| 9 |
from ai_coach.swing_report.schemas import SwingAnalysisPayload, SwingReport
|
| 10 |
from fastapi import FastAPI, Request
|
| 11 |
from fastapi.openapi.utils import get_openapi
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
|
| 100 |
+
REQUEST_MODELS = {"/v1/sessions/{session_id}/swing-report": ("SwingAnalysisPayload",),
|
| 101 |
+
"/v1/sessions/{session_id}/pitch-report": ("PitchAnalysisPayload", "PitchPayload")}
|
| 102 |
|
| 103 |
|
| 104 |
def _openapi(app: FastAPI) -> dict:
|
|
|
|
| 113 |
_, contract = models_json_schema([(SwingAnalysisPayload, "validation"), (PitchAnalysisPayload, "validation"),
|
| 114 |
(SwingReport, "serialization")], ref_template="#/components/schemas/{model}")
|
| 115 |
schemas.update(contract.get("$defs", {}))
|
| 116 |
+
# Isolate pitch-1.1 validation definitions from existing input names and response serialization schemas.
|
| 117 |
+
pitch_input = PitchPayload.model_json_schema(
|
| 118 |
+
mode="validation", ref_template="#/components/schemas/PitchPayload_{model}")
|
| 119 |
+
schemas.update({f"PitchPayload_{name}": value for name, value in pitch_input.pop("$defs", {}).items()})
|
| 120 |
+
schemas["PitchPayload"] = pitch_input
|
| 121 |
error_ref = {"description": "Error", "content": {"application/json": {
|
| 122 |
"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}}
|
| 123 |
for path, operations in spec["paths"].items():
|
|
|
|
| 126 |
responses.pop("422", None)
|
| 127 |
responses.setdefault("400", error_ref)
|
| 128 |
responses.setdefault("default", error_ref)
|
| 129 |
+
request_models = REQUEST_MODELS.get(path)
|
| 130 |
+
if request_models:
|
| 131 |
+
refs = [{"$ref": f"#/components/schemas/{model}"} for model in request_models]
|
| 132 |
operation["requestBody"] = {"required": True, "content": {"application/json": {
|
| 133 |
+
"schema": refs[0] if len(refs) == 1 else {"anyOf": refs}}}}
|
| 134 |
session_out = schemas.get("SessionOut", {}).get("properties", {})
|
| 135 |
if "report" in session_out:
|
| 136 |
+
session_out["report"] = {"anyOf": [{"$ref": "#/components/schemas/SwingReport"},
|
| 137 |
+
{"$ref": "#/components/schemas/PitchReport"}, {"type": "null"}],
|
| 138 |
"description": "Null while status is pending"}
|
| 139 |
app.openapi_schema = spec
|
| 140 |
return spec
|
backend/app/modules/coach/repository.py
CHANGED
|
@@ -45,6 +45,8 @@ class CoachRepository(BaseRepository[Account]):
|
|
| 45 |
ranked = (
|
| 46 |
select(SwingSession.owner_id, SwingSession.mode, SwingSession.id, SwingSession.overall_score,
|
| 47 |
SwingSession.created_at, SwingSession.report["focus_area"]["display_name"].astext.label("focus"),
|
|
|
|
|
|
|
| 48 |
func.row_number().over(partition_by=(SwingSession.owner_id, SwingSession.mode),
|
| 49 |
order_by=(SwingSession.created_at.desc(), SwingSession.id.desc()))
|
| 50 |
.label("rn"))
|
|
|
|
| 45 |
ranked = (
|
| 46 |
select(SwingSession.owner_id, SwingSession.mode, SwingSession.id, SwingSession.overall_score,
|
| 47 |
SwingSession.created_at, SwingSession.report["focus_area"]["display_name"].astext.label("focus"),
|
| 48 |
+
SwingSession.report,
|
| 49 |
+
SwingSession.measurement_payload["schema_version"].astext.label("measurement_schema"),
|
| 50 |
func.row_number().over(partition_by=(SwingSession.owner_id, SwingSession.mode),
|
| 51 |
order_by=(SwingSession.created_at.desc(), SwingSession.id.desc()))
|
| 52 |
.label("rn"))
|
backend/app/modules/coach/service.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""Coach views: roster (F1), a player's sessions (F2) and the review queue (F3). Only the coach's own team."""
|
| 2 |
|
| 3 |
from datetime import UTC, datetime, time
|
|
|
|
| 4 |
from uuid import UUID
|
| 5 |
|
| 6 |
from sqlalchemy.ext.asyncio import AsyncSession
|
|
@@ -9,6 +10,7 @@ from app.common.academy_access import Staff, require_player, sessions_shared, vi
|
|
| 9 |
from app.common.schemas import Page
|
| 10 |
from app.core.errors import Forbidden
|
| 11 |
from app.core.pagination import PageParams, paginate
|
|
|
|
| 12 |
from app.integrations.storage import StorageClient
|
| 13 |
from app.modules.accounts.models import Account
|
| 14 |
from app.modules.coach.repository import (
|
|
@@ -46,6 +48,9 @@ class CoachService:
|
|
| 46 |
by_key: dict[tuple[UUID, str], list] = {}
|
| 47 |
recent_rows = await self.repo.recent_sessions(ids) if ids else []
|
| 48 |
for row in recent_rows: # ordered newest first within each (owner, mode)
|
|
|
|
|
|
|
|
|
|
| 49 |
by_key.setdefault((row.owner_id, row.mode), []).append(row)
|
| 50 |
|
| 51 |
items = []
|
|
|
|
| 1 |
"""Coach views: roster (F1), a player's sessions (F2) and the review queue (F3). Only the coach's own team."""
|
| 2 |
|
| 3 |
from datetime import UTC, datetime, time
|
| 4 |
+
from types import SimpleNamespace
|
| 5 |
from uuid import UUID
|
| 6 |
|
| 7 |
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
| 10 |
from app.common.schemas import Page
|
| 11 |
from app.core.errors import Forbidden
|
| 12 |
from app.core.pagination import PageParams, paginate
|
| 13 |
+
from app.integrations.pitching_reports import report_for_read
|
| 14 |
from app.integrations.storage import StorageClient
|
| 15 |
from app.modules.accounts.models import Account
|
| 16 |
from app.modules.coach.repository import (
|
|
|
|
| 48 |
by_key: dict[tuple[UUID, str], list] = {}
|
| 49 |
recent_rows = await self.repo.recent_sessions(ids) if ids else []
|
| 50 |
for row in recent_rows: # ordered newest first within each (owner, mode)
|
| 51 |
+
report = report_for_read(row.mode, row.report, {"schema_version": row.measurement_schema})
|
| 52 |
+
if report is not row.report:
|
| 53 |
+
row = SimpleNamespace(**{**row._mapping, "overall_score": None, "focus": None})
|
| 54 |
by_key.setdefault((row.owner_id, row.mode), []).append(row)
|
| 55 |
|
| 56 |
items = []
|
backend/app/modules/sessions/service.py
CHANGED
|
@@ -14,6 +14,7 @@ from app.common.schemas import Page
|
|
| 14 |
from app.core.config import get_settings
|
| 15 |
from app.core.errors import Forbidden, NotFound, Unprocessable, ValidationFailed
|
| 16 |
from app.core.pagination import PageParams, paginate
|
|
|
|
| 17 |
from app.integrations.storage import StorageClient
|
| 18 |
from app.modules.accounts.models import Account
|
| 19 |
from app.modules.billing.entitlement import EntitlementService
|
|
@@ -171,17 +172,21 @@ class SessionService:
|
|
| 171 |
review = ReviewOut(coach_id=r.coach_id, coach_name=coach_name, cue=r.cue, drill_id=r.drill_id,
|
| 172 |
verdicts=r.verdicts, at=r.updated_at, voice_note=voice_note)
|
| 173 |
previous = await self.sessions.previous(s)
|
|
|
|
|
|
|
|
|
|
| 174 |
thumb_key = keys.get(s.thumbnail_upload_id) if s.thumbnail_upload_id else None
|
| 175 |
return SessionOut(
|
| 176 |
id=s.id, owner_id=s.owner_id, is_self=s.is_self, mode=s.mode, status=s.status,
|
| 177 |
created_at=s.created_at, analyzed_at=s.analyzed_at,
|
| 178 |
athlete=s.athlete if include_body_data else _without_body_data(s.athlete),
|
| 179 |
-
duration_sec=float(s.duration_sec), fps=s.fps, marks=s.marks,
|
|
|
|
| 180 |
media=MediaOut(
|
| 181 |
video_url=self.storage.presign_get(keys[s.video_upload_id]),
|
| 182 |
thumbnail_url=self.storage.presign_get(thumb_key) if thumb_key else None,
|
| 183 |
expires_at=datetime.now(UTC) + timedelta(seconds=self.storage.download_ttl)),
|
| 184 |
-
previous=PreviousOut(id=previous.id, overall_score=
|
| 185 |
created_at=previous.created_at) if previous else None,
|
| 186 |
ordinal=await self.sessions.ordinal(s),
|
| 187 |
)
|
|
|
|
| 14 |
from app.core.config import get_settings
|
| 15 |
from app.core.errors import Forbidden, NotFound, Unprocessable, ValidationFailed
|
| 16 |
from app.core.pagination import PageParams, paginate
|
| 17 |
+
from app.integrations.pitching_reports import report_for_read
|
| 18 |
from app.integrations.storage import StorageClient
|
| 19 |
from app.modules.accounts.models import Account
|
| 20 |
from app.modules.billing.entitlement import EntitlementService
|
|
|
|
| 172 |
review = ReviewOut(coach_id=r.coach_id, coach_name=coach_name, cue=r.cue, drill_id=r.drill_id,
|
| 173 |
verdicts=r.verdicts, at=r.updated_at, voice_note=voice_note)
|
| 174 |
previous = await self.sessions.previous(s)
|
| 175 |
+
previous_report = (report_for_read(previous.mode, previous.report, previous.measurement_payload)
|
| 176 |
+
if previous else None)
|
| 177 |
+
previous_score = previous.overall_score if previous and previous_report is previous.report else None
|
| 178 |
thumb_key = keys.get(s.thumbnail_upload_id) if s.thumbnail_upload_id else None
|
| 179 |
return SessionOut(
|
| 180 |
id=s.id, owner_id=s.owner_id, is_self=s.is_self, mode=s.mode, status=s.status,
|
| 181 |
created_at=s.created_at, analyzed_at=s.analyzed_at,
|
| 182 |
athlete=s.athlete if include_body_data else _without_body_data(s.athlete),
|
| 183 |
+
duration_sec=float(s.duration_sec), fps=s.fps, marks=s.marks,
|
| 184 |
+
report=report_for_read(s.mode, s.report, s.measurement_payload), review=review,
|
| 185 |
media=MediaOut(
|
| 186 |
video_url=self.storage.presign_get(keys[s.video_upload_id]),
|
| 187 |
thumbnail_url=self.storage.presign_get(thumb_key) if thumb_key else None,
|
| 188 |
expires_at=datetime.now(UTC) + timedelta(seconds=self.storage.download_ttl)),
|
| 189 |
+
previous=PreviousOut(id=previous.id, overall_score=previous_score,
|
| 190 |
created_at=previous.created_at) if previous else None,
|
| 191 |
ordinal=await self.sessions.ordinal(s),
|
| 192 |
)
|
backend/app/modules/sessions/summary.py
CHANGED
|
@@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|
| 9 |
from sqlalchemy.orm import aliased
|
| 10 |
|
| 11 |
from app.common.schemas import ResponseModel
|
|
|
|
| 12 |
from app.integrations.storage import StorageClient
|
| 13 |
from app.modules.accounts.models import Account
|
| 14 |
from app.modules.reviews.models import Review
|
|
@@ -66,13 +67,14 @@ def _focus(report: dict | None) -> FocusSummary | None:
|
|
| 66 |
|
| 67 |
async def load_summaries(db: AsyncSession, storage: StorageClient, query: Select) -> list[SessionSummary]:
|
| 68 |
rows: Sequence = (await db.execute(query)).all()
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
id=s.id, owner_id=s.owner_id, mode=s.mode, is_self=s.is_self, athlete_name=s.athlete.get("name", ""),
|
| 72 |
-
status=s.status, overall_score=s.overall_score,
|
| 73 |
-
overall_score_is_tentative=bool((
|
| 74 |
review=ReviewSummary(coach_name=coach_name or "", at=reviewed_at) if reviewed_at else None,
|
| 75 |
thumbnail_url=storage.presign_get(thumb_key) if thumb_key else None, created_at=s.created_at,
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
]
|
|
|
|
| 9 |
from sqlalchemy.orm import aliased
|
| 10 |
|
| 11 |
from app.common.schemas import ResponseModel
|
| 12 |
+
from app.integrations.pitching_reports import report_for_read
|
| 13 |
from app.integrations.storage import StorageClient
|
| 14 |
from app.modules.accounts.models import Account
|
| 15 |
from app.modules.reviews.models import Review
|
|
|
|
| 67 |
|
| 68 |
async def load_summaries(db: AsyncSession, storage: StorageClient, query: Select) -> list[SessionSummary]:
|
| 69 |
rows: Sequence = (await db.execute(query)).all()
|
| 70 |
+
summaries = []
|
| 71 |
+
for s, thumb_key, reviewed_at, coach_name in rows:
|
| 72 |
+
report = report_for_read(s.mode, s.report, s.measurement_payload)
|
| 73 |
+
summaries.append(SessionSummary(
|
| 74 |
id=s.id, owner_id=s.owner_id, mode=s.mode, is_self=s.is_self, athlete_name=s.athlete.get("name", ""),
|
| 75 |
+
status=s.status, overall_score=s.overall_score if report is s.report else None,
|
| 76 |
+
overall_score_is_tentative=bool((report or {}).get("overall_score_is_tentative")), focus=_focus(report),
|
| 77 |
review=ReviewSummary(coach_name=coach_name or "", at=reviewed_at) if reviewed_at else None,
|
| 78 |
thumbnail_url=storage.presign_get(thumb_key) if thumb_key else None, created_at=s.created_at,
|
| 79 |
+
))
|
| 80 |
+
return summaries
|
|
|
backend/app/modules/swing_reports/controller.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
"""H1: POST /v1/sessions/{session_id}/swing-report (contract 1.0/1.1) and /pitch-report (
|
| 2 |
|
| 3 |
-
The body is the ML API's payload, unchanged.
|
| 4 |
"""
|
| 5 |
|
| 6 |
import uuid
|
|
|
|
| 1 |
+
"""H1: POST /v1/sessions/{session_id}/swing-report (contract 1.0/1.1) and /pitch-report (pitch-1.0/1.1).
|
| 2 |
|
| 3 |
+
The body is the ML API's payload, unchanged. Pitch-1.1 returns the pitching report extension.
|
| 4 |
"""
|
| 5 |
|
| 6 |
import uuid
|
backend/app/modules/swing_reports/service.py
CHANGED
|
@@ -24,6 +24,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|
| 24 |
from app.common.consent import analysis_consent_blocked
|
| 25 |
from app.core.config import get_settings
|
| 26 |
from app.core.errors import Conflict, Forbidden, NotFound, ServiceUnavailable, Unprocessable
|
|
|
|
| 27 |
from app.modules.accounts.models import Account
|
| 28 |
from app.modules.billing.entitlement import EntitlementService
|
| 29 |
from app.modules.swing_reports.repository import SwingReportRepository
|
|
@@ -86,12 +87,6 @@ def pitch_marks(events: Any) -> dict:
|
|
| 86 |
return marks
|
| 87 |
|
| 88 |
|
| 89 |
-
def obsolete_pitch_coaching(report: dict) -> bool:
|
| 90 |
-
return (report.get("coaching") or {}).get("evidence_mode") != "ml_measurements_and_motion" or (
|
| 91 |
-
report.get("visual_evidence") is not None
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
|
| 95 |
@dataclass(frozen=True)
|
| 96 |
class ReportKind:
|
| 97 |
mode: str # session mode this report is for
|
|
|
|
| 24 |
from app.common.consent import analysis_consent_blocked
|
| 25 |
from app.core.config import get_settings
|
| 26 |
from app.core.errors import Conflict, Forbidden, NotFound, ServiceUnavailable, Unprocessable
|
| 27 |
+
from app.integrations.pitching_reports import obsolete_pitch_coaching
|
| 28 |
from app.modules.accounts.models import Account
|
| 29 |
from app.modules.billing.entitlement import EntitlementService
|
| 30 |
from app.modules.swing_reports.repository import SwingReportRepository
|
|
|
|
| 87 |
return marks
|
| 88 |
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
@dataclass(frozen=True)
|
| 91 |
class ReportKind:
|
| 92 |
mode: str # session mode this report is for
|
backend/docs/FRONTEND_INTEGRATION.md
CHANGED
|
@@ -10,14 +10,19 @@
|
|
| 10 |
|
| 11 |
| What | Where | Use it for |
|
| 12 |
|---|---|---|
|
| 13 |
-
| Machine-readable API | `backend/docs/openapi.json` (also served at `GET /openapi.json`
|
| 14 |
| Swing report (the analysis result) | `AI-coach-agent/docs/SWING_REPORT_API.md` | How to render scores, ratings, groups, focus area and measurements |
|
|
|
|
| 15 |
| ML payload the app forwards | `backend/docs/reference/ml_contract_v1.md` | What the ML API returns and the app posts to us, unchanged |
|
| 16 |
| This guide | `backend/docs/FRONTEND_INTEGRATION.md` | Flows, mapping from the old store, rules, edge cases |
|
| 17 |
| Coaching workflow contract | `backend/docs/reference/coaching_workflow_spec.md` and `coaching_workflow_decisions.md` | Spec IDs N01–N50 and C01–C08 used in §14 |
|
| 18 |
|
| 19 |
When this guide and `openapi.json` disagree, `openapi.json` wins. Please report the mismatch.
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
## 1. Conventions
|
| 22 |
|
| 23 |
- **Base URL:** `https://<api host>/v1/...` (deployment owns the host). Local development: `http://127.0.0.1:8000`.
|
|
@@ -87,7 +92,7 @@ All endpoints except `/v1/auth/*` (other than logout) need it.
|
|
| 87 |
| 413 | `TOO_LARGE` | Uploads, swing report | "Clip too large" |
|
| 88 |
| 422 | `UPLOAD_MISSING`, `UPLOAD_INVALID` | Create session | Upload again, or record again |
|
| 89 |
| 422 | `INVALID_PAYLOAD` | Swing report | The ML payload broke the contract. Log `fields` and show "analysis failed, please re-film". |
|
| 90 |
-
| 422 | `MODE_NOT_SUPPORTED` |
|
| 91 |
| 422 | `RECEIPT_INVALID` | Billing | "Purchase could not be verified" |
|
| 92 |
| 429 | `RATE_LIMITED` | Login, forgot password, team lookup | "Too many attempts. Wait a minute." |
|
| 93 |
| 5xx | `INTERNAL` / `UNAVAILABLE` | Any | Generic retry message |
|
|
|
|
| 10 |
|
| 11 |
| What | Where | Use it for |
|
| 12 |
|---|---|---|
|
| 13 |
+
| Machine-readable API | `backend/docs/openapi.json` (also served at `GET /openapi.json` where enabled) | Generate TypeScript types. Errors use the envelope in §3. Swing and pitching report requests/responses are typed, and saved session reports include both kinds plus null. |
|
| 14 |
| Swing report (the analysis result) | `AI-coach-agent/docs/SWING_REPORT_API.md` | How to render scores, ratings, groups, focus area and measurements |
|
| 15 |
+
| Pitching integration | [Pitching API integration](../../docs/PITCHING_APP_INTEGRATION.md) | Pitching marks/context, `pitch-1.1` ML payload, report groups, unavailable scores and coaching retry |
|
| 16 |
| ML payload the app forwards | `backend/docs/reference/ml_contract_v1.md` | What the ML API returns and the app posts to us, unchanged |
|
| 17 |
| This guide | `backend/docs/FRONTEND_INTEGRATION.md` | Flows, mapping from the old store, rules, edge cases |
|
| 18 |
| Coaching workflow contract | `backend/docs/reference/coaching_workflow_spec.md` and `coaching_workflow_decisions.md` | Spec IDs N01–N50 and C01–C08 used in §14 |
|
| 19 |
|
| 20 |
When this guide and `openapi.json` disagree, `openapi.json` wins. Please report the mismatch.
|
| 21 |
|
| 22 |
+
Regenerate older client models before adding pitching: `POST /v1/sessions/{id}/pitch-report` accepts both `pitch-1.0` and `pitch-1.1`. `SessionOut.report` is a nullable union of the existing swing/legacy report and the current pitching report. Report `schema_version` remains `1.0` for both; use `discipline` when present and session `mode` for legacy reports. Numeric pitching scores are currently null by design.
|
| 23 |
+
|
| 24 |
+
When generating with `openapi-typescript`, use `--default-non-nullable false` so optional fields with defaults remain optional. Version 7.13.0 with that setting passed strict TypeScript compilation using current pitching, legacy pitching and hitting fixtures; the pitching guide includes the complete command.
|
| 25 |
+
|
| 26 |
## 1. Conventions
|
| 27 |
|
| 28 |
- **Base URL:** `https://<api host>/v1/...` (deployment owns the host). Local development: `http://127.0.0.1:8000`.
|
|
|
|
| 92 |
| 413 | `TOO_LARGE` | Uploads, swing report | "Clip too large" |
|
| 93 |
| 422 | `UPLOAD_MISSING`, `UPLOAD_INVALID` | Create session | Upload again, or record again |
|
| 94 |
| 422 | `INVALID_PAYLOAD` | Swing report | The ML payload broke the contract. Log `fields` and show "analysis failed, please re-film". |
|
| 95 |
+
| 422 | `MODE_NOT_SUPPORTED` | Report route does not match session mode, or unsupported coaching retry | Use `/swing-report` for `mode=h` and `/pitch-report` for `mode=p`; coaching retry requires saved pitch-1.1 evidence. |
|
| 96 |
| 422 | `RECEIPT_INVALID` | Billing | "Purchase could not be verified" |
|
| 97 |
| 429 | `RATE_LIMITED` | Login, forgot password, team lookup | "Too many attempts. Wait a minute." |
|
| 98 |
| 5xx | `INTERNAL` / `UNAVAILABLE` | Any | Generic retry message |
|
backend/docs/openapi.json
CHANGED
|
@@ -1436,7 +1436,14 @@
|
|
| 1436 |
"content": {
|
| 1437 |
"application/json": {
|
| 1438 |
"schema": {
|
| 1439 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1440 |
}
|
| 1441 |
}
|
| 1442 |
}
|
|
@@ -8435,12 +8442,9 @@
|
|
| 8435 |
},
|
| 8436 |
"evidence_mode": {
|
| 8437 |
"type": "string",
|
| 8438 |
-
"
|
| 8439 |
-
"video_derived_measurements_and_motion",
|
| 8440 |
-
"visual_observations_and_motion"
|
| 8441 |
-
],
|
| 8442 |
"title": "Evidence Mode",
|
| 8443 |
-
"default": "
|
| 8444 |
},
|
| 8445 |
"review_status": {
|
| 8446 |
"type": "string",
|
|
@@ -12658,14 +12662,8 @@
|
|
| 12658 |
]
|
| 12659 |
},
|
| 12660 |
"visual_evidence": {
|
| 12661 |
-
"
|
| 12662 |
-
|
| 12663 |
-
"$ref": "#/components/schemas/VisualEvidence"
|
| 12664 |
-
},
|
| 12665 |
-
{
|
| 12666 |
-
"type": "null"
|
| 12667 |
-
}
|
| 12668 |
-
]
|
| 12669 |
}
|
| 12670 |
},
|
| 12671 |
"additionalProperties": false,
|
|
@@ -14188,6 +14186,9 @@
|
|
| 14188 |
{
|
| 14189 |
"$ref": "#/components/schemas/SwingReport"
|
| 14190 |
},
|
|
|
|
|
|
|
|
|
|
| 14191 |
{
|
| 14192 |
"type": "null"
|
| 14193 |
}
|
|
@@ -15504,114 +15505,6 @@
|
|
| 15504 |
],
|
| 15505 |
"title": "UserOut"
|
| 15506 |
},
|
| 15507 |
-
"VisualEvidence": {
|
| 15508 |
-
"properties": {
|
| 15509 |
-
"status": {
|
| 15510 |
-
"type": "string",
|
| 15511 |
-
"enum": [
|
| 15512 |
-
"provisional",
|
| 15513 |
-
"unavailable"
|
| 15514 |
-
],
|
| 15515 |
-
"title": "Status"
|
| 15516 |
-
},
|
| 15517 |
-
"model": {
|
| 15518 |
-
"anyOf": [
|
| 15519 |
-
{
|
| 15520 |
-
"type": "string"
|
| 15521 |
-
},
|
| 15522 |
-
{
|
| 15523 |
-
"type": "null"
|
| 15524 |
-
}
|
| 15525 |
-
],
|
| 15526 |
-
"title": "Model"
|
| 15527 |
-
},
|
| 15528 |
-
"sampled_frames": {
|
| 15529 |
-
"items": {
|
| 15530 |
-
"type": "integer"
|
| 15531 |
-
},
|
| 15532 |
-
"type": "array",
|
| 15533 |
-
"maxItems": 48,
|
| 15534 |
-
"title": "Sampled Frames"
|
| 15535 |
-
},
|
| 15536 |
-
"observations": {
|
| 15537 |
-
"items": {
|
| 15538 |
-
"$ref": "#/components/schemas/VisualObservation"
|
| 15539 |
-
},
|
| 15540 |
-
"type": "array",
|
| 15541 |
-
"maxItems": 4,
|
| 15542 |
-
"title": "Observations"
|
| 15543 |
-
},
|
| 15544 |
-
"reason": {
|
| 15545 |
-
"anyOf": [
|
| 15546 |
-
{
|
| 15547 |
-
"type": "string"
|
| 15548 |
-
},
|
| 15549 |
-
{
|
| 15550 |
-
"type": "null"
|
| 15551 |
-
}
|
| 15552 |
-
],
|
| 15553 |
-
"title": "Reason"
|
| 15554 |
-
},
|
| 15555 |
-
"validation": {
|
| 15556 |
-
"type": "string",
|
| 15557 |
-
"const": "unvalidated_visual_observations",
|
| 15558 |
-
"title": "Validation",
|
| 15559 |
-
"default": "unvalidated_visual_observations"
|
| 15560 |
-
}
|
| 15561 |
-
},
|
| 15562 |
-
"additionalProperties": false,
|
| 15563 |
-
"type": "object",
|
| 15564 |
-
"required": [
|
| 15565 |
-
"status"
|
| 15566 |
-
],
|
| 15567 |
-
"title": "VisualEvidence"
|
| 15568 |
-
},
|
| 15569 |
-
"VisualObservation": {
|
| 15570 |
-
"properties": {
|
| 15571 |
-
"topic": {
|
| 15572 |
-
"type": "string",
|
| 15573 |
-
"enum": [
|
| 15574 |
-
"loading",
|
| 15575 |
-
"plant",
|
| 15576 |
-
"rotation",
|
| 15577 |
-
"finish"
|
| 15578 |
-
],
|
| 15579 |
-
"title": "Topic"
|
| 15580 |
-
},
|
| 15581 |
-
"status": {
|
| 15582 |
-
"type": "string",
|
| 15583 |
-
"enum": [
|
| 15584 |
-
"observed",
|
| 15585 |
-
"unclear"
|
| 15586 |
-
],
|
| 15587 |
-
"title": "Status"
|
| 15588 |
-
},
|
| 15589 |
-
"description": {
|
| 15590 |
-
"type": "string",
|
| 15591 |
-
"maxLength": 600,
|
| 15592 |
-
"minLength": 1,
|
| 15593 |
-
"title": "Description"
|
| 15594 |
-
},
|
| 15595 |
-
"evidence_frames": {
|
| 15596 |
-
"items": {
|
| 15597 |
-
"type": "integer"
|
| 15598 |
-
},
|
| 15599 |
-
"type": "array",
|
| 15600 |
-
"maxItems": 8,
|
| 15601 |
-
"minItems": 2,
|
| 15602 |
-
"title": "Evidence Frames"
|
| 15603 |
-
}
|
| 15604 |
-
},
|
| 15605 |
-
"additionalProperties": false,
|
| 15606 |
-
"type": "object",
|
| 15607 |
-
"required": [
|
| 15608 |
-
"topic",
|
| 15609 |
-
"status",
|
| 15610 |
-
"description",
|
| 15611 |
-
"evidence_frames"
|
| 15612 |
-
],
|
| 15613 |
-
"title": "VisualObservation"
|
| 15614 |
-
},
|
| 15615 |
"VoiceIn": {
|
| 15616 |
"properties": {
|
| 15617 |
"kind": {
|
|
@@ -17246,6 +17139,980 @@
|
|
| 17246 |
],
|
| 17247 |
"title": "ValueInterval",
|
| 17248 |
"type": "object"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17249 |
}
|
| 17250 |
}
|
| 17251 |
}
|
|
|
|
| 1436 |
"content": {
|
| 1437 |
"application/json": {
|
| 1438 |
"schema": {
|
| 1439 |
+
"anyOf": [
|
| 1440 |
+
{
|
| 1441 |
+
"$ref": "#/components/schemas/PitchAnalysisPayload"
|
| 1442 |
+
},
|
| 1443 |
+
{
|
| 1444 |
+
"$ref": "#/components/schemas/PitchPayload"
|
| 1445 |
+
}
|
| 1446 |
+
]
|
| 1447 |
}
|
| 1448 |
}
|
| 1449 |
}
|
|
|
|
| 8442 |
},
|
| 8443 |
"evidence_mode": {
|
| 8444 |
"type": "string",
|
| 8445 |
+
"const": "ml_measurements_and_motion",
|
|
|
|
|
|
|
|
|
|
| 8446 |
"title": "Evidence Mode",
|
| 8447 |
+
"default": "ml_measurements_and_motion"
|
| 8448 |
},
|
| 8449 |
"review_status": {
|
| 8450 |
"type": "string",
|
|
|
|
| 12662 |
]
|
| 12663 |
},
|
| 12664 |
"visual_evidence": {
|
| 12665 |
+
"type": "null",
|
| 12666 |
+
"title": "Visual Evidence"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12667 |
}
|
| 12668 |
},
|
| 12669 |
"additionalProperties": false,
|
|
|
|
| 14186 |
{
|
| 14187 |
"$ref": "#/components/schemas/SwingReport"
|
| 14188 |
},
|
| 14189 |
+
{
|
| 14190 |
+
"$ref": "#/components/schemas/PitchReport"
|
| 14191 |
+
},
|
| 14192 |
{
|
| 14193 |
"type": "null"
|
| 14194 |
}
|
|
|
|
| 15505 |
],
|
| 15506 |
"title": "UserOut"
|
| 15507 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15508 |
"VoiceIn": {
|
| 15509 |
"properties": {
|
| 15510 |
"kind": {
|
|
|
|
| 17139 |
],
|
| 17140 |
"title": "ValueInterval",
|
| 17141 |
"type": "object"
|
| 17142 |
+
},
|
| 17143 |
+
"PitchPayload_ClockEvidence": {
|
| 17144 |
+
"additionalProperties": false,
|
| 17145 |
+
"properties": {
|
| 17146 |
+
"kind": {
|
| 17147 |
+
"enum": [
|
| 17148 |
+
"unknown",
|
| 17149 |
+
"unretimed",
|
| 17150 |
+
"constant_slowdown",
|
| 17151 |
+
"explicit"
|
| 17152 |
+
],
|
| 17153 |
+
"title": "Kind",
|
| 17154 |
+
"type": "string"
|
| 17155 |
+
},
|
| 17156 |
+
"source": {
|
| 17157 |
+
"anyOf": [
|
| 17158 |
+
{
|
| 17159 |
+
"type": "string"
|
| 17160 |
+
},
|
| 17161 |
+
{
|
| 17162 |
+
"type": "null"
|
| 17163 |
+
}
|
| 17164 |
+
],
|
| 17165 |
+
"title": "Source"
|
| 17166 |
+
},
|
| 17167 |
+
"physical_time_available": {
|
| 17168 |
+
"title": "Physical Time Available",
|
| 17169 |
+
"type": "boolean"
|
| 17170 |
+
},
|
| 17171 |
+
"median_playback_fps": {
|
| 17172 |
+
"anyOf": [
|
| 17173 |
+
{
|
| 17174 |
+
"exclusiveMinimum": 0,
|
| 17175 |
+
"type": "number"
|
| 17176 |
+
},
|
| 17177 |
+
{
|
| 17178 |
+
"type": "null"
|
| 17179 |
+
}
|
| 17180 |
+
],
|
| 17181 |
+
"title": "Median Playback Fps"
|
| 17182 |
+
},
|
| 17183 |
+
"median_capture_fps": {
|
| 17184 |
+
"anyOf": [
|
| 17185 |
+
{
|
| 17186 |
+
"exclusiveMinimum": 0,
|
| 17187 |
+
"type": "number"
|
| 17188 |
+
},
|
| 17189 |
+
{
|
| 17190 |
+
"type": "null"
|
| 17191 |
+
}
|
| 17192 |
+
],
|
| 17193 |
+
"title": "Median Capture Fps"
|
| 17194 |
+
},
|
| 17195 |
+
"minimum_capture_interval_ms": {
|
| 17196 |
+
"anyOf": [
|
| 17197 |
+
{
|
| 17198 |
+
"exclusiveMinimum": 0,
|
| 17199 |
+
"type": "number"
|
| 17200 |
+
},
|
| 17201 |
+
{
|
| 17202 |
+
"type": "null"
|
| 17203 |
+
}
|
| 17204 |
+
],
|
| 17205 |
+
"title": "Minimum Capture Interval Ms"
|
| 17206 |
+
},
|
| 17207 |
+
"maximum_capture_interval_ms": {
|
| 17208 |
+
"anyOf": [
|
| 17209 |
+
{
|
| 17210 |
+
"exclusiveMinimum": 0,
|
| 17211 |
+
"type": "number"
|
| 17212 |
+
},
|
| 17213 |
+
{
|
| 17214 |
+
"type": "null"
|
| 17215 |
+
}
|
| 17216 |
+
],
|
| 17217 |
+
"title": "Maximum Capture Interval Ms"
|
| 17218 |
+
},
|
| 17219 |
+
"reasons": {
|
| 17220 |
+
"items": {
|
| 17221 |
+
"type": "string"
|
| 17222 |
+
},
|
| 17223 |
+
"title": "Reasons",
|
| 17224 |
+
"type": "array"
|
| 17225 |
+
}
|
| 17226 |
+
},
|
| 17227 |
+
"required": [
|
| 17228 |
+
"kind",
|
| 17229 |
+
"source",
|
| 17230 |
+
"physical_time_available",
|
| 17231 |
+
"median_playback_fps",
|
| 17232 |
+
"median_capture_fps",
|
| 17233 |
+
"minimum_capture_interval_ms",
|
| 17234 |
+
"maximum_capture_interval_ms",
|
| 17235 |
+
"reasons"
|
| 17236 |
+
],
|
| 17237 |
+
"title": "ClockEvidence",
|
| 17238 |
+
"type": "object"
|
| 17239 |
+
},
|
| 17240 |
+
"PitchPayload_Curve": {
|
| 17241 |
+
"additionalProperties": false,
|
| 17242 |
+
"properties": {
|
| 17243 |
+
"curve_id": {
|
| 17244 |
+
"enum": [
|
| 17245 |
+
"front_knee_flexion",
|
| 17246 |
+
"throwing_elbow_flexion",
|
| 17247 |
+
"torso_inclination",
|
| 17248 |
+
"hip_shoulder_separation",
|
| 17249 |
+
"pelvis_heading",
|
| 17250 |
+
"shoulder_heading"
|
| 17251 |
+
],
|
| 17252 |
+
"title": "Curve Id",
|
| 17253 |
+
"type": "string"
|
| 17254 |
+
},
|
| 17255 |
+
"unit": {
|
| 17256 |
+
"const": "deg",
|
| 17257 |
+
"default": "deg",
|
| 17258 |
+
"title": "Unit",
|
| 17259 |
+
"type": "string"
|
| 17260 |
+
},
|
| 17261 |
+
"samples": {
|
| 17262 |
+
"items": {
|
| 17263 |
+
"$ref": "#/components/schemas/PitchPayload_Sample"
|
| 17264 |
+
},
|
| 17265 |
+
"maxItems": 240,
|
| 17266 |
+
"title": "Samples",
|
| 17267 |
+
"type": "array"
|
| 17268 |
+
},
|
| 17269 |
+
"usable_frame_count": {
|
| 17270 |
+
"minimum": 0,
|
| 17271 |
+
"title": "Usable Frame Count",
|
| 17272 |
+
"type": "integer"
|
| 17273 |
+
},
|
| 17274 |
+
"total_frame_count": {
|
| 17275 |
+
"exclusiveMinimum": 0,
|
| 17276 |
+
"title": "Total Frame Count",
|
| 17277 |
+
"type": "integer"
|
| 17278 |
+
},
|
| 17279 |
+
"reasons": {
|
| 17280 |
+
"items": {
|
| 17281 |
+
"type": "string"
|
| 17282 |
+
},
|
| 17283 |
+
"title": "Reasons",
|
| 17284 |
+
"type": "array"
|
| 17285 |
+
}
|
| 17286 |
+
},
|
| 17287 |
+
"required": [
|
| 17288 |
+
"curve_id",
|
| 17289 |
+
"samples",
|
| 17290 |
+
"usable_frame_count",
|
| 17291 |
+
"total_frame_count",
|
| 17292 |
+
"reasons"
|
| 17293 |
+
],
|
| 17294 |
+
"title": "Curve",
|
| 17295 |
+
"type": "object"
|
| 17296 |
+
},
|
| 17297 |
+
"PitchPayload_DeliveryEvidence": {
|
| 17298 |
+
"additionalProperties": false,
|
| 17299 |
+
"properties": {
|
| 17300 |
+
"version": {
|
| 17301 |
+
"const": "pitch-evidence-1.0",
|
| 17302 |
+
"default": "pitch-evidence-1.0",
|
| 17303 |
+
"title": "Version",
|
| 17304 |
+
"type": "string"
|
| 17305 |
+
},
|
| 17306 |
+
"source_frame_count": {
|
| 17307 |
+
"exclusiveMinimum": 1,
|
| 17308 |
+
"title": "Source Frame Count",
|
| 17309 |
+
"type": "integer"
|
| 17310 |
+
},
|
| 17311 |
+
"start_frame": {
|
| 17312 |
+
"minimum": 0,
|
| 17313 |
+
"title": "Start Frame",
|
| 17314 |
+
"type": "integer"
|
| 17315 |
+
},
|
| 17316 |
+
"end_frame": {
|
| 17317 |
+
"minimum": 0,
|
| 17318 |
+
"title": "End Frame",
|
| 17319 |
+
"type": "integer"
|
| 17320 |
+
},
|
| 17321 |
+
"clock": {
|
| 17322 |
+
"$ref": "#/components/schemas/PitchPayload_ClockEvidence"
|
| 17323 |
+
},
|
| 17324 |
+
"curves": {
|
| 17325 |
+
"items": {
|
| 17326 |
+
"$ref": "#/components/schemas/PitchPayload_Curve"
|
| 17327 |
+
},
|
| 17328 |
+
"maxItems": 6,
|
| 17329 |
+
"title": "Curves",
|
| 17330 |
+
"type": "array"
|
| 17331 |
+
},
|
| 17332 |
+
"phases": {
|
| 17333 |
+
"items": {
|
| 17334 |
+
"$ref": "#/components/schemas/PitchPayload_Phase"
|
| 17335 |
+
},
|
| 17336 |
+
"maxItems": 4,
|
| 17337 |
+
"title": "Phases",
|
| 17338 |
+
"type": "array"
|
| 17339 |
+
},
|
| 17340 |
+
"sequencing": {
|
| 17341 |
+
"$ref": "#/components/schemas/PitchPayload_Sequencing"
|
| 17342 |
+
},
|
| 17343 |
+
"consistency": {
|
| 17344 |
+
"const": "not_assessable_single_delivery",
|
| 17345 |
+
"default": "not_assessable_single_delivery",
|
| 17346 |
+
"title": "Consistency",
|
| 17347 |
+
"type": "string"
|
| 17348 |
+
},
|
| 17349 |
+
"accuracy_status": {
|
| 17350 |
+
"const": "not_validated_for_this_recording",
|
| 17351 |
+
"default": "not_validated_for_this_recording",
|
| 17352 |
+
"title": "Accuracy Status",
|
| 17353 |
+
"type": "string"
|
| 17354 |
+
}
|
| 17355 |
+
},
|
| 17356 |
+
"required": [
|
| 17357 |
+
"source_frame_count",
|
| 17358 |
+
"start_frame",
|
| 17359 |
+
"end_frame",
|
| 17360 |
+
"clock",
|
| 17361 |
+
"curves",
|
| 17362 |
+
"phases",
|
| 17363 |
+
"sequencing"
|
| 17364 |
+
],
|
| 17365 |
+
"title": "DeliveryEvidence",
|
| 17366 |
+
"type": "object"
|
| 17367 |
+
},
|
| 17368 |
+
"PitchPayload_Event": {
|
| 17369 |
+
"additionalProperties": false,
|
| 17370 |
+
"properties": {
|
| 17371 |
+
"status": {
|
| 17372 |
+
"enum": [
|
| 17373 |
+
"limited",
|
| 17374 |
+
"unavailable"
|
| 17375 |
+
],
|
| 17376 |
+
"title": "Status",
|
| 17377 |
+
"type": "string"
|
| 17378 |
+
},
|
| 17379 |
+
"video_time_s": {
|
| 17380 |
+
"anyOf": [
|
| 17381 |
+
{
|
| 17382 |
+
"minimum": 0,
|
| 17383 |
+
"type": "number"
|
| 17384 |
+
},
|
| 17385 |
+
{
|
| 17386 |
+
"type": "null"
|
| 17387 |
+
}
|
| 17388 |
+
],
|
| 17389 |
+
"title": "Video Time S"
|
| 17390 |
+
},
|
| 17391 |
+
"capture_time_s": {
|
| 17392 |
+
"anyOf": [
|
| 17393 |
+
{
|
| 17394 |
+
"minimum": 0,
|
| 17395 |
+
"type": "number"
|
| 17396 |
+
},
|
| 17397 |
+
{
|
| 17398 |
+
"type": "null"
|
| 17399 |
+
}
|
| 17400 |
+
],
|
| 17401 |
+
"title": "Capture Time S"
|
| 17402 |
+
},
|
| 17403 |
+
"source_frame_index": {
|
| 17404 |
+
"anyOf": [
|
| 17405 |
+
{
|
| 17406 |
+
"minimum": 0,
|
| 17407 |
+
"type": "integer"
|
| 17408 |
+
},
|
| 17409 |
+
{
|
| 17410 |
+
"type": "null"
|
| 17411 |
+
}
|
| 17412 |
+
],
|
| 17413 |
+
"title": "Source Frame Index"
|
| 17414 |
+
},
|
| 17415 |
+
"source": {
|
| 17416 |
+
"anyOf": [
|
| 17417 |
+
{
|
| 17418 |
+
"enum": [
|
| 17419 |
+
"manual_review",
|
| 17420 |
+
"derived_from_release"
|
| 17421 |
+
],
|
| 17422 |
+
"type": "string"
|
| 17423 |
+
},
|
| 17424 |
+
{
|
| 17425 |
+
"type": "null"
|
| 17426 |
+
}
|
| 17427 |
+
],
|
| 17428 |
+
"title": "Source"
|
| 17429 |
+
},
|
| 17430 |
+
"reasons": {
|
| 17431 |
+
"items": {
|
| 17432 |
+
"enum": [
|
| 17433 |
+
"event_not_marked",
|
| 17434 |
+
"event_not_applicable",
|
| 17435 |
+
"event_timing_uncertain",
|
| 17436 |
+
"required_event_unavailable",
|
| 17437 |
+
"required_landmarks_unusable",
|
| 17438 |
+
"ground_plane_unknown",
|
| 17439 |
+
"camera_stability_unverified",
|
| 17440 |
+
"scale_unknown",
|
| 17441 |
+
"scale_is_model_estimated",
|
| 17442 |
+
"capture_time_unknown",
|
| 17443 |
+
"timing_resolution_insufficient",
|
| 17444 |
+
"follow_through_not_recorded",
|
| 17445 |
+
"model_accuracy_unvalidated",
|
| 17446 |
+
"temporal_inconsistency",
|
| 17447 |
+
"throwing_hand_unknown",
|
| 17448 |
+
"event_angle_unstable",
|
| 17449 |
+
"angle_sensitivity_unresolved"
|
| 17450 |
+
],
|
| 17451 |
+
"type": "string"
|
| 17452 |
+
},
|
| 17453 |
+
"minItems": 1,
|
| 17454 |
+
"title": "Reasons",
|
| 17455 |
+
"type": "array"
|
| 17456 |
+
}
|
| 17457 |
+
},
|
| 17458 |
+
"required": [
|
| 17459 |
+
"status",
|
| 17460 |
+
"video_time_s",
|
| 17461 |
+
"capture_time_s",
|
| 17462 |
+
"source_frame_index",
|
| 17463 |
+
"source",
|
| 17464 |
+
"reasons"
|
| 17465 |
+
],
|
| 17466 |
+
"title": "Event",
|
| 17467 |
+
"type": "object"
|
| 17468 |
+
},
|
| 17469 |
+
"PitchPayload_Events": {
|
| 17470 |
+
"additionalProperties": false,
|
| 17471 |
+
"properties": {
|
| 17472 |
+
"leg_lift": {
|
| 17473 |
+
"$ref": "#/components/schemas/PitchPayload_Event"
|
| 17474 |
+
},
|
| 17475 |
+
"foot_strike": {
|
| 17476 |
+
"$ref": "#/components/schemas/PitchPayload_Event"
|
| 17477 |
+
},
|
| 17478 |
+
"release": {
|
| 17479 |
+
"$ref": "#/components/schemas/PitchPayload_Event"
|
| 17480 |
+
},
|
| 17481 |
+
"early_follow_through": {
|
| 17482 |
+
"$ref": "#/components/schemas/PitchPayload_Event"
|
| 17483 |
+
}
|
| 17484 |
+
},
|
| 17485 |
+
"required": [
|
| 17486 |
+
"leg_lift",
|
| 17487 |
+
"foot_strike",
|
| 17488 |
+
"release",
|
| 17489 |
+
"early_follow_through"
|
| 17490 |
+
],
|
| 17491 |
+
"title": "Events",
|
| 17492 |
+
"type": "object"
|
| 17493 |
+
},
|
| 17494 |
+
"PitchPayload_Measurement": {
|
| 17495 |
+
"additionalProperties": false,
|
| 17496 |
+
"properties": {
|
| 17497 |
+
"metric_id": {
|
| 17498 |
+
"title": "Metric Id",
|
| 17499 |
+
"type": "string"
|
| 17500 |
+
},
|
| 17501 |
+
"group": {
|
| 17502 |
+
"enum": [
|
| 17503 |
+
"gather",
|
| 17504 |
+
"stride_plant",
|
| 17505 |
+
"rotation_release",
|
| 17506 |
+
"release_finish"
|
| 17507 |
+
],
|
| 17508 |
+
"title": "Group",
|
| 17509 |
+
"type": "string"
|
| 17510 |
+
},
|
| 17511 |
+
"unit": {
|
| 17512 |
+
"enum": [
|
| 17513 |
+
"deg",
|
| 17514 |
+
"cm",
|
| 17515 |
+
"ms"
|
| 17516 |
+
],
|
| 17517 |
+
"title": "Unit",
|
| 17518 |
+
"type": "string"
|
| 17519 |
+
},
|
| 17520 |
+
"reference": {
|
| 17521 |
+
"title": "Reference",
|
| 17522 |
+
"type": "string"
|
| 17523 |
+
},
|
| 17524 |
+
"event_ids": {
|
| 17525 |
+
"items": {
|
| 17526 |
+
"enum": [
|
| 17527 |
+
"leg_lift",
|
| 17528 |
+
"foot_strike",
|
| 17529 |
+
"release",
|
| 17530 |
+
"early_follow_through"
|
| 17531 |
+
],
|
| 17532 |
+
"type": "string"
|
| 17533 |
+
},
|
| 17534 |
+
"title": "Event Ids",
|
| 17535 |
+
"type": "array"
|
| 17536 |
+
},
|
| 17537 |
+
"value": {
|
| 17538 |
+
"anyOf": [
|
| 17539 |
+
{
|
| 17540 |
+
"type": "number"
|
| 17541 |
+
},
|
| 17542 |
+
{
|
| 17543 |
+
"type": "null"
|
| 17544 |
+
}
|
| 17545 |
+
],
|
| 17546 |
+
"title": "Value"
|
| 17547 |
+
},
|
| 17548 |
+
"status": {
|
| 17549 |
+
"enum": [
|
| 17550 |
+
"limited",
|
| 17551 |
+
"unavailable"
|
| 17552 |
+
],
|
| 17553 |
+
"title": "Status",
|
| 17554 |
+
"type": "string"
|
| 17555 |
+
},
|
| 17556 |
+
"confidence": {
|
| 17557 |
+
"default": null,
|
| 17558 |
+
"title": "Confidence",
|
| 17559 |
+
"type": "null"
|
| 17560 |
+
},
|
| 17561 |
+
"reasons": {
|
| 17562 |
+
"items": {
|
| 17563 |
+
"enum": [
|
| 17564 |
+
"event_not_marked",
|
| 17565 |
+
"event_not_applicable",
|
| 17566 |
+
"event_timing_uncertain",
|
| 17567 |
+
"required_event_unavailable",
|
| 17568 |
+
"required_landmarks_unusable",
|
| 17569 |
+
"ground_plane_unknown",
|
| 17570 |
+
"camera_stability_unverified",
|
| 17571 |
+
"scale_unknown",
|
| 17572 |
+
"scale_is_model_estimated",
|
| 17573 |
+
"capture_time_unknown",
|
| 17574 |
+
"timing_resolution_insufficient",
|
| 17575 |
+
"follow_through_not_recorded",
|
| 17576 |
+
"model_accuracy_unvalidated",
|
| 17577 |
+
"temporal_inconsistency",
|
| 17578 |
+
"throwing_hand_unknown",
|
| 17579 |
+
"event_angle_unstable",
|
| 17580 |
+
"angle_sensitivity_unresolved"
|
| 17581 |
+
],
|
| 17582 |
+
"type": "string"
|
| 17583 |
+
},
|
| 17584 |
+
"minItems": 1,
|
| 17585 |
+
"title": "Reasons",
|
| 17586 |
+
"type": "array"
|
| 17587 |
+
},
|
| 17588 |
+
"uses_interpolated_input": {
|
| 17589 |
+
"title": "Uses Interpolated Input",
|
| 17590 |
+
"type": "boolean"
|
| 17591 |
+
},
|
| 17592 |
+
"value_interval": {
|
| 17593 |
+
"anyOf": [
|
| 17594 |
+
{
|
| 17595 |
+
"$ref": "#/components/schemas/PitchPayload_ValueInterval"
|
| 17596 |
+
},
|
| 17597 |
+
{
|
| 17598 |
+
"type": "null"
|
| 17599 |
+
}
|
| 17600 |
+
],
|
| 17601 |
+
"default": null
|
| 17602 |
+
},
|
| 17603 |
+
"benchmark": {
|
| 17604 |
+
"default": null,
|
| 17605 |
+
"title": "Benchmark",
|
| 17606 |
+
"type": "null"
|
| 17607 |
+
}
|
| 17608 |
+
},
|
| 17609 |
+
"required": [
|
| 17610 |
+
"metric_id",
|
| 17611 |
+
"group",
|
| 17612 |
+
"unit",
|
| 17613 |
+
"reference",
|
| 17614 |
+
"event_ids",
|
| 17615 |
+
"value",
|
| 17616 |
+
"status",
|
| 17617 |
+
"reasons",
|
| 17618 |
+
"uses_interpolated_input"
|
| 17619 |
+
],
|
| 17620 |
+
"title": "Measurement",
|
| 17621 |
+
"type": "object"
|
| 17622 |
+
},
|
| 17623 |
+
"PitchPayload_Phase": {
|
| 17624 |
+
"additionalProperties": false,
|
| 17625 |
+
"properties": {
|
| 17626 |
+
"phase": {
|
| 17627 |
+
"enum": [
|
| 17628 |
+
"setup_to_lift",
|
| 17629 |
+
"move_to_plant",
|
| 17630 |
+
"plant_to_release",
|
| 17631 |
+
"recorded_finish"
|
| 17632 |
+
],
|
| 17633 |
+
"title": "Phase",
|
| 17634 |
+
"type": "string"
|
| 17635 |
+
},
|
| 17636 |
+
"start_frame": {
|
| 17637 |
+
"minimum": 0,
|
| 17638 |
+
"title": "Start Frame",
|
| 17639 |
+
"type": "integer"
|
| 17640 |
+
},
|
| 17641 |
+
"end_frame": {
|
| 17642 |
+
"minimum": 0,
|
| 17643 |
+
"title": "End Frame",
|
| 17644 |
+
"type": "integer"
|
| 17645 |
+
},
|
| 17646 |
+
"duration_ms": {
|
| 17647 |
+
"anyOf": [
|
| 17648 |
+
{
|
| 17649 |
+
"minimum": 0,
|
| 17650 |
+
"type": "number"
|
| 17651 |
+
},
|
| 17652 |
+
{
|
| 17653 |
+
"type": "null"
|
| 17654 |
+
}
|
| 17655 |
+
],
|
| 17656 |
+
"title": "Duration Ms"
|
| 17657 |
+
},
|
| 17658 |
+
"motion": {
|
| 17659 |
+
"items": {
|
| 17660 |
+
"$ref": "#/components/schemas/PitchPayload_PhaseMotion"
|
| 17661 |
+
},
|
| 17662 |
+
"title": "Motion",
|
| 17663 |
+
"type": "array"
|
| 17664 |
+
}
|
| 17665 |
+
},
|
| 17666 |
+
"required": [
|
| 17667 |
+
"phase",
|
| 17668 |
+
"start_frame",
|
| 17669 |
+
"end_frame",
|
| 17670 |
+
"duration_ms",
|
| 17671 |
+
"motion"
|
| 17672 |
+
],
|
| 17673 |
+
"title": "Phase",
|
| 17674 |
+
"type": "object"
|
| 17675 |
+
},
|
| 17676 |
+
"PitchPayload_PhaseMotion": {
|
| 17677 |
+
"additionalProperties": false,
|
| 17678 |
+
"properties": {
|
| 17679 |
+
"curve_id": {
|
| 17680 |
+
"enum": [
|
| 17681 |
+
"front_knee_flexion",
|
| 17682 |
+
"throwing_elbow_flexion",
|
| 17683 |
+
"torso_inclination",
|
| 17684 |
+
"hip_shoulder_separation",
|
| 17685 |
+
"pelvis_heading",
|
| 17686 |
+
"shoulder_heading"
|
| 17687 |
+
],
|
| 17688 |
+
"title": "Curve Id",
|
| 17689 |
+
"type": "string"
|
| 17690 |
+
},
|
| 17691 |
+
"start_value": {
|
| 17692 |
+
"anyOf": [
|
| 17693 |
+
{
|
| 17694 |
+
"type": "number"
|
| 17695 |
+
},
|
| 17696 |
+
{
|
| 17697 |
+
"type": "null"
|
| 17698 |
+
}
|
| 17699 |
+
],
|
| 17700 |
+
"title": "Start Value"
|
| 17701 |
+
},
|
| 17702 |
+
"end_value": {
|
| 17703 |
+
"anyOf": [
|
| 17704 |
+
{
|
| 17705 |
+
"type": "number"
|
| 17706 |
+
},
|
| 17707 |
+
{
|
| 17708 |
+
"type": "null"
|
| 17709 |
+
}
|
| 17710 |
+
],
|
| 17711 |
+
"title": "End Value"
|
| 17712 |
+
},
|
| 17713 |
+
"minimum": {
|
| 17714 |
+
"anyOf": [
|
| 17715 |
+
{
|
| 17716 |
+
"type": "number"
|
| 17717 |
+
},
|
| 17718 |
+
{
|
| 17719 |
+
"type": "null"
|
| 17720 |
+
}
|
| 17721 |
+
],
|
| 17722 |
+
"title": "Minimum"
|
| 17723 |
+
},
|
| 17724 |
+
"maximum": {
|
| 17725 |
+
"anyOf": [
|
| 17726 |
+
{
|
| 17727 |
+
"type": "number"
|
| 17728 |
+
},
|
| 17729 |
+
{
|
| 17730 |
+
"type": "null"
|
| 17731 |
+
}
|
| 17732 |
+
],
|
| 17733 |
+
"title": "Maximum"
|
| 17734 |
+
},
|
| 17735 |
+
"change": {
|
| 17736 |
+
"anyOf": [
|
| 17737 |
+
{
|
| 17738 |
+
"type": "number"
|
| 17739 |
+
},
|
| 17740 |
+
{
|
| 17741 |
+
"type": "null"
|
| 17742 |
+
}
|
| 17743 |
+
],
|
| 17744 |
+
"title": "Change"
|
| 17745 |
+
},
|
| 17746 |
+
"usable_frame_count": {
|
| 17747 |
+
"minimum": 0,
|
| 17748 |
+
"title": "Usable Frame Count",
|
| 17749 |
+
"type": "integer"
|
| 17750 |
+
},
|
| 17751 |
+
"reasons": {
|
| 17752 |
+
"items": {
|
| 17753 |
+
"type": "string"
|
| 17754 |
+
},
|
| 17755 |
+
"title": "Reasons",
|
| 17756 |
+
"type": "array"
|
| 17757 |
+
}
|
| 17758 |
+
},
|
| 17759 |
+
"required": [
|
| 17760 |
+
"curve_id",
|
| 17761 |
+
"start_value",
|
| 17762 |
+
"end_value",
|
| 17763 |
+
"minimum",
|
| 17764 |
+
"maximum",
|
| 17765 |
+
"change",
|
| 17766 |
+
"usable_frame_count",
|
| 17767 |
+
"reasons"
|
| 17768 |
+
],
|
| 17769 |
+
"title": "PhaseMotion",
|
| 17770 |
+
"type": "object"
|
| 17771 |
+
},
|
| 17772 |
+
"PitchPayload_PitchAthlete": {
|
| 17773 |
+
"additionalProperties": false,
|
| 17774 |
+
"properties": {
|
| 17775 |
+
"athlete_id": {
|
| 17776 |
+
"maxLength": 180,
|
| 17777 |
+
"minLength": 1,
|
| 17778 |
+
"pattern": "\\S",
|
| 17779 |
+
"title": "Athlete Id",
|
| 17780 |
+
"type": "string"
|
| 17781 |
+
},
|
| 17782 |
+
"throwing_hand": {
|
| 17783 |
+
"anyOf": [
|
| 17784 |
+
{
|
| 17785 |
+
"enum": [
|
| 17786 |
+
"left",
|
| 17787 |
+
"right"
|
| 17788 |
+
],
|
| 17789 |
+
"type": "string"
|
| 17790 |
+
},
|
| 17791 |
+
{
|
| 17792 |
+
"type": "null"
|
| 17793 |
+
}
|
| 17794 |
+
],
|
| 17795 |
+
"default": null,
|
| 17796 |
+
"title": "Throwing Hand"
|
| 17797 |
+
},
|
| 17798 |
+
"lead_foot": {
|
| 17799 |
+
"anyOf": [
|
| 17800 |
+
{
|
| 17801 |
+
"enum": [
|
| 17802 |
+
"left",
|
| 17803 |
+
"right"
|
| 17804 |
+
],
|
| 17805 |
+
"type": "string"
|
| 17806 |
+
},
|
| 17807 |
+
{
|
| 17808 |
+
"type": "null"
|
| 17809 |
+
}
|
| 17810 |
+
],
|
| 17811 |
+
"default": null,
|
| 17812 |
+
"title": "Lead Foot"
|
| 17813 |
+
},
|
| 17814 |
+
"age_years": {
|
| 17815 |
+
"anyOf": [
|
| 17816 |
+
{
|
| 17817 |
+
"minimum": 0,
|
| 17818 |
+
"type": "integer"
|
| 17819 |
+
},
|
| 17820 |
+
{
|
| 17821 |
+
"type": "null"
|
| 17822 |
+
}
|
| 17823 |
+
],
|
| 17824 |
+
"default": null,
|
| 17825 |
+
"title": "Age Years"
|
| 17826 |
+
},
|
| 17827 |
+
"height_cm": {
|
| 17828 |
+
"anyOf": [
|
| 17829 |
+
{
|
| 17830 |
+
"exclusiveMinimum": 0,
|
| 17831 |
+
"type": "number"
|
| 17832 |
+
},
|
| 17833 |
+
{
|
| 17834 |
+
"type": "null"
|
| 17835 |
+
}
|
| 17836 |
+
],
|
| 17837 |
+
"default": null,
|
| 17838 |
+
"title": "Height Cm"
|
| 17839 |
+
}
|
| 17840 |
+
},
|
| 17841 |
+
"required": [
|
| 17842 |
+
"athlete_id"
|
| 17843 |
+
],
|
| 17844 |
+
"title": "PitchAthlete",
|
| 17845 |
+
"type": "object"
|
| 17846 |
+
},
|
| 17847 |
+
"PitchPayload_PitchContext": {
|
| 17848 |
+
"additionalProperties": false,
|
| 17849 |
+
"properties": {
|
| 17850 |
+
"sport": {
|
| 17851 |
+
"const": "baseball",
|
| 17852 |
+
"default": "baseball",
|
| 17853 |
+
"title": "Sport",
|
| 17854 |
+
"type": "string"
|
| 17855 |
+
},
|
| 17856 |
+
"practice_type": {
|
| 17857 |
+
"default": "unknown",
|
| 17858 |
+
"enum": [
|
| 17859 |
+
"bullpen",
|
| 17860 |
+
"flat_ground",
|
| 17861 |
+
"live_bp",
|
| 17862 |
+
"game",
|
| 17863 |
+
"dry_delivery",
|
| 17864 |
+
"unknown"
|
| 17865 |
+
],
|
| 17866 |
+
"title": "Practice Type",
|
| 17867 |
+
"type": "string"
|
| 17868 |
+
},
|
| 17869 |
+
"drill_type": {
|
| 17870 |
+
"default": "unknown",
|
| 17871 |
+
"enum": [
|
| 17872 |
+
"standard",
|
| 17873 |
+
"step_back",
|
| 17874 |
+
"rocker",
|
| 17875 |
+
"other",
|
| 17876 |
+
"unknown"
|
| 17877 |
+
],
|
| 17878 |
+
"title": "Drill Type",
|
| 17879 |
+
"type": "string"
|
| 17880 |
+
},
|
| 17881 |
+
"pitch_type": {
|
| 17882 |
+
"default": "unknown",
|
| 17883 |
+
"enum": [
|
| 17884 |
+
"fastball",
|
| 17885 |
+
"breaking_ball",
|
| 17886 |
+
"changeup",
|
| 17887 |
+
"other",
|
| 17888 |
+
"unknown"
|
| 17889 |
+
],
|
| 17890 |
+
"title": "Pitch Type",
|
| 17891 |
+
"type": "string"
|
| 17892 |
+
},
|
| 17893 |
+
"ball_type": {
|
| 17894 |
+
"default": "unknown",
|
| 17895 |
+
"enum": [
|
| 17896 |
+
"baseball",
|
| 17897 |
+
"training_ball",
|
| 17898 |
+
"none",
|
| 17899 |
+
"unknown"
|
| 17900 |
+
],
|
| 17901 |
+
"title": "Ball Type",
|
| 17902 |
+
"type": "string"
|
| 17903 |
+
}
|
| 17904 |
+
},
|
| 17905 |
+
"title": "PitchContext",
|
| 17906 |
+
"type": "object"
|
| 17907 |
+
},
|
| 17908 |
+
"PitchPayload_Sample": {
|
| 17909 |
+
"additionalProperties": false,
|
| 17910 |
+
"properties": {
|
| 17911 |
+
"frame": {
|
| 17912 |
+
"minimum": 0,
|
| 17913 |
+
"title": "Frame",
|
| 17914 |
+
"type": "integer"
|
| 17915 |
+
},
|
| 17916 |
+
"value": {
|
| 17917 |
+
"anyOf": [
|
| 17918 |
+
{
|
| 17919 |
+
"type": "number"
|
| 17920 |
+
},
|
| 17921 |
+
{
|
| 17922 |
+
"type": "null"
|
| 17923 |
+
}
|
| 17924 |
+
],
|
| 17925 |
+
"title": "Value"
|
| 17926 |
+
}
|
| 17927 |
+
},
|
| 17928 |
+
"required": [
|
| 17929 |
+
"frame",
|
| 17930 |
+
"value"
|
| 17931 |
+
],
|
| 17932 |
+
"title": "Sample",
|
| 17933 |
+
"type": "object"
|
| 17934 |
+
},
|
| 17935 |
+
"PitchPayload_Sequencing": {
|
| 17936 |
+
"additionalProperties": false,
|
| 17937 |
+
"properties": {
|
| 17938 |
+
"status": {
|
| 17939 |
+
"enum": [
|
| 17940 |
+
"provisional",
|
| 17941 |
+
"unavailable"
|
| 17942 |
+
],
|
| 17943 |
+
"title": "Status",
|
| 17944 |
+
"type": "string"
|
| 17945 |
+
},
|
| 17946 |
+
"pelvis_peak_frame_interval": {
|
| 17947 |
+
"anyOf": [
|
| 17948 |
+
{
|
| 17949 |
+
"items": {
|
| 17950 |
+
"type": "integer"
|
| 17951 |
+
},
|
| 17952 |
+
"maxItems": 2,
|
| 17953 |
+
"minItems": 2,
|
| 17954 |
+
"type": "array"
|
| 17955 |
+
},
|
| 17956 |
+
{
|
| 17957 |
+
"type": "null"
|
| 17958 |
+
}
|
| 17959 |
+
],
|
| 17960 |
+
"default": null,
|
| 17961 |
+
"title": "Pelvis Peak Frame Interval"
|
| 17962 |
+
},
|
| 17963 |
+
"shoulder_peak_frame_interval": {
|
| 17964 |
+
"anyOf": [
|
| 17965 |
+
{
|
| 17966 |
+
"items": {
|
| 17967 |
+
"type": "integer"
|
| 17968 |
+
},
|
| 17969 |
+
"maxItems": 2,
|
| 17970 |
+
"minItems": 2,
|
| 17971 |
+
"type": "array"
|
| 17972 |
+
},
|
| 17973 |
+
{
|
| 17974 |
+
"type": "null"
|
| 17975 |
+
}
|
| 17976 |
+
],
|
| 17977 |
+
"default": null,
|
| 17978 |
+
"title": "Shoulder Peak Frame Interval"
|
| 17979 |
+
},
|
| 17980 |
+
"order": {
|
| 17981 |
+
"enum": [
|
| 17982 |
+
"pelvis_then_shoulders",
|
| 17983 |
+
"shoulders_then_pelvis",
|
| 17984 |
+
"unresolved"
|
| 17985 |
+
],
|
| 17986 |
+
"title": "Order",
|
| 17987 |
+
"type": "string"
|
| 17988 |
+
},
|
| 17989 |
+
"reasons": {
|
| 17990 |
+
"items": {
|
| 17991 |
+
"type": "string"
|
| 17992 |
+
},
|
| 17993 |
+
"title": "Reasons",
|
| 17994 |
+
"type": "array"
|
| 17995 |
+
}
|
| 17996 |
+
},
|
| 17997 |
+
"required": [
|
| 17998 |
+
"status",
|
| 17999 |
+
"order",
|
| 18000 |
+
"reasons"
|
| 18001 |
+
],
|
| 18002 |
+
"title": "Sequencing",
|
| 18003 |
+
"type": "object"
|
| 18004 |
+
},
|
| 18005 |
+
"PitchPayload_ValueInterval": {
|
| 18006 |
+
"additionalProperties": false,
|
| 18007 |
+
"properties": {
|
| 18008 |
+
"lower": {
|
| 18009 |
+
"title": "Lower",
|
| 18010 |
+
"type": "number"
|
| 18011 |
+
},
|
| 18012 |
+
"upper": {
|
| 18013 |
+
"title": "Upper",
|
| 18014 |
+
"type": "number"
|
| 18015 |
+
},
|
| 18016 |
+
"source": {
|
| 18017 |
+
"const": "adjacent_event_frames",
|
| 18018 |
+
"default": "adjacent_event_frames",
|
| 18019 |
+
"title": "Source",
|
| 18020 |
+
"type": "string"
|
| 18021 |
+
}
|
| 18022 |
+
},
|
| 18023 |
+
"required": [
|
| 18024 |
+
"lower",
|
| 18025 |
+
"upper"
|
| 18026 |
+
],
|
| 18027 |
+
"title": "ValueInterval",
|
| 18028 |
+
"type": "object"
|
| 18029 |
+
},
|
| 18030 |
+
"PitchPayload": {
|
| 18031 |
+
"additionalProperties": false,
|
| 18032 |
+
"properties": {
|
| 18033 |
+
"schema_version": {
|
| 18034 |
+
"const": "pitch-1.1",
|
| 18035 |
+
"default": "pitch-1.1",
|
| 18036 |
+
"title": "Schema Version",
|
| 18037 |
+
"type": "string"
|
| 18038 |
+
},
|
| 18039 |
+
"measurement_definitions_version": {
|
| 18040 |
+
"const": "pitch-1.1",
|
| 18041 |
+
"default": "pitch-1.1",
|
| 18042 |
+
"title": "Measurement Definitions Version",
|
| 18043 |
+
"type": "string"
|
| 18044 |
+
},
|
| 18045 |
+
"discipline": {
|
| 18046 |
+
"const": "pitching",
|
| 18047 |
+
"default": "pitching",
|
| 18048 |
+
"title": "Discipline",
|
| 18049 |
+
"type": "string"
|
| 18050 |
+
},
|
| 18051 |
+
"analysis_id": {
|
| 18052 |
+
"minLength": 1,
|
| 18053 |
+
"title": "Analysis Id",
|
| 18054 |
+
"type": "string"
|
| 18055 |
+
},
|
| 18056 |
+
"analysis_revision": {
|
| 18057 |
+
"minimum": 1,
|
| 18058 |
+
"title": "Analysis Revision",
|
| 18059 |
+
"type": "integer"
|
| 18060 |
+
},
|
| 18061 |
+
"pitch_id": {
|
| 18062 |
+
"minLength": 1,
|
| 18063 |
+
"title": "Pitch Id",
|
| 18064 |
+
"type": "string"
|
| 18065 |
+
},
|
| 18066 |
+
"status": {
|
| 18067 |
+
"const": "completed",
|
| 18068 |
+
"default": "completed",
|
| 18069 |
+
"title": "Status",
|
| 18070 |
+
"type": "string"
|
| 18071 |
+
},
|
| 18072 |
+
"athlete": {
|
| 18073 |
+
"$ref": "#/components/schemas/PitchPayload_PitchAthlete"
|
| 18074 |
+
},
|
| 18075 |
+
"context": {
|
| 18076 |
+
"$ref": "#/components/schemas/PitchPayload_PitchContext"
|
| 18077 |
+
},
|
| 18078 |
+
"events": {
|
| 18079 |
+
"$ref": "#/components/schemas/PitchPayload_Events"
|
| 18080 |
+
},
|
| 18081 |
+
"measurements": {
|
| 18082 |
+
"items": {
|
| 18083 |
+
"$ref": "#/components/schemas/PitchPayload_Measurement"
|
| 18084 |
+
},
|
| 18085 |
+
"title": "Measurements",
|
| 18086 |
+
"type": "array"
|
| 18087 |
+
},
|
| 18088 |
+
"delivery_evidence": {
|
| 18089 |
+
"anyOf": [
|
| 18090 |
+
{
|
| 18091 |
+
"$ref": "#/components/schemas/PitchPayload_DeliveryEvidence"
|
| 18092 |
+
},
|
| 18093 |
+
{
|
| 18094 |
+
"type": "null"
|
| 18095 |
+
}
|
| 18096 |
+
],
|
| 18097 |
+
"default": null
|
| 18098 |
+
},
|
| 18099 |
+
"visual_evidence": {
|
| 18100 |
+
"default": null,
|
| 18101 |
+
"title": "Visual Evidence",
|
| 18102 |
+
"type": "null"
|
| 18103 |
+
}
|
| 18104 |
+
},
|
| 18105 |
+
"required": [
|
| 18106 |
+
"analysis_id",
|
| 18107 |
+
"analysis_revision",
|
| 18108 |
+
"pitch_id",
|
| 18109 |
+
"athlete",
|
| 18110 |
+
"context",
|
| 18111 |
+
"events",
|
| 18112 |
+
"measurements"
|
| 18113 |
+
],
|
| 18114 |
+
"title": "PitchPayload",
|
| 18115 |
+
"type": "object"
|
| 18116 |
}
|
| 18117 |
}
|
| 18118 |
}
|
backend/tests/integration/test_pitching_flow.py
CHANGED
|
@@ -24,6 +24,7 @@ def url(sid):
|
|
| 24 |
|
| 25 |
async def test_retry_unavailable_ai_preserves_evidence_usage_and_is_idempotent(client, monkeypatch):
|
| 26 |
from ai_coach.pitch_report.v1_1 import service as coach_service
|
|
|
|
| 27 |
player = await make_account()
|
| 28 |
sid = await make_session(player["id"], mode="p")
|
| 29 |
p = payload(sid)
|
|
@@ -42,7 +43,7 @@ async def test_retry_unavailable_ai_preserves_evidence_usage_and_is_idempotent(c
|
|
| 42 |
"next_step": "Check the ball leaving your hand.", "check": "Compare adjacent frames.",
|
| 43 |
"evidence_ids": ["event:release"], "provisional": True}], "reason": None,
|
| 44 |
"evidence_mode": "ml_measurements_and_motion", "review_status": "automated_evidence_check"}, {
|
| 45 |
-
"text_source": "llm", "model": "test-provider", "prompt_version":
|
| 46 |
"fallback_reason": None, "text_rejections": {}}
|
| 47 |
|
| 48 |
monkeypatch.setattr(coach_service, "generate_coaching", generated)
|
|
@@ -109,8 +110,9 @@ async def test_pitch_report_store_read_retry_and_revision_clear_missing_marks(cl
|
|
| 109 |
assert response.status_code == 200, response.text
|
| 110 |
report = response.json()
|
| 111 |
assert report["discipline"] == "pitching" and len(report["measurements"]) == 10
|
|
|
|
| 112 |
assert report["overall_score"] is None
|
| 113 |
-
assert report["focus_area"]["drill"]
|
| 114 |
saved = await load_session(sid)
|
| 115 |
assert saved.measurement_payload == p and saved.report == report and saved.status == "done"
|
| 116 |
assert saved.marks["release_frame"] == p["events"]["release"]["source_frame_index"]
|
|
|
|
| 24 |
|
| 25 |
async def test_retry_unavailable_ai_preserves_evidence_usage_and_is_idempotent(client, monkeypatch):
|
| 26 |
from ai_coach.pitch_report.v1_1 import service as coach_service
|
| 27 |
+
from ai_coach.pitch_report.v1_1.coaching import VERSION
|
| 28 |
player = await make_account()
|
| 29 |
sid = await make_session(player["id"], mode="p")
|
| 30 |
p = payload(sid)
|
|
|
|
| 43 |
"next_step": "Check the ball leaving your hand.", "check": "Compare adjacent frames.",
|
| 44 |
"evidence_ids": ["event:release"], "provisional": True}], "reason": None,
|
| 45 |
"evidence_mode": "ml_measurements_and_motion", "review_status": "automated_evidence_check"}, {
|
| 46 |
+
"text_source": "llm", "model": "test-provider", "prompt_version": VERSION, "cache_hit": False,
|
| 47 |
"fallback_reason": None, "text_rejections": {}}
|
| 48 |
|
| 49 |
monkeypatch.setattr(coach_service, "generate_coaching", generated)
|
|
|
|
| 110 |
assert response.status_code == 200, response.text
|
| 111 |
report = response.json()
|
| 112 |
assert report["discipline"] == "pitching" and len(report["measurements"]) == 10
|
| 113 |
+
# A rocker drill is not compared with regular fastballs: no score, only the general practice drill.
|
| 114 |
assert report["overall_score"] is None
|
| 115 |
+
assert report["focus_area"]["kind"] == "general" and report["focus_area"]["drill"]["drill_id"] == "pit_12"
|
| 116 |
saved = await load_session(sid)
|
| 117 |
assert saved.measurement_payload == p and saved.report == report and saved.status == "done"
|
| 118 |
assert saved.marks["release_frame"] == p["events"]["release"]["source_frame_index"]
|
backend/tests/integration/test_pitching_openapi.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generated clients must accept current and legacy pitching contracts without changing hitting schemas."""
|
| 2 |
+
|
| 3 |
+
import copy
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
from ai_coach.pitch_report.schemas import PitchAnalysisPayload
|
| 9 |
+
from ai_coach.pitch_report.v1_1.schemas import PitchReport
|
| 10 |
+
from ai_coach.swing_report.schemas import SwingAnalysisPayload, SwingReport
|
| 11 |
+
from fastapi.openapi.utils import get_openapi
|
| 12 |
+
from jsonschema import Draft202012Validator
|
| 13 |
+
from pydantic.json_schema import models_json_schema
|
| 14 |
+
|
| 15 |
+
from app.integrations.pitching_reports import report_for_read
|
| 16 |
+
from app.main import create_app
|
| 17 |
+
from tests.factories import make_account
|
| 18 |
+
from tests.integration.test_pitch_reports import PITCH
|
| 19 |
+
from tests.integration.test_pitching_flow import payload as current_pitch_payload
|
| 20 |
+
from tests.integration.test_swing_reports import PAYLOAD, make_session
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def assert_valid(spec, schema, instance):
|
| 24 |
+
validator = Draft202012Validator({**schema, "components": spec["components"]})
|
| 25 |
+
errors = list(validator.iter_errors(instance))
|
| 26 |
+
assert not errors, "\n".join(f"{list(error.path)}: {error.message}" for error in errors)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def references(value):
|
| 30 |
+
if isinstance(value, dict):
|
| 31 |
+
if "$ref" in value:
|
| 32 |
+
yield value["$ref"]
|
| 33 |
+
for child in value.values():
|
| 34 |
+
yield from references(child)
|
| 35 |
+
elif isinstance(value, list):
|
| 36 |
+
for child in value:
|
| 37 |
+
yield from references(child)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
async def test_openapi_pitching_unions_and_all_references_resolve(client):
|
| 41 |
+
spec = (await client.get("/openapi.json")).json()
|
| 42 |
+
for ref in references(spec):
|
| 43 |
+
assert ref.startswith("#/"), ref
|
| 44 |
+
target = spec
|
| 45 |
+
for part in ref[2:].split("/"):
|
| 46 |
+
target = target[part.replace("~1", "/").replace("~0", "~")]
|
| 47 |
+
paths, schemas = spec["paths"], spec["components"]["schemas"]
|
| 48 |
+
pitch = paths["/v1/sessions/{session_id}/pitch-report"]["post"]
|
| 49 |
+
request = pitch["requestBody"]["content"]["application/json"]["schema"]
|
| 50 |
+
assert request == {"anyOf": [{"$ref": "#/components/schemas/PitchAnalysisPayload"},
|
| 51 |
+
{"$ref": "#/components/schemas/PitchPayload"}]}
|
| 52 |
+
assert schemas["SessionOut"]["properties"]["report"]["anyOf"] == [
|
| 53 |
+
{"$ref": "#/components/schemas/SwingReport"}, {"$ref": "#/components/schemas/PitchReport"}, {"type": "null"}]
|
| 54 |
+
assert paths["/v1/sessions"]["post"]["responses"]["201"]["content"]["application/json"]["schema"] == {
|
| 55 |
+
"$ref": "#/components/schemas/SessionEnvelope"}
|
| 56 |
+
assert paths["/v1/sessions/{session_id}"]["get"]["responses"]["200"]["content"]["application/json"]["schema"] == {
|
| 57 |
+
"$ref": "#/components/schemas/SessionEnvelope"}
|
| 58 |
+
retry = paths["/v1/sessions/{session_id}/pitch-report/retry-coaching"]["post"]
|
| 59 |
+
assert "requestBody" not in retry
|
| 60 |
+
assert retry["responses"]["200"]["content"]["application/json"]["schema"] == {
|
| 61 |
+
"$ref": "#/components/schemas/PitchReport"}
|
| 62 |
+
assert schemas["PitchPayload"]["properties"]["schema_version"]["const"] == "pitch-1.1"
|
| 63 |
+
assert schemas["PitchAnalysisPayload"]["properties"]["schema_version"]["const"] == "pitch-1.0"
|
| 64 |
+
assert schemas["PitchPayload"]["properties"]["visual_evidence"]["type"] == "null"
|
| 65 |
+
assert schemas["PitchReport"]["properties"]["visual_evidence"]["type"] == "null"
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_existing_schema_components_and_hitting_contract_remain_unchanged():
|
| 69 |
+
app = create_app()
|
| 70 |
+
before = get_openapi(title=app.title, version=app.version, routes=app.routes)
|
| 71 |
+
_, contracts = models_json_schema([
|
| 72 |
+
(SwingAnalysisPayload, "validation"), (PitchAnalysisPayload, "validation"), (SwingReport, "serialization"),
|
| 73 |
+
], ref_template="#/components/schemas/{model}")
|
| 74 |
+
before["components"]["schemas"].update(contracts["$defs"])
|
| 75 |
+
after = app.openapi()
|
| 76 |
+
for name, expected in before["components"]["schemas"].items():
|
| 77 |
+
if name not in {"HTTPValidationError", "ValidationError", "SessionOut"}:
|
| 78 |
+
assert after["components"]["schemas"][name] == expected, name
|
| 79 |
+
hitting = after["paths"]["/v1/sessions/{session_id}/swing-report"]["post"]
|
| 80 |
+
assert hitting["requestBody"]["content"]["application/json"]["schema"] == {
|
| 81 |
+
"$ref": "#/components/schemas/SwingAnalysisPayload"}
|
| 82 |
+
assert hitting["responses"]["200"]["content"]["application/json"]["schema"] == {
|
| 83 |
+
"$ref": "#/components/schemas/SwingReport"}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@pytest.mark.parametrize("kind", ["current_pitch", "legacy_pitch", "hitting"])
|
| 87 |
+
async def test_real_requests_reports_and_session_envelopes_validate_against_openapi(client, kind):
|
| 88 |
+
spec = (await client.get("/openapi.json")).json()
|
| 89 |
+
owner = await make_account()
|
| 90 |
+
sid = await make_session(owner["id"], mode="h" if kind == "hitting" else "p")
|
| 91 |
+
payload = copy.deepcopy(PAYLOAD if kind == "hitting" else PITCH if kind == "legacy_pitch"
|
| 92 |
+
else current_pitch_payload(sid))
|
| 93 |
+
path = "/v1/sessions/{session_id}/" + ("swing-report" if kind == "hitting" else "pitch-report")
|
| 94 |
+
operation = spec["paths"][path]["post"]
|
| 95 |
+
assert_valid(spec, operation["requestBody"]["content"]["application/json"]["schema"], payload)
|
| 96 |
+
response = await client.post(path.format(session_id=sid), json=payload, headers=owner["headers"])
|
| 97 |
+
assert response.status_code == 200, response.text
|
| 98 |
+
report = response.json()
|
| 99 |
+
assert_valid(spec, operation["responses"]["200"]["content"]["application/json"]["schema"], report)
|
| 100 |
+
detail = await client.get(f"/v1/sessions/{sid}", headers=owner["headers"])
|
| 101 |
+
assert detail.status_code == 200, detail.text
|
| 102 |
+
assert detail.json()["session"]["report"] == report
|
| 103 |
+
assert_valid(spec, {"$ref": "#/components/schemas/SessionEnvelope"}, detail.json())
|
| 104 |
+
if kind == "current_pitch":
|
| 105 |
+
stale = copy.deepcopy(report)
|
| 106 |
+
stale["meta"]["prompt_version"] = "older-pitching-prompt"
|
| 107 |
+
projected = report_for_read("p", stale, payload)
|
| 108 |
+
PitchReport.model_validate(projected)
|
| 109 |
+
assert_valid(spec, {"$ref": "#/components/schemas/PitchReport"}, projected)
|
| 110 |
+
assert_valid(spec, spec["components"]["schemas"]["SessionOut"]["properties"]["report"], projected)
|
| 111 |
+
retry = await client.post(f"/v1/sessions/{sid}/pitch-report/retry-coaching", headers=owner["headers"])
|
| 112 |
+
assert retry.status_code == 200, retry.text
|
| 113 |
+
assert_valid(spec, {"$ref": "#/components/schemas/PitchReport"}, retry.json())
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def test_checked_in_openapi_matches_generated_document():
|
| 117 |
+
snapshot = Path(__file__).resolve().parents[2] / "docs" / "openapi.json"
|
| 118 |
+
assert json.loads(snapshot.read_text()) == create_app().openapi()
|
backend/tests/integration/test_pitching_report_provenance.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Obsolete pitch-1.1 advice is hidden on reads and refreshed only on explicit report writes."""
|
| 2 |
+
|
| 3 |
+
import copy
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
from ai_coach.pitch_report.v1_1.coaching import VERSION
|
| 8 |
+
from ai_coach.pitch_report.v1_1.schemas import PitchReport
|
| 9 |
+
|
| 10 |
+
from app.core.database import get_session_factory
|
| 11 |
+
from app.modules.sessions.models import SwingSession
|
| 12 |
+
from tests.factories import make_account
|
| 13 |
+
from tests.integration.test_coach import _team_with_player
|
| 14 |
+
from tests.integration.test_pitching_flow import payload, url
|
| 15 |
+
from tests.integration.test_swing_reports import load_session, make_session
|
| 16 |
+
|
| 17 |
+
MARKER = "OBSOLETE_PITCHING_ADVICE"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
async def stale_session(client, owner, *, prompt="previous-pitching-prompt", visual=False):
|
| 21 |
+
sid = await make_session(owner["id"], mode="p")
|
| 22 |
+
p = payload(sid)
|
| 23 |
+
response = await client.post(url(sid), json=p, headers=owner["headers"])
|
| 24 |
+
assert response.status_code == 200, response.text
|
| 25 |
+
report = response.json()
|
| 26 |
+
report["meta"]["prompt_version"] = prompt
|
| 27 |
+
report["coaching"].update(status="generated", summary=MARKER, reason=None)
|
| 28 |
+
report["visual_evidence"] = {"status": "provisional", "description": MARKER} if visual else None
|
| 29 |
+
report["overall_score"] = 99
|
| 30 |
+
report["overview"]["headline"] = MARKER
|
| 31 |
+
report["focus_area"].update(coach_message=MARKER, practice_feel=MARKER, display_name=MARKER)
|
| 32 |
+
report["drill_evaluation"] = {"summary": MARKER, "score": 99}
|
| 33 |
+
report["data_quality"].extend(
|
| 34 |
+
{"code": code, "severity": "warning", "text": MARKER}
|
| 35 |
+
for code in ("partial_measurement_coverage", "event_sensitive_scores", "ai_coaching_unavailable")
|
| 36 |
+
)
|
| 37 |
+
for group in report["groups"]:
|
| 38 |
+
group.update(summary=MARKER, score=99)
|
| 39 |
+
for measurement in report["measurements"]:
|
| 40 |
+
measurement.update(coach_tip=MARKER, result_text=MARKER, score=99)
|
| 41 |
+
async with get_session_factory()() as db:
|
| 42 |
+
row = await db.get(SwingSession, sid)
|
| 43 |
+
row.report = report
|
| 44 |
+
await db.commit()
|
| 45 |
+
return sid, p, report
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def assert_projection(projected, stored):
|
| 49 |
+
PitchReport.model_validate(projected)
|
| 50 |
+
assert MARKER not in json.dumps(projected)
|
| 51 |
+
assert projected["coaching"]["status"] == "unavailable"
|
| 52 |
+
assert projected["coaching"]["reason"] == "coaching_refresh_required"
|
| 53 |
+
assert projected["coaching"]["cards"] == [] and projected["coaching"]["summary"] is None
|
| 54 |
+
assert projected["visual_evidence"] is None and projected["focus_area"] is None
|
| 55 |
+
assert projected["drill_evaluation"] is None and projected["overall_score"] is None
|
| 56 |
+
assert projected["meta"]["prompt_version"] == (stored["meta"]["prompt_version"] or "unknown")
|
| 57 |
+
assert projected["meta"]["fallback_reason"] == "coaching_refresh_required"
|
| 58 |
+
superseded = {"partial_measurement_coverage", "event_sensitive_scores", "ai_coaching_unavailable"}
|
| 59 |
+
retained_notes = [note for note in stored["data_quality"] if note["code"] not in superseded]
|
| 60 |
+
assert projected["data_quality"][:-1] == retained_notes
|
| 61 |
+
assert projected["data_quality"][-1]["code"] == "coaching_refresh_required"
|
| 62 |
+
for key in ("analysis_id", "analysis_revision", "delivery_evidence"):
|
| 63 |
+
assert projected.get(key) == stored.get(key)
|
| 64 |
+
for before, after in zip(stored["measurements"], projected["measurements"], strict=True):
|
| 65 |
+
for key in ("metric_id", "value", "value_interval", "status", "unit", "limitations"):
|
| 66 |
+
assert before.get(key) == after.get(key)
|
| 67 |
+
assert after["score"] is None and after["result_text"] is None and after["coach_tip"] is None
|
| 68 |
+
assert all(group["score"] is None for group in projected["groups"])
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@pytest.mark.parametrize(("prompt", "visual"), [
|
| 72 |
+
("old-visual-prompt", True), ("pitch-coach-ml-3-713b122a9ec9", False), (None, False), (VERSION, True),
|
| 73 |
+
])
|
| 74 |
+
async def test_obsolete_detail_and_list_reads_hide_advice_without_rebuilding(client, monkeypatch, prompt, visual):
|
| 75 |
+
from ai_coach.pitch_report.v1_1 import service as coach_service
|
| 76 |
+
|
| 77 |
+
owner = await make_account()
|
| 78 |
+
sid, p, stored = await stale_session(client, owner, prompt=prompt, visual=visual)
|
| 79 |
+
before = await load_session(sid)
|
| 80 |
+
quota = (await client.get("/v1/me/entitlement", headers=owner["headers"])).json()
|
| 81 |
+
|
| 82 |
+
def forbidden_provider(*args, **kwargs):
|
| 83 |
+
pytest.fail("A session read must not generate pitching coaching")
|
| 84 |
+
|
| 85 |
+
monkeypatch.setattr(coach_service, "generate_coaching", forbidden_provider)
|
| 86 |
+
for _ in range(2):
|
| 87 |
+
response = await client.get(f"/v1/sessions/{sid}", headers=owner["headers"])
|
| 88 |
+
assert response.status_code == 200, response.text
|
| 89 |
+
assert_projection(response.json()["session"]["report"], stored)
|
| 90 |
+
listing = await client.get("/v1/sessions?mode=p", headers=owner["headers"])
|
| 91 |
+
[item] = listing.json()["items"]
|
| 92 |
+
assert item["overall_score"] is None and item["focus"] is None
|
| 93 |
+
assert item["overall_score_is_tentative"] is False
|
| 94 |
+
saved = await load_session(sid)
|
| 95 |
+
assert saved.report == stored and saved.measurement_payload == p
|
| 96 |
+
assert saved.analyzed_at == before.analyzed_at
|
| 97 |
+
assert (await client.get("/v1/me/entitlement", headers=owner["headers"])).json() == quota
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@pytest.mark.parametrize("retry", [False, True])
|
| 101 |
+
async def test_old_ml_prompt_refreshes_on_explicit_report_write(client, monkeypatch, retry):
|
| 102 |
+
from ai_coach.pitch_report.v1_1 import service as coach_service
|
| 103 |
+
|
| 104 |
+
owner = await make_account()
|
| 105 |
+
sid, p, stored = await stale_session(client, owner, prompt="pitch-coach-ml-3-713b122a9ec9")
|
| 106 |
+
before = await load_session(sid)
|
| 107 |
+
quota = (await client.get("/v1/me/entitlement", headers=owner["headers"])).json()
|
| 108 |
+
original = coach_service.generate_coaching
|
| 109 |
+
calls = []
|
| 110 |
+
|
| 111 |
+
def capture(parsed, rubric, **kwargs):
|
| 112 |
+
calls.append(parsed)
|
| 113 |
+
return original(parsed, rubric, **kwargs)
|
| 114 |
+
|
| 115 |
+
monkeypatch.setattr(coach_service, "generate_coaching", capture)
|
| 116 |
+
response = await client.post(url(sid) + ("/retry-coaching" if retry else ""),
|
| 117 |
+
json=None if retry else p, headers=owner["headers"])
|
| 118 |
+
assert response.status_code == 200, response.text
|
| 119 |
+
report = response.json()
|
| 120 |
+
assert len(calls) == 1 and report["meta"]["prompt_version"] == VERSION
|
| 121 |
+
assert report["coaching"]["reason"] != "coaching_refresh_required"
|
| 122 |
+
assert MARKER not in json.dumps(report)
|
| 123 |
+
saved = await load_session(sid)
|
| 124 |
+
assert saved.report == report and saved.measurement_payload == p
|
| 125 |
+
assert saved.analyzed_at == before.analyzed_at
|
| 126 |
+
assert (saved.analysis_id, saved.analysis_revision) == (before.analysis_id, before.analysis_revision)
|
| 127 |
+
assert (await client.get("/v1/me/entitlement", headers=owner["headers"])).json() == quota
|
| 128 |
+
detail = await client.get(f"/v1/sessions/{sid}", headers=owner["headers"])
|
| 129 |
+
assert detail.json()["session"]["report"] == report and len(calls) == 1
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
async def test_coach_views_and_previous_score_hide_obsolete_pitching(client, monkeypatch):
|
| 133 |
+
from ai_coach.pitch_report.v1_1 import service as coach_service
|
| 134 |
+
|
| 135 |
+
coach, _, owner = await _team_with_player(client)
|
| 136 |
+
sid, _, stored = await stale_session(client, owner)
|
| 137 |
+
later = await make_session(owner["id"], mode="p")
|
| 138 |
+
|
| 139 |
+
def forbidden_provider(*args, **kwargs):
|
| 140 |
+
pytest.fail("Coach read views must not call the pitching model")
|
| 141 |
+
|
| 142 |
+
monkeypatch.setattr(coach_service, "generate_coaching", forbidden_provider)
|
| 143 |
+
detail = await client.get(f"/v1/sessions/{sid}", headers=coach["headers"])
|
| 144 |
+
assert detail.status_code == 200, detail.text
|
| 145 |
+
assert_projection(detail.json()["session"]["report"], stored)
|
| 146 |
+
current = await client.get(f"/v1/sessions/{later}", headers=owner["headers"])
|
| 147 |
+
assert current.json()["session"]["previous"]["overall_score"] is None
|
| 148 |
+
page = await client.get(f"/v1/coach/players/{owner['id']}/sessions?mode=p", headers=coach["headers"])
|
| 149 |
+
[item] = page.json()["items"]
|
| 150 |
+
assert item["overall_score"] is None and item["focus"] is None
|
| 151 |
+
queue = (await client.get("/v1/coach/queue", headers=coach["headers"])).json()
|
| 152 |
+
[item] = queue["open"]
|
| 153 |
+
assert item["overall_score"] is None and item["focus"] is None
|
| 154 |
+
[roster] = (await client.get("/v1/coach/roster", headers=coach["headers"])).json()["items"]
|
| 155 |
+
assert roster["last"]["p"]["overall_score"] is None and roster["last"]["p"]["focus_name"] is None
|
| 156 |
+
assert roster["recent"]["p"] == []
|
| 157 |
+
assert (await load_session(sid)).report == stored
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
@pytest.mark.parametrize("kind", ["current_pitch", "hitting", "legacy_pitch"])
|
| 161 |
+
async def test_current_hitting_and_legacy_reports_remain_identical_on_get(client, monkeypatch, kind):
|
| 162 |
+
from ai_coach.pitch_report.v1_1 import service as coach_service
|
| 163 |
+
|
| 164 |
+
from tests.integration.test_pitch_reports import PITCH
|
| 165 |
+
from tests.integration.test_swing_reports import PAYLOAD
|
| 166 |
+
|
| 167 |
+
owner = await make_account()
|
| 168 |
+
sid = await make_session(owner["id"], mode="h" if kind == "hitting" else "p")
|
| 169 |
+
p = copy.deepcopy(PAYLOAD if kind == "hitting" else PITCH if kind == "legacy_pitch" else payload(sid))
|
| 170 |
+
target = f"/v1/sessions/{sid}/swing-report" if kind == "hitting" else url(sid)
|
| 171 |
+
response = await client.post(target, json=p, headers=owner["headers"])
|
| 172 |
+
assert response.status_code == 200, response.text
|
| 173 |
+
report = response.json()
|
| 174 |
+
|
| 175 |
+
def forbidden_provider(*args, **kwargs):
|
| 176 |
+
pytest.fail("Reading a saved report must not call the pitching model")
|
| 177 |
+
|
| 178 |
+
monkeypatch.setattr(coach_service, "generate_coaching", forbidden_provider)
|
| 179 |
+
for _ in range(2):
|
| 180 |
+
response = await client.get(f"/v1/sessions/{sid}", headers=owner["headers"])
|
| 181 |
+
assert response.status_code == 200 and response.json()["session"]["report"] == report
|
| 182 |
+
[item] = (await client.get("/v1/sessions", headers=owner["headers"])).json()["items"]
|
| 183 |
+
assert item["overall_score"] == report["overall_score"]
|
| 184 |
+
assert item["focus"]["display_name"] == report["focus_area"]["display_name"]
|
| 185 |
+
assert (await load_session(sid)).report == report
|
docs/PITCHING_APP_INTEGRATION.md
CHANGED
|
@@ -2,10 +2,47 @@
|
|
| 2 |
|
| 3 |
The mobile app keeps its upload, polling and group-driven report screens. Hitting requests and saved reports remain supported. Pitching is selected explicitly; batting marks and batting-side defaults must never be used as pitching evidence.
|
| 4 |
|
| 5 |
-
The pipeline is **video → ML pose/measurements → structured JSON → AI coach**. No pitching video, sampled image, media URL, or visual-model observation is supplied to the coach. This
|
| 6 |
|
| 7 |
The engine emits `pitch-1.1`. The backend also accepts your team's earlier `pitch-1.0` payloads for compatibility. Their measurement definitions and groups differ; forward each payload unchanged and render its returned groups. New integration should use `pitch-1.1` output described here.
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
## Player flow
|
| 10 |
|
| 11 |
1. Use the existing Pitching tab and `mode: "p"` when creating a session. The Home label can be “Delivery score”. A missing score is **Not rated**, not zero.
|
|
@@ -49,6 +86,8 @@ Continue using `POST /v1/uploads` and its presigned video upload, then `POST /v1
|
|
| 49 |
|
| 50 |
These marks illustrate request shape, not reviewed event labels for an uploaded video. Supply actual marked frames. `frame_count` is the exact decoded count, not duration multiplied by rounded FPS. It is an additive field; legacy hitting clients remain supported. The engine independently decodes and validates the video. For someone else's pitching clip, age, height, weight, playing level and batting hand can be omitted rather than invented. For your own delivery, use `is_self: true, athlete: null` and the backend snapshots the account profile. The ML athlete must describe the filmed pitcher, not unrelated account demographics.
|
| 51 |
|
|
|
|
|
|
|
| 52 |
## ML: submit the delivery
|
| 53 |
|
| 54 |
`POST https://modventures-baseball-engine.hf.space/v1/motion-analyses`
|
|
@@ -90,24 +129,47 @@ Headers: `Accept: application/json`, `Authorization: Bearer <engine key>`. Let t
|
|
| 90 |
}
|
| 91 |
```
|
| 92 |
|
| 93 |
-
Use `timing.kind: "unretimed"` only for a known original-speed recording; include a `source` explanation. Existing documented slowdown/explicit-capture-time options also work. No speed assumption is made for an unknown export. Camera evidence can contradict a `fixed_verified` declaration and withhold affected measurements.
|
| 94 |
|
| 95 |
`handedness` and `athlete.throwing_hand` must agree. Lead foot is opposite the throwing hand. Pitching does not accept `contact_frame`, `swing_id` or `single_swing: true`. Marked indices must satisfy `0 <= frame < decoded frame_count`; `end_frame` is inclusive. Known marks must be ordered leg lift < foot strike < release. Missing marks are independent: foot strike/release can be measured without a leg lift.
|
| 96 |
|
|
|
|
|
|
|
| 97 |
For `dry_delivery` or `ball_type: "none"`, release must be null. Mark the exact file that will be uploaded; if exporting or compressing changes its frame list, review the marks again against that file.
|
| 98 |
|
| 99 |
## Poll, fetch, save
|
| 100 |
|
| 101 |
1. The upload returns HTTP 202 with `job_id`, `status_url`, `result_url`, `coach_payload_url`.
|
| 102 |
-
2. Poll `GET /v1/motion-analyses/{job_id}`
|
| 103 |
3. Fetch `GET /v1/motion-analyses/{job_id}/coach-payload`. Pitching payloads have `schema_version: "pitch-1.1"`, `discipline: "pitching"`, `pitch_id`, and pitching events. Preserve the payload unchanged.
|
| 104 |
4. Send it to **`POST https://baseball-engine.scalethemod.online/v1/sessions/{session_id}/pitch-report`**, using the account bearer token and JSON Content-Type. `pitch_id` must equal the session id; the session must have `mode: "p"`.
|
| 105 |
-
5. The
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
|
| 109 |
For changed marks, use `POST /v1/motion-analyses/{job_id}/revisions` with an `options` patch, then poll/fetch/save the new revision. Discipline, athlete identity and `pitch_id` stay fixed. The existing engine retention/restart limitations still apply; store completed reports promptly.
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
## Four report groups, ten measurements
|
| 112 |
|
| 113 |
| Group id | Label | Measurements |
|
|
@@ -119,7 +181,17 @@ For changed marks, use `POST /v1/motion-analyses/{job_id}/revisions` with an `op
|
|
| 119 |
|
| 120 |
Ankle spacing is an absolute joint-centre distance, not distance travelled or a height-normalized stride grade. Knee straightening is an angle change, not blocking force. Elbow bend is not arm slot, stress or injury risk. The finish metric covers an early interval, not the quality of the entire finish. Ball speed, spin, pitch location, torque, force and injury predictions are not supplied.
|
| 121 |
|
| 122 |
-
Render `groups` and `measurements` dynamically. Show `score_is_tentative`/`rating_is_tentative`, limitation text, `not_rated_reason`, context and coverage warnings. A measurable value can have a null score because no suitable reference exists. `focus_area.drill` may be null: do not display or invent a corrective drill in that case.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
### Motion evidence and personalized coaching
|
| 125 |
|
|
@@ -129,11 +201,17 @@ The additive `delivery_evidence` contains frame-indexed knee, elbow, torso, pelv
|
|
| 129 |
|
| 130 |
`coaching.status: generated` and `meta.text_source: llm` mean a real model produced personalized coaching and an automated evidence critique accepted it. Render `coaching.cards` with `observation`, `why_it_matters`, `next_step`, `check`, and `evidence_ids`. Cards distinguish `positive`, `review`, and `limitation`; all remain provisional. The existing overview/focus fields also contain the generated summary and selected next step. Automated critique reduces unsupported claims but is not expert validation or a guarantee against model mistakes.
|
| 131 |
|
|
|
|
|
|
|
| 132 |
When `coaching.reason` is `some_coaching_cards_withheld`, show that some feedback could not be verified. The returned summary and each returned card passed separate checks; rejected cards are omitted. Never infer a technique fault from withheld feedback. The same reason is preserved when an accepted partial report is served from cache.
|
| 133 |
|
| 134 |
If generation is unavailable or rejected, `coaching.status: unavailable` includes a reason. Keep the measurements available and label the descriptions as non-AI fallback. Do not market them as personalized AI coaching.
|
| 135 |
|
| 136 |
-
Offer **Retry AI coaching** using `POST /v1/sessions/{session_id}/pitch-report/retry-coaching` with the account bearer token and no body. By default it retries unavailable coaching and rebuilds obsolete visual
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
`drill_evaluation` provides source-backed objectives and observed/indeterminate findings for step-back, rocker and standard deliveries. Its `validation_status` is `provisional_qualitative`; its score is null. These are not validated drill scores. Other or unknown drills do not acquire made-up criteria. Do not convert missing scores to zero or assign a percentage based on checklist coverage.
|
| 139 |
|
|
@@ -157,6 +235,21 @@ Angles with unusable neighboring frames, interpolated event landmarks, or more t
|
|
| 157 |
- Invalid fields/order: HTTP 422. Window end past decoded video: `reviewed_frame_out_of_range`; release beyond it: `release_frame_out_of_range`. Do not clamp marks to make the request pass; review the uploaded file's frames.
|
| 158 |
- Backend errors include `MODE_NOT_SUPPORTED`, `INVALID_PAYLOAD`, `ANALYSIS_MISMATCH`, `STALE_REVISION`, `REVISION_PAYLOAD_MISMATCH`, ownership/consent failures and existing plan limits.
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
## Reference provenance
|
| 161 |
|
| 162 |
Nine geometry/timing references are derived from [OpenBiomechanics dataset-v1](https://github.com/drivelineresearch/openbiomechanics/releases/tag/dataset-v1), using the same 3D joint-centre formulas and per-athlete medians. Ankle distance is deliberately ungraded. Generation is reproducible with `data_ref/scripts/compute_pitching_contract_benchmarks.py`; hashes and cohort counts are in `AI-coach-agent/src/ai_coach/knowledge/pitching_benchmarks.yaml`. Derived data retains CC BY-NC-SA 4.0 attribution and terms. Reference distributions describe the sampled pitchers, not ideal technique. Visual foot strike only approximates the laboratory force threshold.
|
|
|
|
| 2 |
|
| 3 |
The mobile app keeps its upload, polling and group-driven report screens. Hitting requests and saved reports remain supported. Pitching is selected explicitly; batting marks and batting-side defaults must never be used as pitching evidence.
|
| 4 |
|
| 5 |
+
The pipeline is **video → ML pose/measurements → structured JSON → AI coach**. No pitching video, sampled image, media URL, or visual-model observation is supplied to the coach. This guide matches the deployed engine 1.21.7 and backend pitching contract verified on 2026-11-02; validation evidence is recorded in `PITCHING_VALIDATION.md`.
|
| 6 |
|
| 7 |
The engine emits `pitch-1.1`. The backend also accepts your team's earlier `pitch-1.0` payloads for compatibility. Their measurement definitions and groups differ; forward each payload unchanged and render its returned groups. New integration should use `pitch-1.1` output described here.
|
| 8 |
|
| 9 |
+
## Changes to an already integrated mobile app
|
| 10 |
+
|
| 11 |
+
Reuse account authentication, presigned uploads, video playback/frame selection, session storage, background polling and the group-driven report layout. Add a pitching branch to the request builders and report models; leave the hitting branch unchanged.
|
| 12 |
+
|
| 13 |
+
| Integration point | Pitching change |
|
| 14 |
+
|---|---|
|
| 15 |
+
| Session | `mode: "p"`; pitching athlete and marks below |
|
| 16 |
+
| Event picker | `leg_lift_frame`, `foot_strike_frame`, `release_frame`; each nullable |
|
| 17 |
+
| Hand | Backend `throws: "L"/"R"` maps to engine `throwing_hand: "left"/"right"` |
|
| 18 |
+
| ML request | `/v1/motion-analyses`, `discipline: "pitching"`, `single_pitch: true`, original video plus JSON options |
|
| 19 |
+
| ML-to-coach handoff | Fetch `coach_payload_url`, forward its JSON unchanged to `/v1/sessions/{id}/pitch-report` |
|
| 20 |
+
| Report | Four pitching group IDs; nullable scores, values, focus and drill; generated/unavailable coaching states |
|
| 21 |
+
| Retry | `/v1/sessions/{id}/pitch-report/retry-coaching`; reruns interpretation from saved ML evidence |
|
| 22 |
+
|
| 23 |
+
There is no mobile Gemini call and no new AI-provider key for the app. The backend generates and stores coaching when `/pitch-report` is called.
|
| 24 |
+
|
| 25 |
+
## Services and authentication
|
| 26 |
+
|
| 27 |
+
| Service | Base URL | Authentication |
|
| 28 |
+
|---|---|---|
|
| 29 |
+
| App backend | `https://baseball-engine.scalethemod.online` | Existing account bearer token |
|
| 30 |
+
| ML engine | `https://modventures-baseball-engine.hf.space` | Engine bearer credential through your existing engine transport |
|
| 31 |
+
|
| 32 |
+
The account token and engine credential are different. Keep engine secrets in the existing server/proxy credential handling, rather than embedding a shared engine key in the mobile binary. All engine status, result, schema and coach-payload requests require engine authentication. Resolve the engine's relative URLs against the **engine** base URL, not the app backend.
|
| 33 |
+
|
| 34 |
+
**SDK generation:** regenerate mobile API models from `https://baseball-engine.scalethemod.online/openapi.json` or the checked-in [backend OpenAPI snapshot](../backend/docs/openapi.json). The pitch-report request supports both `pitch-1.0` and `pitch-1.1`; saved session reports support the existing hitting/legacy report, the current pitching report, or null. The pitching report and retry responses include the current pitching groups and nullable fields. Do not send the ML payload through an older hitting-only serializer that drops pitching fields.
|
| 35 |
+
|
| 36 |
+
The report envelope still has `schema_version: "1.0"`, with `discipline: "pitching"` and `meta.input_schema_version: "pitch-1.1"` for current pitching. Only the incoming ML payload has `schema_version: "pitch-1.1"`. Do not dispatch report parsing on `report.schema_version` alone: use the current report's `discipline` when present and the session's `mode` for legacy reports. Standalone contracts remain available in [pitching-coach-payload.schema.json](pitching-coach-payload.schema.json) and [pitch-report.schema.json](pitch-report.schema.json).
|
| 37 |
+
|
| 38 |
+
For `openapi-typescript`, generation was checked with version 7.13.0 and strict TypeScript compilation against current pitching, legacy pitching and hitting fixtures:
|
| 39 |
+
|
| 40 |
+
```sh
|
| 41 |
+
npx openapi-typescript@7.13.0 https://baseball-engine.scalethemod.online/openapi.json --default-non-nullable false -o src/api/generated.ts
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Choose the output path used by your app. The `--default-non-nullable false` option preserves optional fields with schema defaults; the generator's default setting otherwise makes some optional existing hitting/legacy fields required in generated types. No manual pitching type definitions are needed for these documented contracts.
|
| 45 |
+
|
| 46 |
## Player flow
|
| 47 |
|
| 48 |
1. Use the existing Pitching tab and `mode: "p"` when creating a session. The Home label can be “Delivery score”. A missing score is **Not rated**, not zero.
|
|
|
|
| 86 |
|
| 87 |
These marks illustrate request shape, not reviewed event labels for an uploaded video. Supply actual marked frames. `frame_count` is the exact decoded count, not duration multiplied by rounded FPS. It is an additive field; legacy hitting clients remain supported. The engine independently decodes and validates the video. For someone else's pitching clip, age, height, weight, playing level and batting hand can be omitted rather than invented. For your own delivery, use `is_self: true, athlete: null` and the backend snapshots the account profile. The ML athlete must describe the filmed pitcher, not unrelated account demographics.
|
| 88 |
|
| 89 |
+
Session creation returns HTTP **201** with `{"session": {...}}`; take the ID from `response.session.id`. Reuse the existing `Idempotency-Key` mechanism so a network retry does not create another session. `marks` is required, but individual pitching mark fields may be null or omitted. Frame indices are zero-based. Use the same reviewed marks for the backend session and engine options.
|
| 90 |
+
|
| 91 |
## ML: submit the delivery
|
| 92 |
|
| 93 |
`POST https://modventures-baseball-engine.hf.space/v1/motion-analyses`
|
|
|
|
| 129 |
}
|
| 130 |
```
|
| 131 |
|
| 132 |
+
Use `timing.kind: "unretimed"` only for a known original-speed recording; include a `source` explanation. Existing documented slowdown/explicit-capture-time options also work. No speed assumption is made for an unknown export. Set `camera_stability` to `fixed_verified` only after confirmation; otherwise use `unknown`, or `moving` for a moving camera. Camera evidence can contradict a `fixed_verified` declaration and withhold affected measurements.
|
| 133 |
|
| 134 |
`handedness` and `athlete.throwing_hand` must agree. Lead foot is opposite the throwing hand. Pitching does not accept `contact_frame`, `swing_id` or `single_swing: true`. Marked indices must satisfy `0 <= frame < decoded frame_count`; `end_frame` is inclusive. Known marks must be ordered leg lift < foot strike < release. Missing marks are independent: foot strike/release can be measured without a leg lift.
|
| 135 |
|
| 136 |
+
Include the engine `athlete` object with a nonempty `athlete_id`; without it, no coach payload is requested. Omit inherited `coaching`, or set it to `false`: `coaching: true` is invalid on this endpoint. Omit batting-specific options such as `contact_frame`, `swing_id`, and `single_swing` when constructing a pitching request. Keep `annotated_videos: false`.
|
| 137 |
+
|
| 138 |
For `dry_delivery` or `ball_type: "none"`, release must be null. Mark the exact file that will be uploaded; if exporting or compressing changes its frame list, review the marks again against that file.
|
| 139 |
|
| 140 |
## Poll, fetch, save
|
| 141 |
|
| 142 |
1. The upload returns HTTP 202 with `job_id`, `status_url`, `result_url`, `coach_payload_url`.
|
| 143 |
+
2. Poll `GET /v1/motion-analyses/{job_id}`. `queued`, `processing` and `cancel_requested` are nonterminal; `completed`, `failed` and `cancelled` are terminal. For failure, use `failure?.reason_code`, then `failure?.code`, `error`, or a generic message. Failure details can be null. Stop polling terminal jobs.
|
| 144 |
3. Fetch `GET /v1/motion-analyses/{job_id}/coach-payload`. Pitching payloads have `schema_version: "pitch-1.1"`, `discipline: "pitching"`, `pitch_id`, and pitching events. Preserve the payload unchanged.
|
| 145 |
4. Send it to **`POST https://baseball-engine.scalethemod.online/v1/sessions/{session_id}/pitch-report`**, using the account bearer token and JSON Content-Type. `pitch_id` must equal the session id; the session must have `mode: "p"`.
|
| 146 |
+
5. The report POST returns HTTP **200** with the **bare report object**. `GET /v1/sessions/{session_id}` returns `{"session": {...}}`; read its report from `response.session.report`, with session `status: "done"` and synchronized pitching marks. Engine job completion and backend session completion are separate: the session is not done until the report is saved. Obsolete pitch-1.1 feedback is hidden until refreshed, as described below. Session lists and Home summaries expose its score, including null; use `GET /v1/sessions?mode=p` for pitching history.
|
| 147 |
|
| 148 |
+
Poll at a bounded interval (for example, every 2–3 seconds), resume from the saved `job_id` after app interruption, and preserve the fetched coach payload for an identical report-save retry. Status responses have null result/payload URLs until ready. `result_url` returns an ML manifest, **not** the coach payload; use `coach_payload_url`. Do not send the manifest or rebuild measurements client-side.
|
| 149 |
+
|
| 150 |
+
Retries of identical analysis/revision return a current stored report without charging again; obsolete pitch-1.1 coaching is rebuilt from the saved ML data. A different payload for the same revision is rejected. Higher revisions replace that analysis's report; older revisions and a different analysis id are rejected. Ownership, consent and existing plan limits apply.
|
| 151 |
|
| 152 |
For changed marks, use `POST /v1/motion-analyses/{job_id}/revisions` with an `options` patch, then poll/fetch/save the new revision. Discipline, athlete identity and `pitch_id` stay fixed. The existing engine retention/restart limitations still apply; store completed reports promptly.
|
| 153 |
|
| 154 |
+
Revision requests are JSON, not multipart. Objects merge, but arrays replace: resend the complete one-element `windows` array, including bounds and all retained marks. For example:
|
| 155 |
+
|
| 156 |
+
```json
|
| 157 |
+
{
|
| 158 |
+
"options": {
|
| 159 |
+
"release_frame": 65,
|
| 160 |
+
"windows": [{
|
| 161 |
+
"start_frame": 0,
|
| 162 |
+
"end_frame": 87,
|
| 163 |
+
"leg_lift_frame": null,
|
| 164 |
+
"foot_strike_frame": 58,
|
| 165 |
+
"source": "Reviewed correction on the original uploaded file"
|
| 166 |
+
}]
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
Explicit null clears a mark. The response supplies a new `job_id`, the same `analysis_id`, and a higher `analysis_revision`; poll the new job and forward its new coach payload to the same backend session. Do not submit a brand-new analysis to replace an existing session's analysis.
|
| 172 |
+
|
| 173 |
## Four report groups, ten measurements
|
| 174 |
|
| 175 |
| Group id | Label | Measurements |
|
|
|
|
| 181 |
|
| 182 |
Ankle spacing is an absolute joint-centre distance, not distance travelled or a height-normalized stride grade. Knee straightening is an angle change, not blocking force. Elbow bend is not arm slot, stress or injury risk. The finish metric covers an early interval, not the quality of the entire finish. Ball speed, spin, pitch location, torque, force and injury predictions are not supplied.
|
| 183 |
|
| 184 |
+
Render `groups` and `measurements` dynamically. Each group has `group`, `display_name`, `summary`, `metric_ids` and a nullable `score`. Match measurements using `metric_id` or `group`; render their server-provided `display_name`, `display_value`, `unit` and `limitations`. Show `score_is_tentative`/`rating_is_tentative`, limitation text, `not_rated_reason`, context and coverage warnings. A measurable value can have a null score because no suitable reference exists. `focus_area` and `focus_area.drill` may each be null: do not display or invent a corrective drill in that case.
|
| 185 |
+
|
| 186 |
+
| Returned condition | Mobile display |
|
| 187 |
+
|---|---|
|
| 188 |
+
| `value: null` / unavailable measurement | “Unavailable” plus supplied limitation; never `0` |
|
| 189 |
+
| Value present, `score: null` | Estimated measurement with “Not rated” |
|
| 190 |
+
| `coaching.status: "generated"` | Returned summary and coaching cards |
|
| 191 |
+
| `coaching.reason: "some_coaching_cards_withheld"` | Retained cards plus a partial-feedback notice |
|
| 192 |
+
| `coaching.status: "unavailable"` | Measurements stay visible; show unavailable-AI state and retry action |
|
| 193 |
+
| `coaching.reason: "coaching_refresh_required"` | “Refresh coaching” action; no stale advice |
|
| 194 |
+
| Null `focus_area`, `drill_evaluation`, `delivery_evidence` or `coaching` | Omit that panel; no forced placeholder object |
|
| 195 |
|
| 196 |
### Motion evidence and personalized coaching
|
| 197 |
|
|
|
|
| 201 |
|
| 202 |
`coaching.status: generated` and `meta.text_source: llm` mean a real model produced personalized coaching and an automated evidence critique accepted it. Render `coaching.cards` with `observation`, `why_it_matters`, `next_step`, `check`, and `evidence_ids`. Cards distinguish `positive`, `review`, and `limitation`; all remain provisional. The existing overview/focus fields also contain the generated summary and selected next step. Automated critique reduces unsupported claims but is not expert validation or a guarantee against model mistakes.
|
| 203 |
|
| 204 |
+
Evidence IDs may refer to measurements, events, phases, drill criteria, clock information or limitations. Do not assume every ID maps to a measurement row. Charts are optional for initial integration; if shown, preserve null samples as gaps rather than drawing invented motion through them.
|
| 205 |
+
|
| 206 |
When `coaching.reason` is `some_coaching_cards_withheld`, show that some feedback could not be verified. The returned summary and each returned card passed separate checks; rejected cards are omitted. Never infer a technique fault from withheld feedback. The same reason is preserved when an accepted partial report is served from cache.
|
| 207 |
|
| 208 |
If generation is unavailable or rejected, `coaching.status: unavailable` includes a reason. Keep the measurements available and label the descriptions as non-AI fallback. Do not market them as personalized AI coaching.
|
| 209 |
|
| 210 |
+
Offer **Retry AI coaching** using `POST /v1/sessions/{session_id}/pitch-report/retry-coaching` with the account bearer token and no body. By default it retries unavailable coaching and rebuilds reports with obsolete visual evidence or a superseded coaching prompt; it returns a current generated report unchanged. Reposting the identical analysis also rebuilds an obsolete report without another analysis charge. Use `?refresh=true` to explicitly reinterpret an existing report with the current coaching implementation. Ownership and consent still apply. Neither operation reruns pose estimation or consumes another analysis. The saved engine payload stays unchanged; current quality checks can withhold unreliable older estimates or visual claims from the displayed report. Refresh uses only the saved ML evidence and discards all legacy visual observations.
|
| 211 |
+
|
| 212 |
+
Retry returns HTTP 200 with a **bare report**, which should replace the local displayed report. `refresh=true` can reuse accepted cached coaching (`meta.cache_hit: true`); it does not guarantee a new provider call. Retry requires a saved pitch-1.1 report: a missing report returns `409 REPORT_NOT_READY`, and a legacy pitch-1.0 report returns `422 MODE_NOT_SUPPORTED`.
|
| 213 |
+
|
| 214 |
+
Reading an obsolete pitch-1.1 report returns `coaching.status: "unavailable"` and `coaching.reason: "coaching_refresh_required"`. Superseded advice, visual observations and grades are hidden in session details and summaries, including coach views. Display a refresh action while retaining access to the saved measurements as provisional estimates. Reads do not call the coach, rewrite the stored analysis or consume quota; only the explicit retry/report routes regenerate feedback. Current pitching reports, legacy pitch-1.0 and hitting reports retain their existing read behavior.
|
| 215 |
|
| 216 |
`drill_evaluation` provides source-backed objectives and observed/indeterminate findings for step-back, rocker and standard deliveries. Its `validation_status` is `provisional_qualitative`; its score is null. These are not validated drill scores. Other or unknown drills do not acquire made-up criteria. Do not convert missing scores to zero or assign a percentage based on checklist coverage.
|
| 217 |
|
|
|
|
| 235 |
- Invalid fields/order: HTTP 422. Window end past decoded video: `reviewed_frame_out_of_range`; release beyond it: `release_frame_out_of_range`. Do not clamp marks to make the request pass; review the uploaded file's frames.
|
| 236 |
- Backend errors include `MODE_NOT_SUPPORTED`, `INVALID_PAYLOAD`, `ANALYSIS_MISMATCH`, `STALE_REVISION`, `REVISION_PAYLOAD_MISMATCH`, ownership/consent failures and existing plan limits.
|
| 237 |
|
| 238 |
+
Backend errors use `{"error":{"code":"...","message":"...","fields":{...}}}`; engine HTTP errors use `{"detail":...}`, where detail may be a string, object or validation list. Handle engine `429` using `Retry-After`, `503` as temporarily unavailable, and `404` as missing/expired job instead of polling forever. A failed report save does not require another ML run when the original payload is already available.
|
| 239 |
+
|
| 240 |
+
## Mobile acceptance checklist
|
| 241 |
+
|
| 242 |
+
- A pitching session uses `mode: "p"`, the filmed athlete's throwing hand, and pitching marks only.
|
| 243 |
+
- Left/right hand mappings and zero-based frame bounds are correct; null marks survive JSON encoding.
|
| 244 |
+
- A rocker without leg lift works; a dry delivery does not acquire a fake ball-release mark.
|
| 245 |
+
- Unknown capture timing stays unknown; the app does not infer timing from exported FPS.
|
| 246 |
+
- Engine completion is followed by fetching the coach payload and saving it through `/pitch-report`.
|
| 247 |
+
- JSON forwarding preserves `pitch-1.1`, analysis identity/revision, measurements and motion evidence.
|
| 248 |
+
- All four pitching groups render without hitting-only enum failures; null values/scores/focus/drills are supported.
|
| 249 |
+
- Partial, unavailable and refresh-required coaching states remain distinguishable from a failed ML job.
|
| 250 |
+
- Report-save retry, coaching retry, mark revision, history reload and app-resume polling work.
|
| 251 |
+
- Hitting screens, request builders and existing reports retain their current behavior.
|
| 252 |
+
|
| 253 |
## Reference provenance
|
| 254 |
|
| 255 |
Nine geometry/timing references are derived from [OpenBiomechanics dataset-v1](https://github.com/drivelineresearch/openbiomechanics/releases/tag/dataset-v1), using the same 3D joint-centre formulas and per-athlete medians. Ankle distance is deliberately ungraded. Generation is reproducible with `data_ref/scripts/compute_pitching_contract_benchmarks.py`; hashes and cohort counts are in `AI-coach-agent/src/ai_coach/knowledge/pitching_benchmarks.yaml`. Derived data retains CC BY-NC-SA 4.0 attribution and terms. Reference distributions describe the sampled pitchers, not ideal technique. Visual foot strike only approximates the laboratory force threshold.
|
docs/PITCHING_VALIDATION.md
CHANGED
|
@@ -4,7 +4,7 @@ This work distinguishes implementation tests, inter-method comparisons, visual r
|
|
| 4 |
|
| 5 |
“Manual review” below means assistant inspection of the original frames alongside the returned evidence. It is separate from the engine's automated critique, but it is not an independent review by a pitching coach or biomechanics laboratory.
|
| 6 |
|
| 7 |
-
## Current
|
| 8 |
|
| 9 |
The requested architecture is video → pose ML → measurements/evidence JSON → AI coach, matching the hitting separation. The pitching visual-model stage is retired: export never calls it, its compatibility function never reads media or calls a provider, and older visual observations are discarded before report generation. Hitting behavior is unchanged. Earlier sections below document historical experiments and failures, including the now-removed image-review approach; they do not describe the corrected architecture.
|
| 10 |
|
|
@@ -14,7 +14,7 @@ Current measurements have unvalidated model accuracy. Population reference quant
|
|
| 14 |
|
| 15 |
The original files match the retained SAM3D results (80 step-back frames; 88 rocker frames). Integrity-checked replay is possible from `motion.jsonl`; it is not a fresh GPU inference run and does not establish physical accuracy. New audit evidence is retained separately under `artifacts/pitching-validation-2026-11-02/ml-only-audit`.
|
| 16 |
|
| 17 |
-
Local checks cover 706 engine tests (two skipped),
|
| 18 |
|
| 19 |
Release 1.21.5 source `c6740dc30c6da8c1add9680c0c571ec78bec8366` passed [source tests](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984965), [ML deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984920) and [backend deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984898). The running Hugging Face commit was `66d2e51ce53c0fb1906a3e2c5d9ad5fd770234db`, linked to the source commit in deployment logs. Live readiness and the ML-only capabilities were verified.
|
| 20 |
|
|
@@ -22,7 +22,13 @@ Both original videos then completed fresh SAM3D analysis and real Gemini coachin
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
## Historical validation record
|
| 28 |
|
|
@@ -130,7 +136,7 @@ Refreshing both stored reports under that change produced a supported step-back
|
|
| 130 |
|
| 131 |
The follow-up coaching change reviews the summary and each card independently. A rejected card cannot erase a separately accepted card, and an accepted card cannot rescue an unsupported summary. Deterministic checks cannot be overridden by the model; every card must receive exactly one critique. After bounded repair, a supported subset can be returned as `some_coaching_cards_withheld`. No replacement prose is invented. The accepted subset and its limitation survive caching. Tests exercise false model acceptance, rejected summaries, incomplete/duplicate critiques, omitted cards and cache behavior. The critic also distinguishes future recording instructions from claims about the current file. The updated coach suite has **698 passed, 1 skipped, 12 deselected**; the backend regression remains **54 passed**.
|
| 132 |
|
| 133 |
-
##
|
| 134 |
|
| 135 |
Source commit: `42c1af3e1d2677ea1e2bd56a3d4d63838996e2c3`; engine version: **1.21.4**; coaching prompt: `pitch-coach-2-dd16135a6d1d`.
|
| 136 |
|
|
|
|
| 4 |
|
| 5 |
“Manual review” below means assistant inspection of the original frames alongside the returned evidence. It is separate from the engine's automated critique, but it is not an independent review by a pitching coach or biomechanics laboratory.
|
| 6 |
|
| 7 |
+
## Current deployed correction: ML-only coaching (2026-11-02)
|
| 8 |
|
| 9 |
The requested architecture is video → pose ML → measurements/evidence JSON → AI coach, matching the hitting separation. The pitching visual-model stage is retired: export never calls it, its compatibility function never reads media or calls a provider, and older visual observations are discarded before report generation. Hitting behavior is unchanged. Earlier sections below document historical experiments and failures, including the now-removed image-review approach; they do not describe the corrected architecture.
|
| 10 |
|
|
|
|
| 14 |
|
| 15 |
The original files match the retained SAM3D results (80 step-back frames; 88 rocker frames). Integrity-checked replay is possible from `motion.jsonl`; it is not a fresh GPU inference run and does not establish physical accuracy. New audit evidence is retained separately under `artifacts/pitching-validation-2026-11-02/ml-only-audit`.
|
| 16 |
|
| 17 |
+
Local checks cover 706 engine tests (two skipped), 768 coach tests (one skipped; twelve live tests excluded), and 84 backend regression tests including hitting/session behavior, stored-report provenance and coach views. The final coach changes also passed all 32 targeted engine pitching tests and source CI. Two additional temporary backend checks used each original clip's replayed ML payload with a fake text provider and verified exact persistence. Reusable replay: `tools/validate_pitching_ml_coach.py`; it verifies source/video hashes, recomputes measurements, enforces ML-only evidence and clearly distinguishes offline fallback from optional live text generation.
|
| 18 |
|
| 19 |
Release 1.21.5 source `c6740dc30c6da8c1add9680c0c571ec78bec8366` passed [source tests](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984965), [ML deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984920) and [backend deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41401984898). The running Hugging Face commit was `66d2e51ce53c0fb1906a3e2c5d9ad5fd770234db`, linked to the source commit in deployment logs. Live readiness and the ML-only capabilities were verified.
|
| 20 |
|
|
|
|
| 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 supplies explicit metric-reference and event definitions and rejects these mismatches across all returned prose. Source `0a12cc2b74651190f56408d4885da0f57257bac3` passed [source CI](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41405879352), [ML deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41405879450) and [backend deployment](https://github.com/MOD-Ventures-Org/baseball-engine/actions/runs/41405879328). Hugging Face revision `659d1d9657142033d2eac4ecb550153ea04b482e` is linked to that source in deployment logs. Its running revision, API version **1.21.7**, readiness and ML-only capabilities were checked. The ML implementation is byte-identical to the fresh 1.21.5 runs; only coaching and the advertised API version changed afterward.
|
| 26 |
+
|
| 27 |
+
Both stored reports were refreshed through the deployed backend using real Gemini generation under prompt `pitch-coach-ml-3-b39515cefb5e`. Original payloads, ML measurements, motion evidence, analysis IDs/revisions, analysis timestamps and quota remained unchanged. The saved reports matched the refresh responses and request-specific API audits. A separate assistant review checked the exact retained summary, every card field and cited evidence against each ML payload: no concrete unsupported claim was found in either final report. Step-back remains an explicitly partial result (`some_coaching_cards_withheld`); rocker returned four cards. The earlier failures are retained in `initial/` and `refresh-1.21.6/`, with final report hashes and scoped acceptance in each `manual-review.json` under `artifacts/pitching-validation-2026-11-02/release-1.21.5-ml-only/`.
|
| 28 |
+
|
| 29 |
+
The final backend review found a separate stored-report gap: ordinary session reads could still expose older visual coaching, and retry without `refresh=true` could keep a superseded ML-only prompt. The backend now projects obsolete pitch-1.1 reports as `coaching_refresh_required`, hiding derived advice, visual observations and scores in detail, list, previous-score and coach views. Raw measurements remain available as estimates. Explicit report/retry writes rebuild stale prompts from the unchanged saved payload. Integration tests verify no provider call, DB mutation or quota use on reads, and identical behavior for current pitching, hitting and legacy pitch-1.0. This requires a narrow pitching-only guard in the shared session-summary projection; no shared schema, model or migration changed. Deployment verification for this backend-only safeguard is recorded separately from the ML/coach release.
|
| 30 |
+
|
| 31 |
+
These are accepted provisional interpretations of ML estimates, not certified pitching measurements or a general coaching-accuracy guarantee. The two videos do not provide independent 3D ground truth. Unknown capture timing, unsupported movement directions, unreliable angles and numeric performance grades remain withheld. A green deployment is not a content-accuracy result.
|
| 32 |
|
| 33 |
## Historical validation record
|
| 34 |
|
|
|
|
| 136 |
|
| 137 |
The follow-up coaching change reviews the summary and each card independently. A rejected card cannot erase a separately accepted card, and an accepted card cannot rescue an unsupported summary. Deterministic checks cannot be overridden by the model; every card must receive exactly one critique. After bounded repair, a supported subset can be returned as `some_coaching_cards_withheld`. No replacement prose is invented. The accepted subset and its limitation survive caching. Tests exercise false model acceptance, rejected summaries, incomplete/duplicate critiques, omitted cards and cache behavior. The critic also distinguishes future recording instructions from claims about the current file. The updated coach suite has **698 passed, 1 skipped, 12 deselected**; the backend regression remains **54 passed**.
|
| 138 |
|
| 139 |
+
## Historical 1.21.4 deployed implementation
|
| 140 |
|
| 141 |
Source commit: `42c1af3e1d2677ea1e2bd56a3d4d63838996e2c3`; engine version: **1.21.4**; coaching prompt: `pitch-coach-2-dd16135a6d1d`.
|
| 142 |
|
tests/test_pitching_api.py
CHANGED
|
@@ -128,7 +128,7 @@ def test_rocker_without_leg_lift_does_not_invent_a_phase_or_grade():
|
|
| 128 |
assert len(report["measurements"]) == 10
|
| 129 |
assert any(m["value"] is not None for m in report["measurements"])
|
| 130 |
assert all(m["coach_tip"] is None for m in report["measurements"])
|
| 131 |
-
assert report["focus_area"]["
|
| 132 |
|
| 133 |
|
| 134 |
def test_unknown_camera_keeps_intrinsic_angles_unknown_clock_blocks_times():
|
|
|
|
| 128 |
assert len(report["measurements"]) == 10
|
| 129 |
assert any(m["value"] is not None for m in report["measurements"])
|
| 130 |
assert all(m["coach_tip"] is None for m in report["measurements"])
|
| 131 |
+
assert report["focus_area"]["kind"] == "general" and report["focus_area"]["metric_id"] is None
|
| 132 |
|
| 133 |
|
| 134 |
def test_unknown_camera_keeps_intrinsic_angles_unknown_clock_blocks_times():
|