Formulas
The formula syntax below can be used to add calculated variables when loading data:
- In the upload screen in Njord Player or Njord Analytics
- In Njord Analytics, modify already uploaded data by selecting the uploaded data segment (Data section), and select Process
- In Njord Analytics, configure one or more formulas to be applied every time data is uploaded to a certain boat. Set this up under Boat - Settings - Process
Examples
| Formula | Description |
|---|---|
Heading - COG | Difference between Heading and COG |
DELTAPERSEC(UNWRAP(Heading)) | Rate of turn in degrees per second |
DELTAPERSEC(BoatSpeed) * 60 | Acceleration in knots per minute |
BoatSpeed / -(FILTER(DELTASEC(BoatSpeed, 10), DELTASEC(BoatSpeed, 10) < 0) / 10) | When decelerating, how many seconds to zero knots at current 10 second deceleration average |
INTERPOLATED(SERIES("2022-10-01T08:00+02:00", 10, "2022-10-01T11:00+02:00", 14)) | This could be TWS rising from 10 kts at 8 am to 14 kts at 11 am, for example |
0.012 * Heel / (BoatSpeed * BoatSpeed) | Leeway angle estimate — assign this formula to the Leeway metric. Adjust the constant 0.012 to match your boat class. |
SELECTPORTSTBD(PortFoilLoad, StbdFoilLoad) | Leeward foil load — selects the port foil value on port tack and the starboard foil value on starboard tack |
COALESCE(FILTERPORT(PortFoilLoad), FILTERSTBD(StbdFoilLoad)) | Alternative leeward foil load using COALESCE with tack filters |
Heading + 90 | Correct heading for a device mounted 90° off the centreline — assign to Heading |
MAPLINEAR(AnalogIn1, 0.5, 0, 4.5, 100) | Map a 0.5–4.5 V analog sensor signal (from a B&G H5000 analog input) to a 0–100 range |
Operators
| Operator | Description | Notes |
|---|---|---|
+ | Addition | |
- | Subtraction | |
* | Multiplication | |
/ | Division | |
< | Less than | To be used with FILTER() |
<= | Less than equal | To be used with FILTER() |
> | Greater than | To be used with FILTER() |
>= | Greater than equal | To be used with FILTER() |
== | Equals | To be used with FILTER() |
!= | Not equals | To be used with FILTER() |
& | Logical and | To be used with FILTER() |
| | | Logical or | To be used with FILTER() |
! | Negate | To be used with FILTER() |
Functions
| Function | Description |
|---|---|
ABS(value) | Absolute of value / remove sign |
SIGN(value) | Returns an indication of the sign of values, -1, 0, or 1. |
MIN(value1, value2) | Minimum of two values |
MAX(value1, value2) | Maximum of two values |
MOD(a, n) | Modulo operation |
SIN(value) | Sine of value (which is expected to be in degrees) |
COS(value) | Cosine of value (which is expected to be in degrees) |
ARCTAN2(x, y) | Element-wise arc tangent (in degrees) of x/y choosing the quadrant correctly. |
FILTERPORT(value) | Retains the value only on port tack (AWA between -170 and -10) |
FILTERSTBD(value) | Retains the value only on starboard tack (AWA between 10 and 170) |
COALESCE(value1, value2) | Choose value1 if it's not empty, else value2 |
SELECTPORTSTBD(valuePort, valueStbd) | Select valuePort when sailing on port tack, valueStbd on starboard tack |
UNWRAP(value) | Removes wrap at 0/360 degrees, instead expands value below 0 or above 360 as needed for safe calculations |
SHIFT(value, rows) | Shifts value (series) by given number of rows |
SHIFTSEC(value, seconds) | Shifts value (series) by given number of seconds |
DELTASEC(value, seconds) | Delta of value compared to second seconds ago |
DELTAPERSEC(value) | Delta of value compared to previous datapoint, divided by number of seconds since last datapoint |
ROLLINGMEAN(value, seconds) | Rolling mean over second seconds |
ROLLINGSUM(value, seconds) | Rolling sum over second seconds |
FILTER(value, mask) | Filters value using the given mask, returning empty value where the mask is false |
INTERPOLATED(value) | Fill blanks between values by linear interpolation |
INTERPOLATEDBEARING(value) | Fill blanks between values by linear interpolation, correctly handling 0/360 degree wrap around |
SERIES(time1, value1, time2, value2, ...) | Produces a data series with the given values at the given times. Write times in ISO 8601 format with quotes, like "2022-10-01T10:00+02:00". Use with INTERPOLATED(). |
TWA(awa, aws, sog) | Calculates true wind angle from apparent wind and SOG/boat speed |
TWS(awa, aws, sog) | Calculates true wind speed from apparent wind and SOG/boat speed |
AWA(twa, tws, sog) | Calculates apparent wind angle from true wind and SOG/boat speed |
AWS(twa, tws, sog) | Calculates apparent wind speed from true wind and SOG/boat speed |
INTEGRATE(value, gap) | Integration over time (in seconds) using the trapezoidal rule. gap is optional (defaults to 10 seconds) - any gaps in data greater than this are omitted. |
MAPLINEAR(value, x1, y1, x2, y2[, ...][, xn, yn][, extrapolate]) | For each value between x1 and x2, produces an output value between y1 and y2 using linear interpolation, between x2 and x3 interpolates between y2 and y3, etc. If extrapolate is 1 or true, input values below x1 and above the highest xn value are mapped using extrapolation of the nearest linear pair, otherwise those output values will be empty. |
Note: all function names are case insensitive and may be written in lower case too.
Notes
Metric names with special characters or spaces must be wrapped in double quotes when used in a formula. For example, a channel named Forestay Load from a custom instrument must be referenced as "Forestay Load". Standard Njord metric names (listed in Metrics) do not contain spaces or special characters and do not need quoting.