13 Replies Latest reply on Mar 16, 2015 3:52 AM by punya.sahoo

    How to Create a Timer Attribute

    punya.sahoo

      Hi,

       

      I would like to make a attribute which will act like Timer and the Timer should start and stop depending on another attribute value.

      So if another attribute value goes to 1 then the timer should start and when it goes to 0, the timer should stop.

       

       

      Thanks

      Punya

        • Re: How to Create a Timer Attribute
          xwang

          Hi Punya,

           

          From your description, may I have a quetion that how you will use the attribute --- Timer please?

           

          Why I ask this is that if you using an attribute to store a timestamp, it will only show the time at the stopped point.

           

          I believe you might wish to use the timerange for the future, is that right please?  If so, PI Event Frame is the good function for this goal.  If my guess is right, let us discuss something for PI Event Frame.  If not, could you please explain more about which timestamp you will store in the attribute please?  Many thanks.

           

          Xi Wang

          PI Developer Club

          • Re: How to Create a Timer Attribute
            André Åsheim

            My first thought is to create a timeGE calculations

            IF('Attribute'>0) then TimeGE('Attribute','t','*') else 0
            

            But this have some limitations, it will include all the times the value has been above 0 today.

            It's also possible to achieve this using event frames, but then you can't output the value to a attribute in that element

             

            You can also try this:

            LastStop output to attribute "Last Stop" (Date Time)

            LastStart output to attribute "Last Start" (Date Time)

            Output output to attribute "Timer" (Double, UOM: Seconds)

            LastStop: If('Attribute1'<50)then ParseTime("*") else NoOutput()
            LastStart: FindGE('Attribute1','Last stop','*',50)
            Output: if('Attribute1'>50) then TimeGE('Attribute1','Last start','*',50) else 0
            

            Attibutes.PNG

            Analyse.PNG

              • Re: How to Create a Timer Attribute
                Karl.Hodgkiss

                And I'm guessing you could put another attribute on top of the "Timer" to give a cumulative value over a given time period?

                E.G. How would I create a running average PI totalizer tag triggered by an event?

                .

                  • Re: How to Create a Timer Attribute
                    André Åsheim

                    Yes, you can for example add a new calculation or just use the same calculation as in my first example:

                    TimeGE('Attribute','t','*',0)

                    This gives you the time (in seconds) that the attribute/tag has been greater than 0 today (or specify different start time, for example TimeGE('Attribute','*-7d','*',0) for the last 7 days)

                      • Re: How to Create a Timer Attribute
                        punya.sahoo

                        Hello,

                         

                        Actually what my requirement is :

                         

                        Suppose I have a interface status which I am monitoring on processbook that if it good or bad.

                        So I want to use a timer near to it which will tell me if the interface status is bad then the timer will start and it will tell me how long this status stays at bad.

                         

                        Thanks

                        Punya

                          • Re: How to Create a Timer Attribute
                            Karl.Hodgkiss

                            If I was using a PE it would look something like this:

                             

                            CALC1: IF 'InterfaceStatus' = "Bad" AND 'InterfaceStatus' <> PrevVal('InterfaceStatus', PrevEvent('InterfaceStatus','*+1h')) THEN 1 ELSE NoOutput()

                            Checks current value is bad and previous value (based on timestamp from current value) was good to set a marker.

                            CALC2: IF 'InterfaceStatus' = "Bad" THEN TimeEQ('CALC1',PrevEvent('CALC1','*+1h'),'*',1) ELSE 0

                            Uses above marker to calculate time in seconds since it was activated.

                             

                            Above isn't tested but I have something similar running. Of course the IF could be altered to look for BadVal('InterfaceStatus') etc and you can add time conversions but that's the basics. Should also be easy enough to use in AF.

                            .

                            • Re: How to Create a Timer Attribute
                              André Åsheim

                              You can use the same logic on that aswell, if you know what value it has when its bad you can just use TimeEQ instead of timeGE.

                              I've done something similar on a customers envirnoment but there I only take the time difference between NOW and the timestamp on the last value from the interface. Like this:

                              INT(ParseTime("*")-PrevEvent('Attribute1','*'))


                                • Re: How to Create a Timer Attribute
                                  Karl.Hodgkiss

                                  Just have to ensure you don't get any new "Bad" events with that

                                  .

                                    • Re: How to Create a Timer Attribute
                                      André Åsheim

                                      Yes, this is not a good way to detect "BAD" values, this is to detect if there are no values

                                        • Re: How to Create a Timer Attribute
                                          dng

                                          Great suggestions!

                                           

                                          Punya, if you decided to use PrevEvent/PrevVal, etc. in PI Analytics to calculate the timer, make sure to note that the Analysis service looks at the data cache in order to do calculations. The AF data cache signs up for updates on the PI server, and therefore will contain all snapshot values from the PI server. Even when the events were compressed out of the PI archive, they still reside on the AF Data Cache. E.g. If you were trying to determine the timestamp of the last bad value using PrevEvent(...) and you have repeated bad values coming in. Even if the values might be compressed out on the PI server, as long as they come in as new snapshots, they will still show up in the AF Data Cache. (This behavior is different from performance equations, which looks at archived values for these calculations.) Depending on the exception and compression settings on your interface status tag, you might want to keep that in mind.

                                            • Re: How to Create a Timer Attribute
                                              skwan

                                              The next AF release has a new function to accomplish this.  It's currently scheduled for Q2 2015.


                                              In general, it's not advisable to writing outputs of a scheduled analysis to a static AF attribute.  There are numerous reasons not to do this.  The analysis is evaluating and writing writing to the AF database but you don't have history of the output and if the user is using PSE to view the output, you need to hit refresh.  Meanwhile all the outputs are basically lost and you're causing a lot of load on the AF Server.


                                              The next release will allow adhoc (unscheduled) analyses, which will evaluate on demand.


                                              --

                                              Steve Kwan

                                              AF Product Manager


                                      • Re: How to Create a Timer Attribute
                                        gregor

                                        Hello Punya,

                                         

                                        Do you consider one of the provided answers / suggestions a sufficient solution for what you were looking for?

                                        If so, can you please mark the right answer as "Correct Answer?" If not, please let us know if you have more questions or what you did to solve your problem.