Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _data/calculated-fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
simple-calculated-field:
title: Simple calculated field
description: Simple calculated fields use basic arithmetic operations (+, -, *, /) and standard functions such as sqrt (square root), pow (power), abs (absolute value), etc.
script-calculated-field:
title: Script calculated field
description: For complex calculations, TBEL is used. It enables advanced operations such as conditional statements, loops, and access to historical data.
6 changes: 6 additions & 0 deletions _data/pages_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4839,6 +4839,12 @@
"/docs/user-guide/calculated-fields/":
url: "/docs/user-guide/calculated-fields/"
redirect_from: []
"/docs/user-guide/calculated-fields/script-calculated-field/":
url: "/docs/user-guide/calculated-fields/script-calculated-field/"
redirect_from: []
"/docs/user-guide/calculated-fields/simple-calculated-field/":
url: "/docs/user-guide/calculated-fields/simple-calculated-field/"
redirect_from: []
"/docs/user-guide/certificates/":
url: "/docs/user-guide/certificates/"
redirect_from: []
Expand Down
17 changes: 17 additions & 0 deletions _includes/calculated-fields-cards.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% assign calculatedFields = site.data.calculated-fields %}

<ul class="calculated-fields">
{% for field in calculatedFields %}
<li class="field">
<a class="field-link" href="/docs/user-guide/calculated-fields/{{ field[0] }}">
<div class="field-img">
<img src="{{ field[1].img }}" alt="{{ field[1].title }} icon" width="36" height="36" loading="lazy">
</div>
<div class="field-text">
<span>{{ field[1].title }}</span>
<p>{{ field[1].description }}</p>
</div>
</a>
</li>
{% endfor %}
</ul>
40 changes: 40 additions & 0 deletions _includes/calculated-fields-cards.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#docsContent
.calculated-fields
max-width: 1300px
display: flex
flex-wrap: wrap
justify-content: center
gap: 20px
margin: 40px 0
padding-left: 0
.field
width: 258px
list-style: none
background: #FFF
border-radius: 16px
border: 1px solid rgba(0, 0, 0, 0.08)
transition: ease-in-out 0.3s
&:hover
background: #F4F8FE
box-shadow: -4px 15px 50px -20px rgba(0, 0, 0, 0.15), 0 0 8px 0 rgba(0, 0, 0, 0.08)
.field-link
display: flex
flex-direction: column
gap: 20px
padding: 24px
&:hover
text-decoration: none
.field-text
display: flex
flex-direction: column
gap: 8px
span
font-size: 16px
font-weight: 500
line-height: 28px
color: rgba(0, 0, 0, 0.87)
p
font-size: 14px
font-weight: 400
line-height: 24px
color: rgba(0, 0, 0, 0.76)
Original file line number Diff line number Diff line change
Expand Up @@ -105,101 +105,9 @@ Time series rolling<small>only for Script type</small>%,%timeSeriesRolling%,%tem

{% include content-toggle.liquid content-toggle-id="calculatedfieldsargumenttype" toggle-spec=calculatedfieldsargumenttype %}

### Simple calculated field
### Calculated fields

Simple calculated fields use basic arithmetic operations (+, -, *, /) and standard functions such as `sqrt` (square root), `pow` (power), `abs` (absolute value), etc.

#### Expression

In the "Expression" section, enter the mathematical expression for the calculation using the variables defined in the ["Arguments"](#arguments) section.

{% include images-gallery.html imageCollection="expression-simple-calculated-fields-1" %}

#### Output

The result of the calculation can be saved either as a [time series](/docs/{{docsPrefix}}user-guide/telemetry/){:target="_blank"} or as an [attribute](/docs/{{docsPrefix}}user-guide/attributes/){:target="_blank"}.
> See [how calculated field output is processed](#calculated-field-output-processing) for details on rule engine behavior and data persistence.

In the "Output" section:
- Specify the variable type: **Time series** or **Attribute**, along with the **attribute scope**.
- Assign a name to the variable that will store the calculation result.
- Optionally, set **Decimals by default** to define how many decimal places the result should be rounded to. If not specified, the result will not be rounded.
- To finish adding the calculated field, click "Add".

> **[Only for Time series]**<br>
"**Use latest timestamp**" option — when enabled, the calculated value will be stored using the most recent timestamp from the arguments telemetry instead of the server time.

{% include images-gallery.html imageCollection="output-simple-1" %}

### Script calculated field

For complex calculations, [TBEL](/docs/{{docsPrefix}}user-guide/tbel/){:target="_blank"} is used.
It enables advanced operations such as conditional statements, loops, and access to historical data.

#### Script

Define a function that will perform calculations using the variables defined in the ["Arguments"](#arguments) section.

> The variable name that will store the calculation result is defined within the function itself.

<br>

Example: the function below uses the `temperature` and `humidity` arguments to calculate the dew point value.
The calculation result will be stored in the variable `dewPoint`, rounding the value to one decimal places.

```js
// Constants for Magnus formula
var a = 17.625;
var b = 243.04;

var alpha = ((a * temperature) / (b + temperature)) + Math.log(humidity / 100.0);
var dewPoint = toFixed((b * alpha) / (a - alpha), 1);

return {"dewPoint": dewPoint};
```
{: .copy-code}

{% include images-gallery.html imageCollection="expression-script-calculated-fields-1" %}

Script calculated fields require the definition of a `calculate(ctx, ...)` function. This function receives the `ctx` object and arguments declared in the configuration.

```javascript
function calculate(ctx, arg1, arg2, ...): object | object[]
```

- `ctx`: context object that stores `latestTs` and provides access to all configured arguments.

Context structure:
- `ctx.latestTs`: the most recent timestamp (in milliseconds) from the arguments telemetry. Useful for aligning the result with the incoming data time instead of the server time.
- `ctx.args`: an object that contains all declared arguments, where each argument can be accessed using `.` notation:
- **single value arguments** (attribute or latest telemetry):
- `ctx.args.<arg>.ts`: timestamp of the argument.
- `ctx.args.<arg>.value`: actual value of the argument.
- **time series rolling arguments**:
- `ctx.args.<arg>.timeWindow`: object with `startTs` and `endTs` timestamps.
- `ctx.args.<arg>.values`: array of `{ ts, value }` records representing timestamped telemetry.
- `ctx.args.<arg>.<method>`: call built-in aggregation methods such as `mean()`, `sum()`, `min()`, `max()`, `first()`, `last()`, `merge(...)`, and others.
> For more details, refer to the [time series rolling argument](#arguments).
- `arg1, arg2, ...`: direct access to arguments by name as function parameters. This can be useful for cleaner or more concise expressions. These arguments may be:
- single value arguments (attribute or latest telemetry arguments): telemetry value may be of type boolean, int64 (long), double, string, or JSON.
- time series rolling arguments: objects that contain time series data within a defined time window.

Use either `ctx.args.<arg>` or direct parameter access depending on preference and context clarity.

#### Output

> See [how calculated field output is processed](#calculated-field-output-processing) for details on rule engine behavior and data persistence.

The calculated values are returned as a JSON object containing **keys** that represent the computed results, which are then used to store those values in the system.

- Specify the **Output type** for storing the calculation result:
- [Time series](/docs/{{docsPrefix}}user-guide/telemetry/){:target="_blank"}: function must return a JSON object or array with or without a timestamp containing the computed value.
- [Attribute](/docs/{{docsPrefix}}user-guide/attributes/){:target="_blank"}: function must return a JSON object **without timestamp** information containing the computed value.
- Choose the **attribute scope**: **Server attributes**, **Client attributes**, or **Shared attributes**.
- To align the result with the latest timestamp of the input arguments telemetry, use `ctx.latestTs` and assign it explicitly to the `ts` field in the returned object.
- To finish adding the calculated field, click "Add".

{% include images-gallery.html imageCollection="output-script-1" %}
{% include calculated-fields-cards.liquid %}

### Result

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
* TOC
{:toc}

For complex calculations, [TBEL](/docs/{{docsPrefix}}user-guide/tbel/){:target="_blank"} is used.
It enables advanced operations such as conditional statements, loops, and access to historical data.

#### Script

Define a function that will perform calculations using the variables defined in the ["Arguments"](#arguments) section.

> The variable name that will store the calculation result is defined within the function itself.

<br>

Example: the function below uses the `temperature` and `humidity` arguments to calculate the dew point value.
The calculation result will be stored in the variable `dewPoint`, rounding the value to one decimal places.

```js
// Constants for Magnus formula
var a = 17.625;
var b = 243.04;

var alpha = ((a * temperature) / (b + temperature)) + Math.log(humidity / 100.0);
var dewPoint = toFixed((b * alpha) / (a - alpha), 1);

return {"dewPoint": dewPoint};
```
{: .copy-code}

{% include images-gallery.html imageCollection="expression-script-calculated-fields-1" %}

Script calculated fields require the definition of a `calculate(ctx, ...)` function. This function receives the `ctx` object and arguments declared in the configuration.

```javascript
function calculate(ctx, arg1, arg2, ...): object | object[]
```

- `ctx`: context object that stores `latestTs` and provides access to all configured arguments.

Context structure:
- `ctx.latestTs`: the most recent timestamp (in milliseconds) from the arguments telemetry. Useful for aligning the result with the incoming data time instead of the server time.
- `ctx.args`: an object that contains all declared arguments, where each argument can be accessed using `.` notation:
- **single value arguments** (attribute or latest telemetry):
- `ctx.args.<arg>.ts`: timestamp of the argument.
- `ctx.args.<arg>.value`: actual value of the argument.
- **time series rolling arguments**:
- `ctx.args.<arg>.timeWindow`: object with `startTs` and `endTs` timestamps.
- `ctx.args.<arg>.values`: array of `{ ts, value }` records representing timestamped telemetry.
- `ctx.args.<arg>.<method>`: call built-in aggregation methods such as `mean()`, `sum()`, `min()`, `max()`, `first()`, `last()`, `merge(...)`, and others.
> For more details, refer to the [time series rolling argument](#arguments).
- `arg1, arg2, ...`: direct access to arguments by name as function parameters. This can be useful for cleaner or more concise expressions. These arguments may be:
- single value arguments (attribute or latest telemetry arguments): telemetry value may be of type boolean, int64 (long), double, string, or JSON.
- time series rolling arguments: objects that contain time series data within a defined time window.

Use either `ctx.args.<arg>` or direct parameter access depending on preference and context clarity.

#### Output

> See [how calculated field output is processed](#calculated-field-output-processing) for details on rule engine behavior and data persistence.

The calculated values are returned as a JSON object containing **keys** that represent the computed results, which are then used to store those values in the system.

- Specify the **Output type** for storing the calculation result:
- [Time series](/docs/{{docsPrefix}}user-guide/telemetry/){:target="_blank"}: function must return a JSON object or array with or without a timestamp containing the computed value.
- [Attribute](/docs/{{docsPrefix}}user-guide/attributes/){:target="_blank"}: function must return a JSON object **without timestamp** information containing the computed value.
- Choose the **attribute scope**: **Server attributes**, **Client attributes**, or **Shared attributes**.
- To align the result with the latest timestamp of the input arguments telemetry, use `ctx.latestTs` and assign it explicitly to the `ts` field in the returned object.
- To finish adding the calculated field, click "Add".

{% include images-gallery.html imageCollection="output-script-1" %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
* TOC
{:toc}

Simple calculated fields use basic arithmetic operations (+, -, *, /) and standard functions such as `sqrt` (square root), `pow` (power), `abs` (absolute value), etc.

#### Expression

In the "Expression" section, enter the mathematical expression for the calculation using the variables defined in the ["Arguments"](#arguments) section.

{% include images-gallery.html imageCollection="expression-simple-calculated-fields-1" %}

#### Output

The result of the calculation can be saved either as a [time series](/docs/{{docsPrefix}}user-guide/telemetry/){:target="_blank"} or as an [attribute](/docs/{{docsPrefix}}user-guide/attributes/){:target="_blank"}.
> See [how calculated field output is processed](#calculated-field-output-processing) for details on rule engine behavior and data persistence.

In the "Output" section:
- Specify the variable type: **Time series** or **Attribute**, along with the **attribute scope**.
- Assign a name to the variable that will store the calculation result.
- Optionally, set **Decimals by default** to define how many decimal places the result should be rounded to. If not specified, the result will not be rounded.
- To finish adding the calculated field, click "Add".

> **[Only for Time series]**<br>
"**Use latest timestamp**" option — when enabled, the calculated value will be stored using the most recent timestamp from the arguments telemetry instead of the server time.

{% include images-gallery.html imageCollection="output-simple-1" %}
1 change: 1 addition & 0 deletions css/docs.sass
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import "../_includes/content-toggle-liquid"
@import "../_includes/images-gallery"
@import "../_includes/rule-node-cards"
@import "../_includes/calculated-fields-cards"
@import "../_includes/manual-breadcrumbs"
@import "../_includes/usecase-nav"
@import "../_includes/trendz-wizard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ time-series-rolling-argument-type:
image: /images/user-guide/calculated-fields/time-series-rolling-argument-type-2-pe.png
title: 'A new argument has been added.'

expression-simple-calculated-fields-1:
0:
image: /images/user-guide/calculated-fields/expression-simple-calculated-fields-1-pe.png
title: 'In the "Expression" section, enter the mathematical expression for the calculation using the variables defined in the "Arguments" section.'

output-simple-1:
0:
image: /images/user-guide/calculated-fields/output-simple-1-pe.png
title: 'Select the output type as "Time series". Set a name to the variable that will store the calculation result. Optionally, specify the number of decimal places.'
1:
image: /images/user-guide/calculated-fields/output-simple-2-pe.png
title: 'Select the output type as "Attribute" and choose its scope: "Server attributes", "Client attributes", or "Shared attributes". Set a name to the variable that will store the calculation result. Optionally, set the number of decimal places.'

expression-script-calculated-fields-1:
0:
image: /images/user-guide/calculated-fields/expression-script-calculated-fields-1-pe.png
title: 'Define a function that will perform calculations using the variables defined in the "Arguments" section. The variable name that will store the calculation result is defined within the function itself.'

output-script-1:
0:
image: /images/user-guide/calculated-fields/output-script-1-pe.png
title: 'Time series: function must return a JSON object or array with or without a timestamp containing the computed value.'
1:
image: /images/user-guide/calculated-fields/output-script-2-pe.png
title: 'Attribute: function must return a JSON object without timestamp information containing the computed value.'

calculated-field-result:
0:
image: /images/user-guide/calculated-fields/calculated-field-result-1-pe.png
Expand Down Expand Up @@ -238,4 +212,4 @@ example-script-calculated-fields-3:

{% assign docsPrefix = "paas/eu/" %}
{% include get-hosts-name.html docsPrefix=docsPrefix %}
{% include docs/user-guide/calculated-fields.md %}
{% include docs/user-guide/calculated-fields/index.md %}
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ time-series-rolling-argument-type:
image: /images/user-guide/calculated-fields/time-series-rolling-argument-type-2-pe.png
title: 'A new argument has been added.'

expression-simple-calculated-fields-1:
0:
image: /images/user-guide/calculated-fields/expression-simple-calculated-fields-1-pe.png
title: 'In the "Expression" section, enter the mathematical expression for the calculation using the variables defined in the "Arguments" section.'

output-simple-1:
0:
image: /images/user-guide/calculated-fields/output-simple-1-pe.png
title: 'Select the output type as "Time series". Set a name to the variable that will store the calculation result. Optionally, specify the number of decimal places.'
1:
image: /images/user-guide/calculated-fields/output-simple-2-pe.png
title: 'Select the output type as "Attribute" and choose its scope: "Server attributes", "Client attributes", or "Shared attributes". Set a name to the variable that will store the calculation result. Optionally, set the number of decimal places.'

expression-script-calculated-fields-1:
0:
image: /images/user-guide/calculated-fields/expression-script-calculated-fields-1-pe.png
title: 'Define a function that will perform calculations using the variables defined in the "Arguments" section. The variable name that will store the calculation result is defined within the function itself.'

output-script-1:
0:
image: /images/user-guide/calculated-fields/output-script-1-pe.png
title: 'Time series: function must return a JSON object or array with or without a timestamp containing the computed value.'
1:
image: /images/user-guide/calculated-fields/output-script-2-pe.png
title: 'Attribute: function must return a JSON object without timestamp information containing the computed value.'

calculated-field-result:
0:
image: /images/user-guide/calculated-fields/calculated-field-result-1-pe.png
Expand Down Expand Up @@ -238,4 +212,4 @@ example-script-calculated-fields-3:

{% assign docsPrefix = "paas/" %}
{% include get-hosts-name.html docsPrefix=docsPrefix %}
{% include docs/user-guide/calculated-fields.md %}
{% include docs/user-guide/calculated-fields/index.md %}
Loading