5 Replies Latest reply on Jun 12, 2017 10:04 AM by gregor

    Is there a better way to get multiple values Uisng AFSummaryTypes


      Is there a better way to get the Start and End value along with Summary( AFSummaryTypes.Maximum | AFSummaryTypes.Minimum | AFSummaryTypes.Average) ? I have to call InterpolatedValue two times to get both Initial and final readings! please help.

      below is my sample code.

                           var summarizedvals = pivalue.Result.Summary(new AFTimeRange("00:00", "01:00"), AFSummaryTypes.Maximum | AFSummaryTypes.Minimum | AFSummaryTypes.Average, AFCalculationBasis.EventWeighted, AFTimestampCalculation.Auto);                       


                              //this can be eliminated  if i get  the values using summarizedvals itself

                                var initialVal = pivalue.Result.InterpolatedValue(new AFTime("00:00"));// pivalue.Result.RecordedValue(new AFTime("00:00"), AFRetrievalMode.Exact);

                               var finalVal = pivalue.Result.InterpolatedValue(new AFTime("01:00"));//pivalue.Result.RecordedValue(new AFTime("20:00"), AFRetrievalMode.Exact);

                              Console.WriteLine("Initial: " + initialVal.Value);

                              Console.WriteLine("Final: " + finalVal.Value);


                              Console.WriteLine("Average: " + summarizedvals[AFSummaryTypes.Average].Value);

                              Console.WriteLine("Max: " + summarizedvals[AFSummaryTypes.Maximum].Value);

                              Console.WriteLine("Min: " + summarizedvals[AFSummaryTypes.Minimum].Value);



      Thanks in advance.

        • Re: Is there a better way to get multiple values Uisng AFSummaryTypes
          Rick Davin

          Hi Goldy,


          You're asking for 2 entirely different things though, right?  One of those things is summarized data over a time range, and the other thing are values at specific points in time.  You'll need to have one call for the apples and totally different call for the oranges.


          If you already had the AFValues across the time range in memory, you could get by with the AFValues.Summary call but I would only recommend this IF the values are already in memory.  Otherwise you would be worse off if you tried to do this just for the sake of making one RPC to the server.


          You're actually making 3 RPC's.  The first is for the summary, the second is for the interpolated value at the start time, and the third is for the interpolated value at the end time.  You could get the interpolated values in one call using AFData.InterpolatedValuesAtTimes.


          For completeness of the answer, there are also async versions of Summary and InterpolatedValuesAtTimes so you could send both requests concurrently.

          • Re: Is there a better way to get multiple values Uisng AFSummaryTypes

            Thanks Rick for suggesting few options.


            1) I was trying the first option to bring all AFValues in memory across time range, but as you suggested by using AFValuse.Summary how can I get the Initial and Final values along with AVG,MIN and MAX, can you provide some sample would really help me in this?


            I was trying something like

            var afValues = pivalue.Result.InterpolatedValues(new AFTimeRange("00:00", "01:00"), new AFTimeSpan(0, 0, 0, 1, 0, 0, 0),"", false);

                                    var dictionVal = afValues.Summary(new AFTimeRange("00:00", "01:00"), AFSummaryTypes.All, AFCalculationBasis.EventWeighted, AFTimestampCalculation.Auto);

                                    foreach (var item in dictionVal)


                                        Console.WriteLine("key {0}, Value :{1}",item.Key, dictionVal[item.Key].Value);



            2) AFData.InterpolatedValuesAtTimes  , valid point by eliminating one extra RPC call, by using this got some improvement. 

            3) And about Async call, I am using PI Asset Framework (AF) Client 2012 SP2 Install Kit (with PSE and AF SDK)     2012 SP2 ( in this I couldn't see any Async methods. Do I need to upgrade to a newer version of SDK?