AnsweredAssumed Answered

PI AF Counter and Time on State

Question asked by deitosrafael on Feb 27, 2018
Latest reply on Dec 17, 2018 by LalBabuShaik

Hi folks,


I'm using AF (PSE 2017) and want to extract two measures of an element as follows:

1. Count the number of times an attribute is equal to an specific value, over a period of time;

2. Ge the amount of time the attribute value was equal to an specific value, over a period of time (any base, preferably seconds);


The specifics are as follows:

a) The element has 2 attributes (i.e., ATTRIBUTE_1 and ATTRIBUTE_2) that are used to compute/extract the STATE according to the calculation:


( StateNo('ATTRIBUTE_1') = 0 and StateNo('ATTRIBUTE_2') = 1 and ( StateNo(PrevVal('ATTRIBUTE_1','*')) <> 0 or StateNo(PrevVal('ATTRIBUTE_2','*')) <> 1))


When this calculation returns TRUE, the STATE is activated.

b) ATRIBUTE_1 and ATRIBUTE_2 are tags from PI Server;

c) The calculation that define the STATE is "Event Triggered" (on any of the underlying attributes);

d) The calculation that would sum the time is/could be "Time Triggered", once a day, for example.


Solutions I've tried:


a) Creating an analyses with the expression above setting the result as 1 or 0. This way, I can use TimeEq(...) to extract measure number 2.

Problem: I was not able to correctly count (tried using EventCount(...)) since it's possible that any of the attributes change state but the result of the expression does not, thus generating entries on archive that are equal to the last state, for example. This way, the number of events will always be equal or greater to the number I expect.


b) Creating an analyses with the expression above setting the result as 1 or NoOutput(). With this solution I can use EventCount(...) to extract measure number 1.

Problem: I was not able to correctly get the time since TimeEq(...) requires tag with complete history (cannot use NoOutput()).


c) Creating event frames for the STATE. With this solution, using PI SQL Commander, I was able to extract measure number 1 (counting the number of events) and part of measure number 2 (sum of duration of events).

Problem: I was not able to compute the time at the limits of the period of interest. Assume I'm searching events on any given period of time, as depicted on the line bellow (from point B to F). In such time period (B to F), there was one complete event on archive (from point D to E). But let's say there was another event from point A to C, which means it started before the start of the period of analysis (B) and ended after (C). The question is: how to I measure the time of interest, which is this case, for the analyses period of B to F is equal to [(B->C)+(D->E)]?


Time goes from A to F:



I hope there is a simple/better solution for such naive problems: (1) counter when state is equal to value, (2) amount of time in state.


Hope to hear from you guys.


Thanks in advance,

Rafael D.