2 Replies Latest reply on Sep 19, 2011 7:25 PM by Bannikov

    AFDataReference.GetValue inputValues versus inputAttributes

    Bannikov

      Hello !

       

      We've developed some AF Data Reference Plug-Ins and now I'm a bit curiously about two parameters in .GetValue call. These are two parameters - inputAttributes and inputValues. Maybe someone can explain -- in which cases should I use inputAttributes (and make subsequent calls to each AFAttribute.GetValue) or I can simply use inputValues. Please note that we heavly use not only AFTime context, but also AFTimeRange context - primary for reporting and for PI Table representaion using PI OLEDB Enterprise.

       

      My primary question is -- how inputValue is filled? Is requested timeContext applied to these values before GetValue is called?

       

      One more question -- how standard AFDataReference.GetValues method is implemented? In which cases should I use it, and in which cases override it?

       

       

       

       

        • Re: AFDataReference.GetValue inputValues versus inputAttributes
          cmanhard

          A data reference which is going to consume other attribute's should implement GetInputs.  The return from this call is a list of attributes for which your Data Reference needs values.  The AFSDK will then supply you these values in your GetValue call which will mean that you will not need to make the call yourself.  By doing this, the AFSDK can much more efficiently bulk-up calls to the PI Server.  The inputAttributes parameter you receive in GetValue will just be a reference to the same collection you returned in GetInputs.  The inputValues is a parallel collection of their values.

           

          Note that typically for DRs that compute their values from other attributes, you should implement SupportedContexts method and return AFDataReferenceContext.All.

           

          The standard implementation of GetValues uses the input list to determine the times when your DR GetValue implementation should be invoked.  You may use it if your DR is calculation based DR and supplies the list of inputs it needs in GetInputs.  Otherwise, if you are accessing an external historical data provider, or cannot provide an input list for some reason, then you will need to provide your own implementation.

            • Re: AFDataReference.GetValue inputValues versus inputAttributes
              Bannikov

              Thank you for clarification. My DR (one of them) is a variation about Rollup sample in White Paper. My DR scans all children of owning element and calculates average (min, max, total) value from specified attribute. DR should support both AFTime and AFTimeRange time context. My current implementation is like this. I hope that it's correct.

               

               

               
                  Public Overrides Function GetValue(ByVal context As Object, ByVal timeContext As Object, ByVal inputAttributes As AFAttributeList, ByVal inputValues As AFValues) As AFValue
                      Dim total As Double = Double.NaN
                      Dim count As Integer = 0
              
                      For Each afv As AFValue In inputValues
                          Dim val As Double
                          If afv.IsGood AndAlso afv.Value IsNot Nothing AndAlso Double.TryParse(afv.Value.ToString, val) Then
                            
                              Select Case Operation.ToLower
                                  Case "min"
                                      If Double.IsNaN(total) Then
                                          total = val
                                      Else
                                          total = Math.Min(total, val)
                                      End If
              
                                  Case "max"
                                      If Double.IsNaN(total) Then
                                          total = val
                                      Else
                                          total = Math.Max(total, val)
                                      End If
              
                                  Case "avg"
                                      If Double.IsNaN(total) Then
                                          total = val
                                      Else
                                          total = total + val
                                      End If
                                      count = count + 1
              
                                  Case "sum"
                                      If Double.IsNaN(total) Then
                                          total = val
                                      Else
                                          total = total + val
                                      End If
              
                                  Case Else
                                      Return New AFValue(0, Attribute.DefaultUOM)
                              End Select
                          End If
              
                      Next
              
                      If Operation.ToLower = "avg" Then total = total / count
              
                      If Double.IsNaN(total) Then total = 0
              
                      Return New AFValue(total, Attribute.DefaultUOM)
                  End Function