math
Look up math.avg, math.min, math.max, and math.derivative, the running statistics of the Arc math module.
The math module gives running statistics and rates of change of a numeric value.
Import it with import math. All math functions are flow functions: a function body
cannot call them.
avg, min, and max share these parameters:
durationi64 ns = 0Start again when this much time has passed, measured on input timestamps.
counti64 = 0Start again on the next input after this many values.
resetbool = falseHas no effect in text mode, which cannot wire an input to it.
With duration and count at 0, the value covers every input since the stage started.
A window starts again with the input that ends the old window. Synnax reads duration
and count once, when the automation starts.
avg
Gives the average of all input values since the window started.
- Input -> a numeric value.
- Output -> one value for each input batch, of the same type as the input. It has the timestamp of the last value in the batch. It is not a moving average.
- Runs -> on each new input. Its window starts again when its stage starts.
import math
tank_pt -> math.avg{duration=5s} -> tank_pt_avgAn integer input gives an integer average, rounded toward zero. On the Core, the sum
uses the input type, so it can overflow and loses precision. Use a float input. A Driver
sums in f64.
derivative
Gives the rate of change of the input, in units per second.
- Input -> a numeric value.
- Output -> one
f64value for each input value, with the same timestamp. The rate is the change from the previous value, divided by the time between their timestamps. - Runs -> on each new input. The first value, and a value with a timestamp that is not later than the one before it, give 0. It starts again when its stage starts.
derivative has no parameters.
import math
tank_pt -> math.derivative{} -> tank_pt_ratemax
Gives the largest input value since the window started.
- Input -> a numeric value.
- Output -> one value for each input batch, of the same type as the input.
- Runs -> on each new input. Its window starts again when its stage starts.
import math
tank_pt -> math.max{} -> tank_pt_maxmin
Gives the smallest input value since the window started.
- Input -> a numeric value.
- Output -> one value for each input batch, of the same type as the input.
- Runs -> on each new input. Its window starts again when its stage starts.
import math
tank_pt -> math.min{count=1000} -> tank_pt_min