Expression builders are used to create expression for computing values based on a set of available datapoints, fields, or constants and storing them as realtime or scheduled KPI datapoints.
Note: Expression builder is available by default for Scheduled KPI datapoints. It will become available to Realtime Datapoints on enabling computation allowing for realtime expression computation.
The three components of an expression builder are expressions, variables, and operators.
Expression: An expression can contain up to two variables linked by a single mathematical operator for a single row and can consist of up to five rows, sequentially labelled from A to E. The final expression is constructed using the labels of these rows.
Mathematical Operator: Plus, Minus, Multiply, and Divide are the four supported mathematical operators.
Variables: Variables hold the value to be used in the expression. A variable can be one of the four options: Constant, Datapoint, Field, Parsing Key.
Constant: Numeric value provided by the user. This value will remain constant for all computations.
For example, consider a simple expression used in a datapoint that needs to store the temperature in Kelvin.
Here, the value 273.15 will be the same irrespective of the temperature value in Celsius; values like 273.15 are provided as constants.
Field: A field configured to accept numerical input from the user that can be utilised in further evaluations and computations.
For example, consider an expression used to calculate energy per person, where the daily count of people must be manually input. This data is entered into a field labelled "Today's Head Count."
Parsing Key: Value corresponding to the parsing key fetched from the telemetry JSON object.
For example, consider a JSON payload where the temperature is sent in Kelvin, but you need a datapoint to store the value in Celsius. You can use the parsing key of the JSON object as a variable and then compute the value.
Note: Parsing Key option is not available for Scheduled KPI Datapoints
Datapoint: Value stored in other available datapoint.
For example, consider a scenario where you need a datapoint for power, and you already have the datapoints for current and voltage. You can use them to create the Power Datapoint with the following expression.
In Realtime Datapoints, selecting the datapoint option during configuration allows the value from the datapoint to be used as-is or reprocessed using one of the available mathematical functions. Below is a list of these functions.
Function
| Description |
SIN | Uses the sine value of the datapoint sin(datapoint_value). |
COS | Uses the cosine value of the datapoint sin(datapoint_value). |
TAN | Uses the tan value of the datapoint sin(datapoint_value). |
SQRT | Uses the square root value of the datapoint. |
ABS | Uses the absolute value (non-negative value) of the datapoint. |
CEIL | Uses the value rounded up to the nearest integer. |
FLOOR | Uses the value rounded down to the nearest integer less than or equal to the datapoint value. |
ROUND | Uses the value rounded to the nearest integer. Rounds up if the decimal is 0.5 or more; rounds down if the decimal is less than 0.5. |
PREVIOUS_VALUE | Retrieves and uses the value of the datapoint from the previously received value. |
In Scheduled KPI datapoints, selecting the datapoint option allows you to choose aggregation functions and time periods for these aggregations.
Similarly, for Scheduled KPI Datapoints, related datapoints will become available for selection.
How to build an expression?
Expression are created while creating or configuring a new datapoint.
For a basic expression, fill two variable fields in a row with an operator to compute a value.
Consider a JSON payload where the distance is measured in centimetres but needs to be converted to millimetres.
You can use the expression builder for a straightforward calculation. Since 1 cm equals 10 mm, multiplying the received value by 10 converts it to millimetres. Set up the expression as follows:
Add a variable with the parsing key, and input the parsing key, distance.
Choose the multiplication operator
Add a constant value of 10 in the second variable field
The expression will now store a computed value of 100 in the datapoint.
For complex calculations where you need to perform multiple calculations on a value to be stored, you can use multiple rows and edit the expression of the row labels.
For instance, consider a JSON message where the temperature value is sent in Fahrenheit, but you want to store data in Celsius.
Now, the formula for converting Fahrenheit to Celsius: (F - 32) * 0.55.
To achieve this computation,
In the first row,
Add the parsing key variable with value temp_F
Choose the Subtraction operator.
Add a constant variable of 32.
Then, in the second row,
Add a constant variable of 0.55.
Now, In the expression editor, Create the formula A*B.
Based on the expression, the resulting value stored in the datapoint will be 32.22.
Another example is calculating water usage in an agricultural setup. Here, the water consumed is stored in a datapoint, and the number of plants watered can change and is manually entered in a field called "Plants Watered." An expression can be created to calculate the water usage per plant as follows: