2 Replies Latest reply on Dec 17, 2018 2:34 PM by Lal_Babu_Shaik

    PI AF Counter and Time on State


      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.

        • Re: PI AF Counter and Time on State

          I am experimenting with virtually the same use case. I have a process circuit whose state is defined in one of Down, Idle, Maintenance, Trouble, and Running. Ideally I would like to see a dynamic percentage of time that the circuit was in each state over a given period of time, that could be explored in PI Vision.


          I feel that this is probably native in Power BI, but it's not as easy within AF unless you do a TimeEq, which requires saved output history. This also isn't really dynamic, you have to set the time of evaluation in the analysis. Or, maybe do small pieces and then sum the results in a client tool such as Datalink or some other method. And it isn't really possible in a PI Point data reference, since these are configured for min, max, total. Event frames might have some utility, that's what I'm experimenting with now.

          • Re: PI AF Counter and Time on State

            Hi Rafael


            Request you to check below procedure


            Step 1 : Create two tags one counter(Integer) and another timecounter(To count number of sec).

            Step 2: Initialise both tags to zero.

            Step 3: Check the current value for every update .i.e. Check Current event with previous event value. If condition evaluates to true then update counters in step 4 and 5 else NoOutput


            e.g. If (PrevVal('Attribute1','*'))="Alarm" and (PrevVal('Attribute1',(PreEvent('Attribute1','*'))))<>"Alarm"


            Step 4: Increment the counter counter:=Counter+1 --> (Output to PI Point)


            Step 5 : timecounter:= Int(PrevEvent('Attribute1',(PreEvent('Attribute1','*'))) - PrevEvent('Attribute1','*')) --> (output to timecounter tag in seconds)


            Reset the counters whenever required.


            Hope this helps.