Expressions and Rules
Overview
The Expressions and Rules system provides a powerful way to implement custom logic throughout the application. It enables dynamic behavior for aircraft display, tag formatting, and target symbology based on various flight conditions, controller data, and more.
This system consists of two primary components:
- Expressions: Logical conditions that evaluate to true or false
- Rules: Expressions paired with a value to return when the expression evaluates to true
Schema
Expressions and rules are defined in JSON or YAML format according to the following schema:
{
"expressions": {
"expression_name": <expression>,
...
},
"rules": {
"rule_name": {
"expression": <expression> or [<expression_reference>, ...],
"value": <value>
},
...
}
}
Expressions
Expressions are defined as arrays that represent a logical operation or comparison. The first element is always the operator, followed by the operands.
Basic Comparisons
Basic comparisons take the form:
[<operator>, <variable>, <value>]
For example:
["==", "altitude", 10000]
This checks if the altitude is equal to 10000 feet.
Available Comparison Operators
| Operator | Description |
|---|---|
== | Equality |
!= | Inequality |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
beginsWith | String begins with |
endsWith | String ends with |
contains | String contains |
String Operations
Special string operations:
[<operator>, <string_check_type>, <variable>]
For example:
["notEmpty", "scratchpad"]
This checks if the scratchpad has text in it.
Available String Operators
| Operator | Description |
|---|---|
notEmpty | Checks if a variable has a non-empty value |
isEmpty | Checks if a variable is empty or zero |
Logical Operations
Logical operations take the form:
[<logical_operator>, [<expression1>, <expression2>, ...]]
For example:
[
"AND",
[
["==", "altitude", 10000],
["==", "groundSpeed", 250]
]
]
This checks if BOTH the altitude is 10000 AND the ground speed is 250.
Available Logical Operators
| Operator | Description |
|---|---|
AND | All expressions must be true |
OR | At least one expression must be true |
NOT | Inverts the result of the expression |
Referenced Expressions
You can reference other expressions by name using a string starting with $:
"expressions": {
"is_high_altitude": [">", "altitude", 30000],
"is_fast": [">", "groundSpeed", 450],
"is_high_and_fast": ["AND", ["$is_high_altitude", "$is_fast"]]
}
This creates a reusable is_high_and_fast expression that references two other expressions.
Working with References and Complex Logic
You can build complex logic by combining references and nested expressions:
"is_valid_arrival": ["AND", [
["==", "isArrival", 1],
["NOT", [
["isEmpty", "callsign"]
]],
["OR", [
["==", "groundStatus", "TAXI"],
["==", "groundStatus", "DEPA"]
]]
]]
Available Variables
The expressions system can access variables from several sources:
Aircraft Position Data
altitude- Aircraft altitudeagl- Height above ground levelgroundSpeed- Ground speed in knotsreportedHeading- Aircraft heading as reportedtrackHeading- Track heading (computed)verticalSpeed- Vertical speed in feet per minuteverticalTrend- Vertical trend (UP/DOWN/LEVEL)stopped- Whether the aircraft is stoppedonGround- Whether the aircraft is on the groundtimestamp- Time of the last position updatetransponder- Transponder codelatLon- Latitude/LongitudetrueAltitude- True altitudepressureAltitude- Pressure altitude
Aircraft Data
callsign- Aircraft callsigntype- Aircraft typeisTimingOut- Whether the aircraft track is about to time outlastPositionUpdateReceivedAt- Time of last position updatesquawk- Transponder squawk codelatestTransponderStatus- Status of the transponder
Flight Plan Data
flightRule- Flight rules (IFR/VFR)rawType- Raw aircraft typeicaoTransponderEquipment- ICAO transponder equipment codeicaoEquipment- ICAO equipment codeicaoWakeCategory- ICAO wake categoryacShortType- Short aircraft typeorigin- Origin airportdestination- Destination airportalternate- Alternate airportplannedTas- Planned true airspeedplannedFlightLevel- Planned flight levelrmk- RemarksflightTimeHours- Flight time hoursflightTimeMinutes- Flight time minutesfuelTimeHours- Fuel time hoursfuelTimeMinutes- Fuel time minuteseobt- Estimated off-block timeaobt- Actual off-block timeisValid- Whether the flight plan is validvoiceType- Voice type
Flight Plan Route
sid- Standard Instrument Departurestar- Standard Terminal Arrival RouteisAmended- Whether the route has been amendeddepRunway- Departure runwayarrRunway- Arrival runwayrawRoute- Raw route stringhadStar- Whether the route had a STARhadSid- Whether the route had a SID
Controller Data
clearedFlightLevel- Cleared flight levelassignedHeading- Assigned headingassignedSpeed- Assigned speedassignedMach- Assigned Mach numberassignedVerticalRate- Assigned vertical rateclearanceIssued- Whether clearance has been issuedassignedSquawk- Assigned squawk codeownedByMe- Whether the aircraft is owned by the current controllerownedByCallsign- Callsign of the controller that owns the aircraftscratchpad- Scratchpad contentgroundStatus- Ground statusclearanceQueuePosition- Position in the clearance queueattentionState- Attention state
Computed Data
isArrival- Whether the aircraft is arriving at one of the active airportsisDeparture- Whether the aircraft is departing from one of the active airportsisMyArrival- Whether the aircraft is arriving at my airportisMyDeparture- Whether the aircraft is departing from my airportsuggestedStar- Suggested STAR based on routingsuggestedSid- Suggested SID based on routingsuggestedDepRunway- Suggested departure runwaysuggestedArrRunway- Suggested arrival runwaymyCallsign- Current controller's callsignownedByID- ID of the controller that owns the aircraftcomputedSpeed- Computed speed displaycomputedCFL- Computed cleared flight level display
Rules
Rules combine expressions with values to return when the expression evaluates to true. This allows for dynamic values in tags, colors, and display properties.
Basic Rules
A basic rule consists of an expression and a value:
"rules": {
"warning_color": {
"expression": ["<", "verticalSpeed", -2000],
"value": "255,0,0"
}
}
This returns the color red (255,0,0) when the vertical speed is less than -2000 feet per minute.
Multiple Condition Rules
Rules can include an array of expressions, which are evaluated in order. The first expression that evaluates to true will determine the returned value:
"flight_level_color": {
"expression": [
["<", "altitude", 10000],
["<", "altitude", 20000],
[">=", "altitude", 20000]
],
"value": "0,0,255"
}
Dynamic Values in Rules
Rules can return dynamic values by referencing variables. These are prefixed with &:
"display_assigned_altitude": {
"expression": ["notEmpty", "clearedFlightLevel"],
"value": "&clearedFlightLevel"
}
This returns the actual cleared flight level when one has been assigned.
Using Expressions and Rules in Configuration
Tag Items
Tag items can reference rules for their values and style properties:
{
"itemName": "text",
"value": ["=warning_text", "=normal_text"],
"color": ["=warning_color", "=normal_color"],
"fontSize": "=size_rule"
}
Target Symbology
Target symbols can use expressions to determine when they should be applied:
{
"applyWhen": [
"AND",
[
["==", "onGround", 1],
["<", "groundSpeed", 5]
]
],
"symbol": "parked_aircraft"
}
Colors and Style Properties
Style properties like colors can reference rules:
"speedVectorColor": "=speed_vector_color_rule"
Examples
Example 1: Flight Level Formatting
"expressions": {
"is_low_altitude": ["<", "altitude", 10000],
"is_medium_altitude": ["AND", [
[">=", "altitude", 10000],
["<", "altitude", 20000]
]],
"is_high_altitude": [">=", "altitude", 20000]
},
"rules": {
"altitude_color": {
"expression": ["$is_low_altitude", "$is_medium_altitude", "$is_high_altitude"],
"value": "255,0,0"
},
"altitude_format": {
"expression": ["$is_low_altitude"],
"value": "&altitude"
}
}
Example 2: Attention State Rules
"expressions": {
"needs_attention": ["OR", [
["==", "attentionState", "kWarning"],
["==", "attentionState", "kEmergency"]
]]
},
"rules": {
"callsign_color": {
"expression": "$needs_attention",
"value": "255,255,0"
}
}
Example 3: Ground Movement
"expressions": {
"is_on_ground": ["==", "onGround", 1],
"is_taxiing": ["AND", [
["$is_on_ground"],
[">", "groundSpeed", 5],
["<", "groundSpeed", 30]
]],
"is_taking_off": ["AND", [
["$is_on_ground"],
[">=", "groundSpeed", 30]
]]
},
"rules": {
"ground_status_text": {
"expression": ["$is_taxiing", "$is_taking_off"],
"value": "TAXI"
}
}
Tips and Best Practices
- Name expressions clearly: Use descriptive names like
is_on_approachrather than generic names. - Break down complex logic: Create smaller expressions and combine them using references.
- Validate your expressions: Ensure that they're properly formatted according to the schema.
- Test edge cases: Consider what happens when data is missing or unexpected.
- Use common expressions: Define expressions once and reference them multiple times.
- Create fallback rules: Ensure there's always a valid value for every condition.
- Order matters: In multi-condition rules, expressions are evaluated in the order they appear.
- Avoid deep nesting: Too many nested expressions can be hard to read and maintain.
Troubleshooting
Common Issues
- Expression never evaluates to true: Check that variables exist and have the expected values.
- Rule returns unexpected value: Verify that expressions are being evaluated in the correct order.
- Reference error: Ensure that all referenced expressions (
$expression_name) exist. - Syntax error: Validate your JSON/YAML against the schema.
Debugging Approaches
- Start simple: Test basic expressions before combining them.
- Check the logs: Look for error messages from the expressions engine.
- Use test values: Create expressions with known outcomes to verify behavior.
- Inspect variable values: Add temporary rules to display variable values.