baseball-engine / docs /MOTION_COACH_PAYLOAD.md
github-actions[bot]
Automated Deploy: 576e5fa0b5a38e119a36684f345434445973a81e
4b1e064
|
Raw History Blame Contribute Delete
10.7 kB
# Motion analysis → AI coach: contract 1.0
The existing motion API can export the three measurements from `ml_contract_v1.md`.
It still supports every previous request field, both SAM 3D and GVHMR, skeleton
playback, measurements, projections, annotated videos and immutable revisions.
The coaching export is opt-in through `options.athlete`, and supports **one swing
per video**. Existing uploads without athlete information keep their previous flow.
## Request
Send multipart form data to **`POST /v1/motion-analyses`**:
| Field | Type | Meaning |
|---|---|---|
| `video` | File | Original recording. |
| `options` | Text containing JSON | Existing motion options plus the fields below. |
| `source_asset_id` | Text, optional | Existing source reuse; supply this **instead of** `video`. |
Example `options` (frame numbers are illustrative and must match your recording):
```json
{
"model": "gvhmr",
"single_swing": true,
"annotated_videos": true,
"handedness": "right",
"lead_foot": "left",
"camera_stability": "fixed_verified",
"timing": { "kind": "unknown" },
"athlete": {
"athlete_id": "player-001",
"batting_hand": "right",
"lead_foot": "left",
"age_years": 16,
"height_cm": 175
},
"context": { "sport": "baseball", "practice_type": "tee" },
"swing_id": "swing-001",
"contact_frame": 90,
"windows": [{
"start_frame": 0,
"end_frame": 140,
"baseline_frame": 10,
"forward_start_frame": 75,
"forward_end_frame": 120,
"stride_start_frame": 45,
"landing_frame": 70,
"source": "Reviewed original recording"
}]
}
```
Use `model: "sam3d"` to run SAM. Set `fixed_verified` only when known. Use
`timing: {"kind":"unretimed","source":"Original recording; no speed changes"}`
only when confirmed. Existing camera calibration, up/pitcher references and floor
point selections, scale, rotation, athlete box, correction, refinement, tracking,
GVHMR settings and window fields remain accepted. No new tuning is required.
| New option | Required / default | Meaning |
|---|---|---|
| `athlete` | Optional; default `null` | Enables the coach payload. Requires `single_swing: true`. |
| `athlete.athlete_id` | Required when athlete is supplied | Nonempty player ID. |
| `athlete.batting_hand` | Optional, default `null` | `left` / `right`. May use existing top-level `handedness` instead. Conflicting non-null values are rejected. |
| `athlete.lead_foot` | Optional, default `null` | `left` / `right`. May use existing top-level `lead_foot` instead. Conflicting non-null values are rejected. When omitted, inferred from known batting hand. |
| `athlete.age_years` | Optional, default `null` | Nonnegative integer. |
| `athlete.height_cm` | Optional, default `null` | Positive number. Player metadata; **does not calibrate 3D scale**. |
| `context` | Default baseball / unknown | `sport: "baseball"`; `practice_type`: `tee`, `front_toss`, `side_toss`, `pitching_machine`, `live_pitching`, `game`, `dry_swing`, `unknown`. |
| `contact_frame` | Optional, default `null` | Reviewed bat-ball contact source-frame index. Requires `single_swing: true`. |
| `swing_id` | Optional | Stable ID for this recorded swing. Defaults to `<analysis_id>:swing_1`. |
All frame indices are **zero-based decoded source-frame indices**, matching
`motion.jsonl.source_frame_index`. They refer to the uploaded video, before any
cropping of the timeline or playback-speed changes. Image rotation does not
renumber frames. Do not send a timestamp or a screenshot number in these fields.
No bat/ball pixel coordinates are required for these three body measurements.
## Which frames should the app request?
- `windows[0].stride_start_frame`: the reviewed beginning of the final stride.
- `windows[0].landing_frame`: the **first visible ground touch at the end of that
stride**, excluding earlier toe taps. This supplies the coach's `front_foot_down`.
- `contact_frame`: the reviewed frame showing bat-ball contact.
Keep the existing `start_frame`, `end_frame`, baseline and forward-window fields.
Stride start and landing must be supplied together, with stride start before
landing. Contact must be inside the selected swing window and cannot precede
landing. If frame count is only known after decoding, an out-of-range frame fails
the job **before model inference** with `contact_frame_out_of_range` or
`reviewed_frame_out_of_range`. Revision requests reject known invalid ranges with
HTTP 422 before queuing. Negative, fractional and boolean frame indices are invalid.
These are reviewed video events, not validated automatic detections. The coach's
laboratory benchmark uses a ground-force threshold; visible touch is an
approximation and does not prove 10% bodyweight loading or full plant. Selected
events use `source: "manual_review"`, `status: "limited"` and
`reasons: ["event_timing_uncertain"]`. Dependent measurements retain this limitation.
The API does not guess a landing from the maximum separation or a contact from
body pose. Missing stride frames leave both foot-down metrics unavailable.
Missing contact leaves only the contact metric unavailable. For `dry_swing`,
contact is `contact_not_applicable`; supplying a contact frame is rejected.
## Fetch and forward the payload
1. Upload as before; save `job_id`, `analysis_id`, `analysis_revision`, `status_url`
and the new `coach_payload_url`.
2. Poll `status_url` until completed. Fetch the normal `result_url` for motion
playback and existing artifacts.
3. Fetch **`GET /v1/motion-analyses/{job_id}/coach-payload`** using the same bearer
authentication. It returns the contract JSON itself, without an envelope.
4. The app forwards that JSON unchanged to the coach's
**`POST /v1/sessions/{id}/swing-report`**. The motion API does not call the coach,
invent benchmarks or produce additional scores.
The manifest also exposes `artifacts.coach_payload` with its URL, filename,
checksum, size and expiry. `GET /v1/motion-analyses/{job_id}/artifacts/coach_payload`
downloads the same immutable bytes. The convenience endpoint checks the artifact
checksum and analysis ID/revision before returning it, and sends `Cache-Control:
no-store`. A pending job or a completed analysis without player information returns
409; unauthorized access returns 401; failed integrity checks return 500.
See [output schema](motion-coach-payload.schema.json) and
[example response](motion-coach-payload.example.json). Live schemas remain at
`GET /v1/motion-analyses/input-schema` and `output-schema`; the latter includes
`coach_payload`. The original motion manifest schema version remains `1.0`.
## Measurements, units and reliability
Every completed coach payload includes exactly these three entries, even when
some values are unavailable. Contract and measurement-definition versions are
both `"1.0"`; IDs, units, groups, references and point/interval scopes match the
receiver contract exactly.
| Metric | Calculation |
|---|---|
| `hip_shoulder_separation_at_foot_down` | `wrap180(shoulder_heading - hip_heading)` at `landing_frame`, using the corrected horizontal hip and shoulder lines. **Not the maximum over the swing.** |
| `stride_relative_length` | `100 * norm(horizontal((lead_ankle - rear_ankle)[landing] - (lead_ankle - rear_ankle)[stride_start]))`, in cm. Includes forward and sideways displacement; is not absolute lead-foot ground travel or a percentage of height. |
| `hip_shoulder_separation_at_contact` | The same signed angle at `contact_frame`. |
Angles are in `[-180, 180)`: positive is counter-clockwise shoulder minus hip
heading viewed from above. The same sign convention is kept for both batting
sides. The coach owns side-specific comparisons. SAM and GVHMR use different
native anatomical joint definitions; formula compatibility does not establish
lab accuracy or interchangeability between models.
The exporter uses the **same corrected points** and resolved up direction as
`motion.jsonl`, existing measurements and annotations. Relative measurements do
not require a ground origin; their horizontal plane requires a usable up
direction. The existing camera-stability and landmark checks still apply.
- Unknown up direction → `ground_plane_unknown`; unusable body points →
`required_landmarks_unusable`; unverified/moving camera → `temporal_inconsistency`.
- Model-estimated centimeters → `limited` with `scale_is_model_estimated`.
Unknown scale → stride `unavailable`, `value: null`, `scale_unknown`.
- Missing required events propagate `required_event_unavailable`; missing verified
contact includes `contact_not_verified`. Unknown lead foot includes `lead_foot_unknown`.
- `uses_interpolated_input` checks the required joints at the actual event frames,
not unrelated joints elsewhere in the recording. GVHMR's source-time resampling
is retained as interpolated provenance. Such inputs and filter boundaries add
`temporal_inconsistency`; small interpolation is not called excessive.
- `confidence: null` and `benchmark: null` for every measurement. Accuracy has
not been independently validated. Numerical availability is not a quality grade.
- `video_time_s` comes from source presentation timestamps relative to the first
frame. `capture_time_s` is supplied only with a documented clock mapping; it is
otherwise null. No physical timing is guessed from playback FPS.
## Revisions
Use existing **`POST /v1/motion-analyses/{job_id}/revisions`** with an `options`
patch to change player metadata, contact/stride selections or calculation inputs.
An older analysis can acquire a coach export through a revision adding `athlete`
and `single_swing: true`. Review its `landing_frame` again if it previously marked
a settled/full plant: this contract uses first visible touch. For example:
```json
{
"options": {
"contact_frame": 91,
"athlete": { "height_cm": 176 }
}
}
```
The new payload keeps the root `analysis_id` and `swing_id` and increments
`analysis_revision`, matching the new visual artifacts. Parent files remain
unchanged. Changing an established `athlete_id` or `swing_id` requires a new
analysis. The app/coach must ignore duplicate or older revisions as specified by
the receiver contract. Once enabled, retain `athlete` across revisions; individual
optional player fields can still be cleared to null. Event/player metadata edits reuse eligible native inference
through the existing integrity-checked reuse path.
The payload registers no Balance and Load or Power Move metrics. Other motion
measurements remain in the existing artifacts, but cannot be appended to this
strict three-metric contract without a coordinated contract update.