AnsweredAssumed Answered

What is the most efficient way to use the summary function for a list of tags and time ranges.

Question asked by mvisconte on Sep 6, 2018
Latest reply on Sep 6, 2018 by mvisconte

I use AF-SDK to retrieve history for a list of HistorianValues, defined as:

 

public class HistorianValue
{
    public DateTime BeginTime { get; }
    public DateTime EndTime { get; }
    public string Name { get; }
}

 

The aim is to get, for each item in the list, the average of the tag 'Name' between BeginTime and EndTime.

The historian server is on a different continent than the server running this code, therefore, round-trip-times are huge, and I am trying to optimize the code.

 

For the time being, I grouping the tags by time range, and call PIPointList.Summary for each time range, but that can amount for a good amount of calls. (Grouping by tag name is usually worse, as there is more different tag names than different time ranges).

 

 PIPagingConfiguration config = new PIPagingConfiguration(PIPageType.TagCount, 100);

var groupsOfSameTimeRange = tagList.GroupBy(t => new { t.BeginTime, t.EndTime });

foreach (var groupOfSameTimeRange in groupsOfSameTimeRange)
    {
        AFTime AFBeginTime = new AFTime(groupOfSameTimeRange.Key.BeginTime);
        AFTime AFEndTime = new AFTime(groupOfSameTimeRange.Key.EndTime);

        AFTimeRange oAFTimeRange = new AFTimeRange() { StartTime = AFBeginTime, EndTime = AFEndTime };

        PIPointList PIPointList = new PIPointList(PIPoint.FindPIPoints(PIServer, groupOfSameTimeRange.Select(t => t.Name)));

        IEnumerable<IDictionary<AFSummaryTypes, AFValue>> PIAggregates = PIPointList.Summary(oAFTimeRange,  AFSummaryTypes.Average, AFCalculationBasis.TimeWeightedDiscrete, AFTimestampCalculation.Auto, config);

       //Put the values in the return object
    }

 

Is there any way to optimize this further, and, ideally, get the data for all (tags,range) couple in a single call?

 

Thank you for your help.

Outcomes