11 Replies Latest reply on Jul 24, 2013 3:18 PM by mhamel

    Analysis Rule Or Simple GetValues

    Ashok_NK

      Hi

       

      I have the following scenarios:

       

      "Alert when x falls below 50% of target value in 5 minutes"
      "Alert when x falls below 10% of target value in 1 hour"
      "Alert when x exceeds target value"

       

      How can I achieve this using the PI AF API:
      1. A time weighted query? Run it every few minutes? Sample/Link?
      2. Analysis Rules?

       

      Note: There's no requirement to actually provide a notification - though, maybe in the future. This is just for the purposes of a dashboard style display. 

       

      Regards

        • Re: Analysis Rule Or Simple GetValues
          mhalhead

          This logic could be handled in a number of ways; personally I won't go down the Analysis Rule road. It should be noted that the Analysis Rules are not officially exposed; Abacus will be the future path for configured analytics. I view the current analysis rules as legacy support for Sigma Fine.

           

          With the limited information I would look at using PI Notifications (PINS). Bear in mind that PINS does not imply that you are alerting a person; you can just as easily send notifications to another process (web services are support out of the box). If PINS isn't an option then what about good old ACE; you can easily write an ACE module to do the above logic. Using the AF Link you can use the AF elements in the ACE configuration.

           

          One limitation to be aware of is that you can only trigger ACE and PINS of a PI Point; you can't use a calculation/formula to trigger them. In this case you need to use a periodic time rule.

            • Re: Analysis Rule Or Simple GetValues
              Ashok_NK

              Hi

               

              Thanks for your help, I'm fairly new to the PI platform and am not really familiar with ACE/PINS, or your reference to "periodic time rule" :(

               

              Allow me to provide a little more information. I'll be building a component on .NET 4 using the PI AF SDK 2.5. For the most part just getting attribute values and displaying trends.

               

              In regard to the scenarios:

               

              "Alert when x falls below 50% of target value in 5 minutes"

               

              This translates to:

               

              For an AFAttribute "x", when the value falls below 50% of a preconfigured target value over a continuous time block of 5 minutes, for a day duration - log it.

               

              If I can rephrase my questions:

               

              1. Is there any PI AF SDK / API I can leverage for the scheduling/monitoring of the attribute?

               

              2. If not, If I have my own scheduling logic, could I determine the above through a query. Could I get some sample code that does that for a given AF Attribute.

               

              Thanks

                • Re: Analysis Rule Or Simple GetValues
                  mhamel

                  @Ashok: What you describe requires an analytic scheduler such as PI Notifications, Abacus or a custom one.

                   

                  This can be handled by PI Notifications as it provides the scheduler engine and all the analytical tools you need to perform the type of query you are looking; you are not forced to subscribe to it and send output. You can query the notification instances collection to fill your dashboard display.

                   

                  You will need to create an attribute (probably with a Formula DR) that will contain the rule for 50% of target. This attribute would be used in the comparison rule of notification with a Time True condition. You can also combine (AND) your rules to create the alert you want with different states or the same. Remember that the rules are evaluated in the order of appearance in the collection, so place the one to execute first at the top.

                   

                  Regarding the time rule, I would opt out for a periodic time rule to insure a "regular" validation of your conditions otherwise with a natural time rule it may be delayed when a new value is pushed in the pipeline.

                   

                  To answer the question on the Analysis Rules side, those are used by a scheduler such as PI Notifications to create the conditions to validate (type, time, state, operation, etc.). It is possible to create your own if you really need but many cases are already covered with the current ones.

                   

                  I hope this helps!

                    • Re: Analysis Rule Or Simple GetValues

                      Hello Ashok,

                       

                      Please accept my apology. It's not my intention to confuse you but to me what you describe looks like a classic use case for PI Alarm Subsystem. I hence recommend looking at the chapter about it at PI Server Applications User Guide. The PI AlarmView client user manual can be found at Technical Support Download Center.

                        • Re: Analysis Rule Or Simple GetValues

                          As far as doing this within your own scheduler, something like this should work...

                           

                           

                           
                          string expression = "TagMin('sinusoid','*-5m','*') < ('sinusoid_target' * 0.5)";
                          bool alert = (OSIsoft.AF.Data.AFCalculation.CalculateAtTimes((OSIsoft.AF.PI.PIServer)srv, expression, new List<AFTime>(){ new AFTime("*") }).Count<AFValue>(e => e.Value.Equals((Single)1.0)) > 0);
                          

                           

                            • Re: Analysis Rule Or Simple GetValues
                              Ashok_NK

                              Hi Rhys

                               

                              Thanks for providing that query - is that approach using Performance Equation syntax equivalent to using the following API:

                               

                               

                               
                                var afTimeRange = /* One Day - From Midnight To Now */
                              
                                var afTimeSpan = new AFTimeSpan(TimeSpan.FromMinutes(5.0));
                              
                                             string expression = @"'\\Path\To\Element|Flow Rate'";
                                              var summaries = AFCalculation.CalculateSummaries(server, expression, afTimeRange, afTimeSpan, AFSummaryTypes.Average, AFCalculationBasis.TimeWeighted, AFSampleType.ExpressionRecordedValues, AFTimeSpan.Zero, AFTimestampCalculation.Auto);
                                              var average = summaries[AFSummaryTypes.Average];
                                              bool alert = average.Any(x => (Single)x.Value < (0.5 * myTarget));
                              

                              The crux of it is ensuring it evaluates for continuous 5 minutes rather than chunks/even distribution of 5 minute intervals (which I believe to be controlled by this param:  AFSampleType.ExpressionRecordedValues)

                               

                              Thanks

                                • Re: Analysis Rule Or Simple GetValues

                                  Ashok Krishnan

                                  The crux of it is ensuring it evaluates for continuous 5 minutes rather than chunks/even distribution of 5 minute intervals (which I believe to be controlled by this param:  AFSampleType.ExpressionRecordedValues)

                                   

                                  Thanks

                                   

                                  Timestamps used in the PE are relative so it will evaluate the 5 minute period from when you send the expression to be evaluated by the PI Server. It you continuously send it to be evaluated then it will be continuous. If for example you have a break in your continuous scheduler then you will have to supply more timestamps for it to be evaluated for those gaps, e.g. *-1s, *-2s, *-3s, ... but it probably needs testing for efficiency.

                                   

                                  Your method looks equivalent, but I don't know which code path is more efficient between CalculateSummaries vs CalculateAtTimes.

                              • Re: Analysis Rule Or Simple GetValues
                                Ashok_NK

                                Thanks for the references @Mathieu and @Gregor.

                                 

                                @Mathieu

                                 

                                From a programmability perspective, PI Notifications corresponds to AFNotification? If I understand correctly:

                                 

                                It's likely I could use existing analysis rules to achieve what I need, and set up a notification over the top. Would it be possible to provide a code sample targeted at my sample. I've referred to this guide but am a little confused about passing input and output parameters.

                                 

                                vcampus.osisoft.com/.../Library.aspx

                                 

                                @Gregor &

                                 

                                On Alarming - If I set up alarms... is there any API for working with those alarms?

                                 

                                Does alarming support pulling in external data (e.g. data ref attributes)?

                                  • Re: Analysis Rule Or Simple GetValues

                                    Hello Ashok,

                                     

                                    PI Alarm Subsystem services tags of data type Digital with point source @.

                                     

                                    Ashok Krishnan

                                    is there any API for working with those alarms?

                                     

                                    You can use any Data Access method (PI SDK, PI OLEDB, AF SDK ...) to retrieve data from Alarm tags.  

                                     

                                    Ashok Krishnan

                                    Does alarming support pulling in external data (e.g. data ref attributes)?

                                     

                                    If this question refers to element attributes in PI AF (PI Asset Framework) the answer is no or at least not directly. As described in PI Server Applications User Guide there are certain tests that are specified with an alarm tags configuration but even a tags configuration can be changed, I consider them fixed. The good news is that you can use other calculation engines to treat your raw data as long as the data is stored with PI tags. Those other calculation engines are PI Totalizer Subsystem, PI Performance Equation Scheduler (PE) and PI Advanced Computing Engine (PI ACE). Totalizer and Performance Equation Scheduler are as well described in the PI Server Applications User Guide. PI ACE has it's own documentation.

                                     

                                    I like to avoid to confuse you with a too extensive answer but if you have additional questions, please don't hesitate to ask.

                                     

                                    For the use cases you described, I would first look at the capabilities of PI Alarm Subsystem. In case you require more flexibility I suggest looking into Performance Equations. The Performance Equation Reference Manual (%PIHOME%\Help\PEReference.chm) has detailed descriptions of all available functions. If you don't plan to use PI AlarmView client, you may prefer evaluating alerts in PE or ACE directly. As a final side note, please try to avoid using string data types but consider using Digital data type. Within custom Digital State sets you can specify state strings to be used with digital tags.

                                    • Re: Analysis Rule Or Simple GetValues
                                      mhamel

                                      @Ashok: PI Notifications has a "leg" within the AF SDK (OSIsoft.AF.Notification namespace) and another in the AN SDK (OSIsoft.AN et al. namespaces). The former one is related to configuration for the generation of notification events, the latter is to handle the manipulation of notification concepts (delivery channel, notification instance, notification event, contact, ect.).

                                       

                                      I would suggest taking a look at the Create a Notification Rule section in the PI Notifications Programmers’ Guide that you can find within the Library.