advice on optimizing pulling values over a time range for attributes from bulk loaded partial elements

Discussion created by mstephenson on Jun 24, 2014
Latest reply on Jul 1, 2014 by jking

We are looking to optimize getting attribute values (over a time span, at a regular interval) for a subset of attributes belong to elements of the same element template.


Currently we do this by bulk loading the elements (partial loading of only attributes needed) then calling AFAttribute.GetValues(timeRange, numberOfValues, desiredUOM) per element, per attribute.This does not seem the most performance optimized approach. We are using AF SDK Version and .NET v4.0.30319


Is there a better way to accomplish this?


My first guess was to do it per element and have one values call for all loaded attributes via AFAttributeList.GetValue(timeRange). This works for single point in time strategy. However there is no parameter for numberOfValues when calling for a timeRange so this would not seem to work directly.


For reference: Below is an partial example of our current approach.

            Dim adjustedStartTime As DateTime = criteria.Range.StartTime

            Dim elementTemplate As AFElementTemplate = Me.Repository.ElementTemplates("Site")
            Dim queriedElements As AFNamedCollectionList(Of AFElement)
            Dim queriedAttributes As New AFNamedCollectionList(Of AFAttributeTemplate)
            Dim pageStart As Integer = 0
            Dim elementCount As Integer

            Dim tr As New OSIsoft.AF.Time.AFTimeRange
            tr.StartTime = adjustedStartTime.ToLocalTime
            tr.EndTime = criteria.Range.EndTime.ToLocalTime

            Dim tsInterval As String = "-1h"
            Select Case criteria.Interval
                Case DateInterval.Year : tsInterval = "-1y"
                Case DateInterval.Month : tsInterval = "-1M"
                Case DateInterval.Day : tsInterval = "-1d"
                Case DateInterval.Hour : tsInterval = "-1h"
                Case Else : tsInterval = "-1h"
            End Select
            Dim ts As Time.AFTimeSpan = Time.AFTimeSpan.Parse(tsInterval)
            'this function is not shown for brevity, for this example assume it loads the attribute templates for "Demand", "Rate", and "Consumption"
            Me.AddUtilitiesAttributeTemplates(queriedAttributes, elementTemplate, criteria.Range.ConsumptionInterval, BandsInclusion.ExcludeBands)

                queriedElements = AFElement.FindElements(Me.Repository, Nothing, Me.Settings.Root,
                                                            AFSearchField.Name, False, AFSortField.Name, AFSortOrder.Ascending,
                                                            pageStart, Me.Settings.BatchLoadPageSize,
                If (queriedElements Is Nothing) Then
                    Exit Do
                End If
                AFElement.LoadAttributes(queriedElements, queriedAttributes)

                For Each element In queriedElements
                    'not setting results of these calls for brevity, in full function they are fed to DTOs
                    element.Attributes("Demand").GetValues(tr, -ts.GetIntervalTimes(tr).Count, Nothing)
                    element.Attributes("Rate").GetValues(tr, -ts.GetIntervalTimes(tr).Count, Nothing)
                    element.Attributes("Consumption").GetValues(tr, -ts.GetIntervalTimes(tr).Count, Nothing)
                pageStart += Me.Settings.BatchLoadPageSize
            Loop While (pageStart < elementCount)