5 Replies Latest reply on Jul 9, 2015 9:06 PM by Rhys Kirk

    How can I aggregate results from summaries?

    b3sys

      Say I run Summaries to calculate the average of a point over a large TimeRange for a TimeSpan of every day, then I want to sum those results to get a final total- is there an efficient way to do this?  I'm using C# and right now I pull all the data from Summaries and then aggregate it in my code.

        • Re: How can I aggregate results from summaries?
          Rhys Kirk

          Depends on your end goal but you could do that without "programming" and just use "configuration".

          AF Analyses could do that...you perform your Summaries and then roll-up the results for your overall sum of the summaries.

            • Re: How can I aggregate results from summaries?
              b3sys

              What about if I don't have access to the AF server?

                • Re: How can I aggregate results from summaries?
                  Rhys Kirk

                  No AF. Buy AF.

                   

                  Are you using the PI SDK then?

                  You'll have to do as you already describe; perform a Summary for each PI Point and then locally aggregate the results.

                    • Re: How can I aggregate results from summaries?
                      b3sys

                      AF is in place, and I am using the AF SDK,  Looking for the most efficient way to accomplish this using "programming"- thoughts?

                        • Re: How can I aggregate results from summaries?
                          Rhys Kirk

                          It depends on the number of PI Points you are accessing data for. You could in theory submit a dynamic Performance Equation (that includes the summary details) and have the PI Data Archive process it and just return you a value. That would probably work for a few PI Points. e.g.

                          TagTotal('Tag1','y','t') + TagTotal('Tag2','y','t') + TagTotal('Tag3','y','t') ...
                          

                           

                          Otherwise you could make use of the PIPointList object, call the Summary method and parse the results using Linq. e.g. (quick example)

                           

                          OSIsoft.AF.PI.PIPointList pl = new OSIsoft.AF.PI.PIPointList();
                          // ...
                          IEnumerable<IDictionary<OSIsoft.AF.Data.AFSummaryTypes, OSIsoft.AF.Asset.AFValue>> summaries = pl.Summary(new OSIsoft.AF.Time.AFTimeRange("y", "t"), OSIsoft.AF.Data.AFSummaryTypes.Total, OSIsoft.AF.Data.AFCalculationBasis.TimeWeighted, OSIsoft.AF.Data.AFTimestampCalculation.Auto, new OSIsoft.AF.PI.PIPagingConfiguration(OSIsoft.AF.PI.PIPageType.TagCount, 10000));
                          double total = summaries.Sum(sum => sum.Values.Sum(val => double.Parse(val.Value.ToString())));