Special tags
In addition to @tagName and @metadataName, the following values are available for live KPIs formulas.
@@PreviousValue(@tagName)
Indicates the previous value of the tag.
Example:
@temperature – @@PreviousValue(@temperature);
– 2022-12-31 09:00:00: temperature 19.6°
– 2022-12-31 09:05:00: temperature 20.1°
When the KPI calculation runs at 9:05, @temperature is 20.1 and @@PreviousValue(@temperature) is 19.6, and therefore the KPI is 0.5.
NOTE: if one of the tag of the formula wasn’t updated from the field, when calculating a KPI, its @@PreviousValue remains the same @@PreviousValue used for the previous KPI calculation. By the way, please see also @@TagUpdate(tagName), in order to properly achieve the desired output.
Example:
(@t1 – @@PreviousValue(@t1)) + (@t2 – @@PreviousValue(@t2);
Data points coming from the field are the following:
- 2022-12-31 09:00:00: t1 = 10, t2 = 11
- 2022-12-31 09:05:00: t1 = 12, t2 = 14
The KPI calculation is the following:
(12 – 10) + (14 – 11) - 2022-12-31 09:05:00: t1 = 15, t2 wasn’t collected
The KPI calculation is the following:
(15 – 12) + (14 – 11)
You see how @@PreviousValue(@t2) is still 11.
@@PreviousTS_UTC(@tagName)
@@PreviousTS_local(@tagName)
They represent the timestamp of the previous tag data point, in UTC and in the plant’s timezone, respectively.
Example with a plant with a timezone in Italian time:
– 2022-12-31 09:00:00 Italian time: temperature 19.6°
– 2022-12-31 09:05:00 Italian time: temperature 20.1°
When the 9:05 calculation runs:
@@PreviousTS_UTC value is ‘2022-12-31 08:00:00’
@@PreviousTS_local value is ‘2022-12-31 09:00:00’
@@TagUpdated(@tagName)
Indicates whether, compared to the previous KPI calculation, a new sample has arrived for the @tagName tag or not.
NOTE: TagUpdated doesn’t make any evaluation whether the values has changed or not; if a new sample has arrived with the same value as the previous one, @@TagUpdated(@tagName) would still be 1.
@@TagUpdated(@tagName) value is therefore set as follows:
- 0: No new samples have arrived for the tag, compared to the previous KPI calculation.
- 1: A new sample has arrived for the tag, compared to the previous KPI calculation.
Example.
I have two flow rates whose value, in normal conditions, is constantly changing, and I want to implement the following logic:if two consecutive data points have the same value, it means that something is wrong, and therefore I have to send an alert.
However, I must consider that it’s possible that, for certain timestamps, only one of the two tags is collected from the field, and in this case, the tag that wasn’t collected didn’t change value of course, but I must not consider it as an alert.
I then calculate a digital KPI this way:
/*
NOTE: a Rilheva alert is bound to this KPI, so that when the KPI triggers to 1, it’s sending an email, a SMS and a VoIP call to the on-call personnel.
*/
CASE
WHEN @@TagUpdated(@flow1) = 1
AND (@flow1 – @@PreviousValue(@flow1) = 0)
THEN 1 – alert!!!
WHEN @@TagUpdated(@flow2) = 1
AND (@flow2 – @@PreviousValue(@flow2) = 0)
THEN 1 – alert!!!
ELSE 0 – everything is fine
END;
Directives
The directives available are: @@SKIP_WHEN_NULL and @@RECALCULATE_FROM (see the “Common directives between Live KPIs and Periodic KPIs” section).
Custom functions
In live KPIs it is possible to use the following custom Rilheva functions, in addition to all the functions available in Transact SQL language.
stats.ema(arg0, α)
Exponential moving average
The arguments are:
- arg0: it can be a simple variable, or even a formula directly calculable in Transact SQL
- α: decay factor (smoothing factor). The higher the decay factor, the lower is the weight given to older data.
Example:
stats.ema(@temperature – 32) × 5/9, 0.8)
The moving average of the formula “@temperature – 32) × 5/9” is calculated with a decay factor of 0.8.
stats.slope(arg0, run_um)
Returns the slope between the T-1 value and the current value, i.e. the absolute increase/decrease per unit of measurement over time.
The arguments are:
- arg0: it can be a simple variable, or even a formula directly calculable in Transact SQL.
- run_um: unit of measurement of time to calculate the slope.
It can be: SECOND, MINUTE, HOUR, DAY
Example:
stats.slope(@temperature, MINUTE)
– 2022-12-31 09:00:00: temperature: 18.0
– 2022-12-31 09:05:00: temperature: 20.5
The 9:05 KPI calculates the slope per minute compared to the previous data. In this case the temperature increased by 2.5 in 5 minutes, and therefore the KPI is 0.5.
Was this helpful?
0 / 0