4 Replies Latest reply on Sep 16, 2017 11:37 AM by Chirag89

    Can we get initial and final value from PIPoint.Summary method ?




      I am new to this thing, i want to get all the points and for each point i want to get values like initial, final, max, min,avg. I have access to min, max and avg values using summary method. Can i also get the initial and final value for specific time frame ?


      Here is my sample code :


                          List<PIPoint> pp = PIPoint.FindPIPoints(server, "abcd.*", null).ToList<PIPoint>();
                          foreach (PIPoint pivalue in pp)
                              AFTimeRange at = new AFTimeRange("23-Jun-2017 1:25:00 AM", "23-Jun-2017 2:25:00 AM");
                              var summarizedvals = pivalue.Summary(at,AFSummaryTypes.Maximum | AFSummaryTypes.Minimum | AFSummaryTypes.Average, AFCalculationBasis.TimeWeighted,
                                  AFTimestampCalculation.EarliestTime | AFTimestampCalculation.MostRecentTime);
                                    Console.WriteLine("Average Value: " + summarizedvals[AFSummaryTypes.Average].Value);
                                  Console.WriteLine("Max Value: " + summarizedvals[AFSummaryTypes.Maximum].Value);
                                  Console.WriteLine("Min Value: " + summarizedvals[AFSummaryTypes.Minimum].Value);
                               // Can we get the first and final value using summary method ?
                               // Currently i am using plotValues method to fetch the value for a time frame, but i want to optimize it because data is too much.



        • Re: Can we get initial and final value from PIPoint.Summary method ?
          Marcos Vainer Loeff

          Hey Chirag,


          Have you taken a look at the method below?


          PIPointList.RecordedValuesAtTimes Method


          Please let me know if this works for you!

          • Re: Can we get initial and final value from PIPoint.Summary method ?
            Dan Fishman

            Take a look at the PIPoint.RecordedValuesAtTimes method within the OSIsoft.AF.PI namespace.  This method allow you to provide an IList<AFTime> and this is where you could enter your start and end times. 


            If you want to get serious about performance, and your PI Data Archive (PI Server) is 2016 or later, you can page the results.  Check out under the OSIsoft.AF.PI namespace, the PIPointList Class and its methods.  Look at both the PIPointList.Summaries and the RecordedValuesAtTimes.  You also will have to configure the PIPagingConfiguration object.

            • Re: Can we get initial and final value from PIPoint.Summary method ?
              Rick Davin

              Hi Chirag,


              RecordedValuesAtTimes will give you the interpolated values at the StartTime and EndTime of your time range.  If you were wanting the closed archive value, you would need to make 2 additional calls after the Summary.


              AFValue firstValue = pivalue.RecordedValue(at.StartTime, AFRetrievalMode.AtOrAfter);
              AFValue lastValue = pivalue.RecordedValue(at.EndTime, AFRetrievalMode.AtOrBefore);


              As your code currently is, you can do a few minor things:


              • There is no reason for pp to be a List<PIPoint>.  The code shown works fine and may be quicker if you were to change it to:
              IEnumerable<PIPoint> pp = PIPoint.FindPIPoints(server, "abcd.*", null);
              • Defining the time range may be set before the loop.  No need to set it to the same value each iteration through the loop.
              • And personally, I would rename the variable "pivalue" to something like "pipt", "point", or "tag".  To me the phrase "pivalue" carries a different meaning (similar to AFValue or the PISDK.PIValue).


              As Dan suggests, you could find efficiencies by using bulk calls and paging with PIPointList.  The things to look out for are having too many PI points in the PIPointList, which could make the Summary call throw an OperationTimeout exception.  This is all dependent upon how dense your data may be, how wide the time range is, and how many tags you want to aggregate.  So you may have to play around to find the right sweet spot.


              To help get you started, you may start off setting pp to the PIPointList with:

              PIPointList pp = new PIPointList(PIPoint.FindPIPoints(server, "abcd.*", null));


              Then you don't need to loop per tag and make 3 data calls per individual tag.  You can issue 3 bulk data calls using PIPointList.Summary  and two PIPointList.RecordedValue  calls.  This means you've only made 4 calls to the PI Data Archive (FindPIPoints, Summary, and 2 X RecordedValue).