Skip to main content

Operator - Formula

note

This page has been automatically translated and has not been reviewed in detail yet. Therefore, the translation might not be completely accurate.

Formulas are a special type of operation

Variable processing formulas are primarily used to perform simple to complex calculations of variable values. They can also be used to trim or rewrite values, as well as to manipulate character strings.

Directions

First, a target variable is defined using drag and drop.

Then switch to the “Operations” tab in the left area and enter “Formula” using drag and drop.

A new field appears below for the Value, where the formula can be entered.

Any number of parameters can be added using the plus button.

Screenshot Operator "Formula"

Constant values can be entered in the parameter fields or you can use variables from the variables tab on the left.

Important: Values are JSON strings. This means that texts must be written in quotation marks. For the text Hello World, you have to enter “Hello World”`.

The numbered input fields cannot contain any formula code themselves and are therefore limited to valid JSON values for constants: string/number/boolean.

Examples

Multiplying two values

Screenshot example of multiplying two values

If typecasting is activated, the decimal place is rounded and written to the target variable.

Replace one text with another

$[1].replace($[2], $[3])

Screenshot example replace text

Result: "I am a text!"

Complex example: Linear conversion between value ranges

($[3] - $[2]) * ($[1] - $[4]) / ($[5] - $[4]) + $[2]

Screenshot Linear conversion between value ranges

In this example you get a volume value from an audio DSP in dB, i.e. a value between -60 and 0. This value is stored in the variable "Volume_in_DB".

For example, this value should be displayed as a percentage on a dashboard. For this we use the target variable “Volume_in_Percent”

If the dB value is e.g. E.g. -20, you want to display "66%" on the dashboard.

$\[1\] = Initial value in DB
$\[2\] = 0 = Target value range start
$\[3\] = 100 = target value range end
$\[4\] = -60 = Initial value range start
$\[5\] = 0 = Output value range end

If you want to convert from percent to dB, the value ranges can simply be swapped.

A logarithmic conversion would also be possible using an extended formula.

Further examples

  • $[1].trim() to remove whitespace around a string
  • $[1].toUpperCase()$[1].toLowerCase() Convert all letters to uppercase or lowercase
  • $[1].length to determine the length of a text
  • Math.floor((Math.random() * 10``) + 1``) Generate a random number between 1 and 10
  • Math.log($[1]) Calculate logarithm of a number
  • Math.PI For the Pi value
  • new Date().toISOString() Creates an ISO string at the current time