Displaying Duration of specific events as a separate tag
Sometimes a specific duration of events is of interest and it is necessary to display the duration of a specific event as a new tag in the focus diagram.
Here are 3 ways to display the duration of an event as a new tag:
Create a Tag Builder Formula that is equal to 0 at the start of the event and equal to 1 at the end of the event.
Formula:
if(and(a="ACTIVE", b="INACTIVE"), 0, if(and(a="INACTIVE", b="ACTIVE "), 1, sqrt(-1)))
Variable mapping:
a = discrete/ string tag (no shift);
b = discrete/ string tag (shift: 1s)
The slope of the resulting tag from step 1 is inversely proportional to the duration of the event. Calculate the slope of the previous formula tag can be converted to minutes/or hours/or days by multiplying the slope by a factor.
Formula [Minutes]: if((a-b)&0, (1/(a-b)/60), 0)
Formula [Hours]: if((a-b)&0, (1/(a-b)/3600), 0)
Formula [Days]: if((a-b)&0, (1/(a-b)/ 86400), 0)
In this example the goal is to show the duration when the level is between 10 and 30.
Create a formula tag that is equal to 0 at the start of the event and equal to 1 at the end of the event.
Formula:
if(and(LEVEL_now>10, LEVEL_before<10), 0, if(and(LEVEL_now>30, LEVEL_before<30), 1, sqrt(-1)))
Variable mapping:
LEVEL_now = analog level tag (no shift);
LEVEL_before = analog level tag (shift: 1min)
The slope of the resulting tag from step 1 is inversely proportional to the duration of the event. Calculate the slope of the previous formula tag can be converted to minutes/or hours/or days by multiplying the slope by a factor.
Formula [Minutes]: if((a-b)&0, (1/(a-b)/60), 0)
Formula [Hours]: if((a-b)&0, (1/(a-b)/3600), 0)
Formula [Days]: if((a-b)&0, (1/(a-b)/86400), 0)
Variable mapping:
a = analog level tag (no shift);
b = analog level tag (shift: 1s)
Create a new Formula tag that shows the value of 1440 (minutes per day) if the event of interest occurs.
Formula: if(a="PHASE2",1440,0)-b*0
Variable mapping:
a = discrete/ string tag (no shift);
b = any analog tag (shift: 1s)
Here we use the following trick:
https://userguide.trendminer.com/en/74136-stepped-formula-tags.html
Create an Aggregation tag that calculates the integral over a given moving window (choose this larger than your maximum expected duration).
Operator: Integral
Tag unit is 'Per day' Tag unit is 'Per day'
Direction: 'Central'.
Aggregate per: It is important to identify the most suitable aggregation window for this situation. If the chosen method is too lengthy, it could potentially overlap with another timeframe when the event of interest occurs. Please be mindful of this consideration.
The aggregations max value equals the duration of the event of interest.The aggregations max value equals the duration of the event of interest.
Tip
The duration value is ±1 minute inaccurate due to indexing.