13 Replies Latest reply on Nov 17, 2011 3:03 AM by kkolli

    PI Webservices Aggregation


      I have some data in pi which is at 2 second intervals. I need to retrieve this data and aggregate into 15 minute intervals, either SUM or average.


      Is there a way to do it in PI web services? I understand that we can use totalizers for that purpose, I was wondering if there is way to do it via PI web services directly.


      Thank you





        • Re: PI Webservices Aggregation
          Ahmad Fattahi

          Check out the GetPISummaryData method in IPITimeSeries interface. Using this method you can get averages, means, minima, maxima, ranges, totals, values, counts, and both sample and population standard deviations. You pass your objects to do the summary over, time range, and the action using the PISummaryDataRequest which in turn includes PISummaryManner encapsulating your desired operation.

            • Re: PI Webservices Aggregation

              You can find more information and short code snippet in the PI Web Services user manual, available on the vCampus Library (under vCampus PI Products Kit > Data Access Technologies).

                • Re: PI Webservices Aggregation

                  Thank you Ahmad and steven for the responses.


                  Sorry , my previous was not clear. i need to report this data aggregated at 15 minute intervals over a period of the day. so if i give startime and end time..i need to get a  response aggregated in 15 minute intervals for the whole duration.

                    • Re: PI Webservices Aggregation
                      Ahmad Fattahi

                      You are very welcome! You should be able to tweak the above-mentioned GetPISummaryData to get what you want. Posting your code and what you have right now would be very helpful in moving forward and seeing what we are missing here.

                        • Re: PI Webservices Aggregation

                          Well, I did some reading and figured out how to do what i was asking. Now i got a different problem. i have a tag value every 2 seconds. this value can be either 1 or 0. at the end of the day i need to aggregate this tag at 15 minute intervals based on a condition. that is in the 15 minute period if all the 2 sec values were 1 then only the 15 minute value can be 1. or else 0.


                          For example purpose lets assume there is a value at every 5 minute interval


                          2011-11-11T00:05:00    1  


                          2011-11-11T00:10:00    1


                          2011-11-11T00:15:00    1


                          2011-11-11T00:20:00    1  


                          2011-11-11T00:25:00    1


                          2011-11-11T00:30:00    1


                          2011-11-11T00:35:00    0  


                          2011-11-11T00:40:00    1


                          2011-11-11T00:45:00    1


                          So my resultset would be


                          2011-11-11T00:15:00    1  


                          2011-11-11T00:30:00    1


                          2011-11-11T00:45:00    0


                          can this be done with a single call to the GetPISummaryData? Or do we need to create a performance equation for this purpose.

                            • Re: PI Webservices Aggregation

                              I would suggest to use a performance equation like:

                              IF TIMEGT('tag', '*-15m', '*', 0) = 900 THEN 1 ELSE 0

                              Essentially it is just testing for the amount of time in the last 15 minutes where the value of the tag is greater than 0. If it is equal to 15 mins (900 sec) then return 1, else return 0. This way, you will get the result that you want directly.


                              If you go with the route of using GetPISummaryData, you can probably find the sum or average, which can help you determine if it should be 1 or 0, but it means you still have to analyze it based on the return result. 


                              Also, you probably want to test the equation for different scenarios like missing values and cases where the value before and after your boundaries are 0.

                                • Re: PI Webservices Aggregation

                                  As explained in the "Web Services Inputs" section of the PI Web Services User Guide, you can pass a Performance Equation (PE) expression directly to the web methods of the PITimeSeries interfaces (e.g. GetIArchiveData). It should start with the "pe:" designator, rather than "pi:" for a PI Point path or "af:" for an AF Attribute path.


                                  Alternatively you can create a PE tag directly on the PI Server, as Han Yong suggested, which might be better if this equation is useful in other contexts as well (e.g. users might want to trend that in PI ProcessBook or create an Excel report that includes that information, using PI DataLink).

                                    • Re: PI Webservices Aggregation

                                      Thank you guys. The reason i am trying to avoid any kind of PE is, we have a bunch of tags..and for each tag i will end up creating PE.  So i was trying the approach suggested han yong and implement it as a Pi webservice path like steven suggested.


                                      I am still not getting the correct results.






                                      and all my source values from 12:300 to 13:15 that day are 1's. so i am basically expecting to see the first 3 values as 1's. and rest 0's


                                      I gave the amount of time as 450 seconds to see if that makes a difference since they are at 2 sec intervals. but either case whether it is 900 or 450, it is giving me the same result. I understand the logic i should be applying. but i dont understand how the combination of these parameters work together to give me what i want.


                                      what am i doing wrong?

                                        • Re: PI Webservices Aggregation

                                          I am getting the following error -


                                          "Cannot do summary calculation on non-numeric data", when i try to do a summary calculation on a tag.


                                          I believe the datatype is Digital for that tag.


                                          are there any conversion functions, or is there a work around to perform summary calculations on Digital data? -  the tag values are either 1 or 0

                                          • Re: PI Webservices Aggregation

                                            Hi Keethi,


                                            When you were trying to apply the PE equation to the PI Web Services call, where you using the GetPISummaryData method or the GetPIArchiveData method? Seems like you are using the GetPISummaryData method, since there are summary parameters in the screenshot. 


                                            I would try using GetPIArchiveData method instead, here's an xml view of my request to PI Web Services:

                                             <Start>15-Nov-2011 08:00:00</Start>
                                             <End>15-Nov-2011 10:00:00</End>
                                             <Path>pe:\\hyong\IF TIMEGT('testcountstate', '*-15m', '*', 0) = 900 THEN 1 ELSE 0</Path>
                                            -<PIArcManner RetrievalType="Interpolated"NumValues="9">

                                            I've attached my test data in the form of a csv file. The only difference is that the interval of values is 1 minutes instead of 2 second. You can see that I am interpolating for data every 15 minutes interval (by requesting for 9 values in a 2 hours time period), which essentially is calculating at 15 minutes interval.


                                            The result I get are as follows (again in xml view):

                                            -<TimeSeries Path="pe:\\hyong\IF TIMEGT('testcountstate', '*-15m', '*', 0) = 900 THEN 1 ELSE 0"Error="0"SeriesID="1c396dfb-c136-42d6-9e0e
                                             <TimedValue Time="2011-11-15T00:00:00Z">0</TimedValue> 
                                             <TimedValue Time="2011-11-15T00:15:00Z">1</TimedValue>
                                             <TimedValue Time="2011-11-15T00:30:00Z">0</TimedValue>
                                             <TimedValue Time="2011-11-15T00:45:00Z">1</TimedValue>
                                             <TimedValue Time="2011-11-15T01:00:00Z">1</TimedValue>
                                             <TimedValue Time="2011-11-15T01:15:00Z">1</TimedValue>
                                             <TimedValue Time="2011-11-15T01:30:00Z">0</TimedValue>
                                             <TimedValue Time="2011-11-15T01:45:00Z">1</TimedValue>
                                             <TimedValue Time="2011-11-15T02:00:00Z">1</TimedValue>

                                            The first result is actually the result of the PE equation from 7:45 to 8:00 which I did not backfill any test data, hence 0 would be the expected result. And for the rest, if you refer to my test data, you can see that the 0s corresponds to the 15 minute period where there are 0 values. I believe this is what you are expecting to get, from your description in the previous posts.

                                              • Re: PI Webservices Aggregation

                                                @Keethi: Just like to follow up on this, were you able get to your desired result?

                                                  • Re: PI Webservices Aggregation

                                                    Issue1 - For getting summary over 15 minutes fo the  CF tag with 1's and 0's logic - turns out , i was over thinking the whole thing. So i used a maximum function -  to get the result i desired.


                                                    Issue 2 - Summary on Digital type tags.i was able to achieve this using the Int(string(tagval)).  which is still kind of crude. but it solves my purpose for now.


                                                    Thank you all for your help on these. I learnt a lot during the process