Reference
Grading rules
Data-driven grading, carried in the same file as triggers
(ScriptImport.File.grading.rules) — a JSON-authored script can be scored without a
coach-ios recompile, the same way its triggers already can be. Source of truth:
ScriptImport.makeGradingRules in CoachApp/ATC/ScriptImport+Grading.swift,
resolving into a real DeclarativeGradingRule (CoachApp/Debrief/DeclarativeGradingRule.swift).
There's a second, reusable grading mechanism outside this file entirely: an
action.grade_against field (see the
failure action) names a ProcedureFlowCatalog id — an existing, engine-identity-aware,
ordered-checklist grader (e.g. abort-take-off-multi, drill-engine-out-multi)
that already threads which engine actually failed straight from the fired trigger's own payload, with
zero plumbing here. Reach for a real procedure flow before writing a custom declarative rule, if one
already matches the checklist you're grading.
Rule shape, fields & tolerance
{ "id": "r_centerline_1", "label": "Centerline tracking during the rejected takeoff",
"kind": "centerline_deviation", "runway_width_ft": 75,
"window_start": { "kind": "trigger", "trigger_id": "t_fail_1" },
"window_end": { "kind": "trigger", "trigger_id": "t_stopped_1" } }
Every rule has a stable id (your own choice, used only for internal lookup), a human
label (shown in the audit/debrief UI), a kind, and kind-specific fields.
trigger_id-style fields here resolve against the same real id→UUID map
this file's own triggers array built — not a trigger's name (a
hand-authored Swift script's own graders resolve by name instead; a JSON file always uses the real id).
field (telemetry channel)
One of: obs_deg, mag_hdg, true_hdg, alt_ft,
agl_ft, ias_kts, loc_dots_abs (localizer, always vs. 0),
gs_dots_abs (glideslope, always vs. 0), gear_down_fraction (1.0/0.0),
flap_ratio, brake_ratio, bank_deg_abs (bank angle magnitude,
always vs. a target regardless of turn direction — a left and right bank of the same magnitude are
equally correct or equally wrong).
tolerance
Omit entirely for the default, or give one of:
| a string | "heading" or "altitude" — resolves against the pilot's live, preset-tiered ScoringRules. |
| a number | a literal tolerance, overriding the preset entirely. |
| a 2-element array | ["heading", 2.0] — a named tolerance scaled by a factor. |
window_start / window_end (WindowBoundary)
| kind | fields | resolves to |
|---|---|---|
| start_of_flight | — | the recording's first sample. |
| end_of_flight | — | the recording's last sample. |
| trigger | trigger_id | the instant that trigger fired. |
| first_sample_where | field, op ("gte"/"lte"), value | the first sample anywhere in the flight where field crosses value in that direction. |
| first_sample_where_after | same as above, plus after (a nested WindowBoundary) | the first crossing strictly after after's own resolved instant — use this instead of the bare form whenever the same crossing condition can happen more than once in a flight (e.g. the same NAV frequency's localizer dots dip below threshold on an intercept, a procedure-turn rejoin, AND the real final). |
| fallback | primary, if_unresolved (both nested WindowBoundary) | primary unless it never resolves (e.g. a first_sample_where that never happens), in which case if_unresolved instead. |
fired pass/fail
→ DeclarativeGradingRule.fired(id:label:triggerID:)
| trigger_id | required | that named trigger fired at all during the flight. |
{ "id": "landed", "label": "Landed", "kind": "fired", "trigger_id": "t_complete" }
value_at_trigger pass/fail
→ DeclarativeGradingRule.valueAtTrigger
| trigger_id | required | |
| field | required | |
| target | required | number. |
| tolerance | optional | see above. |
| accept_reciprocal | optional, default false | bool — true accepts target OR target+180, whichever is closer (a charted radial, equally correct dialed either direction). Only meaningful for a heading-shaped field. |
{ "id": "r_sac_radial", "label": "SAC radial dialed", "kind": "value_at_trigger",
"trigger_id": "t_at_sokoy", "field": "obs_deg", "target": 71, "accept_reciprocal": true }
value_at_trigger_from_payload pass/fail, dynamic target
→ DeclarativeGradingRule.valueAtTriggerFromPayload
Like value_at_trigger, except the target isn't a fixed number — it's extracted from
another trigger's own fired payload via a registered extractor (e.g. ATC rolled a fresh hold radial live;
there's no fixed chart number to put in a JSON file for it). field is read at
read_trigger_id's own instant, NOT payload_trigger_id's — the pilot isn't told
the assigned value until that trigger's own message finishes.
| payload_trigger_id | required | which trigger's fired payload to extract the target from. |
| extractor_id | required | string — a registered extractor key (DeclarativeGrading.payloadExtractors). |
| read_trigger_id | required | which trigger's instant to read field at. |
| field | required | |
| tolerance | optional | |
| accept_reciprocal | optional, default false | bool. |
{ "id": "r_hold_radial", "label": "Hold radial dialed", "kind": "value_at_trigger_from_payload",
"payload_trigger_id": "t_hold_instruction", "extractor_id": "hold_radial_deg",
"read_trigger_id": "t_established_inbound", "field": "obs_deg" }
value_between_triggers pass/fail
→ DeclarativeGradingRule.valueBetweenTriggers
| start_trigger_id | required | |
| end_trigger_id | required | |
| field | required | |
| tolerance | optional | |
| target_delta | optional, default 0 | number — 0 checks "ended up back near where it started"; nonzero checks "changed by about this much" (e.g. "turned ~30° left"). |
{ "id": "r_turn_30", "label": "Turned 30 left", "kind": "value_between_triggers",
"start_trigger_id": "t_baseline", "end_trigger_id": "t_turn_done", "field": "mag_hdg", "target_delta": -30 }
window_percent_in_tolerance percentage
→ DeclarativeGradingRule.windowPercentInTolerance
What percent of samples in a window satisfy the per-sample check. target is genuinely
optional here, unlike every other rule kind — omitted means "whatever field actually read at
the window's own start" (a self-referential, per-flight target — e.g. "no turns off whatever heading you
actually departed on").
| field | required | |
| window_start / window_end | required | |
| target | optional | number — see above. |
| tolerance | optional | |
| comparison | optional, default "symmetric" | symmetric (abs(actual-target) <= tol), at_or_below, or at_or_above — a one-sided ceiling/floor instead of a band (e.g. "mark down if we ever exceed 2000 ft"). |
{ "id": "r_gear_2", "label": "Gear stayed down", "kind": "window_percent_in_tolerance",
"field": "gear_down_fraction", "target": 1.0, "tolerance": 0, "comparison": "at_or_above",
"window_start": { "kind": "trigger", "trigger_id": "t_fail_2" },
"window_end": { "kind": "trigger", "trigger_id": "t_stopped_2" } }
closest_in_window pass/fail over a window
→ DeclarativeGradingRule.closestInWindow
"Did the value ever get close to target, at some point in this window" — finds the single closest sample, then checks THAT one's error against tolerance. A pass/fail check, not a percentage.
| field | required | |
| target | required | number. |
| window_start / window_end | required | |
| tolerance | optional |
{ "id": "r_intercept", "label": "Flew the charted intercept heading", "kind": "closest_in_window",
"field": "mag_hdg", "target": 245,
"window_start": { "kind": "trigger", "trigger_id": "t_departed" },
"window_end": { "kind": "trigger", "trigger_id": "t_on_course" } }
capture_then_hold_to_end percentage, floating start
→ DeclarativeGradingRule.captureThenHoldToEnd
"No penalty before the aircraft actually captures the target, a real tolerance once it does" — searches
forward from window_start for the first sample within tolerance of target (that's the
capture point), then grades every sample from there to the end of the flight. Never captured at all →
the whole rule is ungraded, not scored as a failure for still approaching.
| field | required | |
| target | required | number. |
| window_start | required | where to start searching for capture (wire key is window_start; there is no separate window end — it always grades to the end of the flight). |
| tolerance | optional |
{ "id": "r_cruise_alt", "label": "Held cruise altitude", "kind": "capture_then_hold_to_end",
"field": "alt_ft", "target": 7000, "window_start": { "kind": "trigger", "trigger_id": "t_departed" } }
reached_fix pass/fail, no trigger needed
→ DeclarativeGradingRule.reachedFix
Did the aircraft ever get within within_nm of a resolved fix, at some point in the window.
fix_ref is resolved through the grader's own fix-resolver — a plain string key, not
necessarily a real published fix name (an ad-hoc hold site rolled fresh every attempt resolves through
its own sentinel key the same way a real VOR would).
| fix_ref | required | string. |
| within_nm | required | number. |
| window_start / window_end | required |
{ "id": "r_briefing", "label": "Reached the entry briefing point", "kind": "reached_fix",
"fix_ref": "SAC", "within_nm": 3,
"window_start": { "kind": "start_of_flight" }, "window_end": { "kind": "end_of_flight" } }
centerline_deviation continuous
→ DeclarativeGradingRule.centerlineDeviation
How close the aircraft stayed to the runway centerline over the window — a continuous, per-sample credit
score, not pass/fail: max(0, 1 - |crossTrackFt| / (runway_width_ft/2)) * 100 (100% on
centerline, linear to 0% at half-width, floored at 0% beyond). The runway anchor itself (position + true
course) is resolved from the window's own START sample — no separate runway/plan lookup needed.
runway_width_ft is a given input, never looked up from CIFP (which has no width column).
| runway_width_ft | required | number. |
| window_start / window_end | required |
{ "id": "r_centerline_1", "label": "Centerline tracking", "kind": "centerline_deviation", "runway_width_ft": 75,
"window_start": { "kind": "trigger", "trigger_id": "t_fail_1" },
"window_end": { "kind": "trigger", "trigger_id": "t_stopped_1" } }
stopped_before_runway_end pass/fail
→ DeclarativeGradingRule.stoppedBeforeRunwayEnd
Did the aircraft ever get further along the runway than runway_length_ft from the window's
own start — never exceeded, anywhere in the window, passes. Same runway-anchor convention as
centerline_deviation.
| runway_length_ft | required | number. |
| window_start / window_end | required |
{ "id": "r_stopped_1", "label": "Stopped before the runway end", "kind": "stopped_before_runway_end",
"runway_length_ft": 5000,
"window_start": { "kind": "trigger", "trigger_id": "t_fail_1" },
"window_end": { "kind": "trigger", "trigger_id": "t_stopped_1" } }
airspeed_penalty_curve continuous
→ DeclarativeGradingRule.airspeedPenaltyCurve
A piecewise-linear penalty curve over author-supplied anchor points, each resolved against a V-speed
(AircraftProfile.value(for:), same lookup vspeed-relative
conditions use) plus a fixed offset — e.g. "0% at Vmc, 25% at Vmc+5, 100% at blue line." NOT a fixed
two-point line — three anchors can't be expressed by min/max interpolation alone. Per-sample credit
interpolates ias_kts between the two bracketing anchors (sorted by resolved knots), clamped
flat outside that range. An anchor whose vspeed_ref doesn't resolve on the pilot's current
profile is simply dropped from the curve (not a failure) — a curve left with fewer than 2 resolvable
anchors isn't graded at all.
| anchors | required, >= 2 | array of { "vspeed_ref": string?, "offset_kts": number, "percent": number }. |
| window_start / window_end | required |
{ "id": "r_airspeed_curve_3", "label": "Airspeed vs. blue line", "kind": "airspeed_penalty_curve",
"anchors": [
{ "vspeed_ref": "vmc", "offset_kts": 0, "percent": 0 },
{ "vspeed_ref": "vmc", "offset_kts": 5, "percent": 25 },
{ "vspeed_ref": "vyse", "offset_kts": 0, "percent": 100 }
],
"window_start": { "kind": "trigger", "trigger_id": "t_fail_3" },
"window_end": { "kind": "trigger", "trigger_id": "t_tpa_reached" } }
swift_classifier escape hatch
→ DeclarativeGradingRule.swiftClassifier
The deliberate escape hatch for a real shape that doesn't fit "trigger + field + tolerance" — today only
"hold_entry" exists, reading the already-graded hold-entry classification
(teardrop/parallel/direct) rather than re-running that geometric classifier. Adding a new classifier key
requires a Swift change (DeclarativeGrading.classifiers); this rule kind just exposes
whatever's registered there to JSON.
| classifier_id | required | string — a registered key. |
| fix_ident | optional | string — narrows to one hold when a plan has more than one; omitted matches the first graded entry. |
{ "id": "r_entry", "label": "Correct hold entry", "kind": "swift_classifier", "classifier_id": "hold_entry" }
Objectives live checklist
A lesson's own live, in-flight objectives checklist (ScriptImport.File.objectives) — carried
in the same file as triggers/grading, same reasoning: one file, not two composed
across a shared id map. Source: ScriptImport.makeObjectives in
CoachApp/ATC/ScriptImport+Objectives.swift.
| text | required | string — shown in the objectives panel. |
| for_trigger | required | string — matched against a trigger's name (not its id) via LessonManager.firedTriggerNames. A typo or later rename just never completes — same silent-no-match failure mode a stale string already has, not a new risk. |
| highlighted | optional, default false | bool — renders in orange. |
| expected_delta_seconds | optional | number — seconds normally expected since the PREVIOUS objective's real completion (or mission start, for the first). Omitted opts this objective out of timeout checking. If real elapsed time exceeds 200% of this budget, the pilot gets a "possible deviation" nudge. |
{ "text": "Reach pattern altitude.", "for_trigger": "Reached pattern altitude" }