8 Replies Latest reply on Feb 9, 2011 4:34 PM by andreas

    Values from time span with frequency

    jimmilton

      I have been searching for how to accomplish the following.   I'm creating a service that will take in a server name, point, start time, end time, and an interval in seconds.  The goal is to allow the a client application to submit a request for data for example from a server for tag "Sinusoid" for 1/1/2011 3:00:00 to  1/1/2011 22:30:00 with an interval of 300 (5 minutes) and get back a dataset of timestamps and values every 5 minutes through the period (228 values returned).  I have been trying to figure out how to do this with PI SDK.  Could anyone give me an example of how this is written?  I have the code to connect to the server and pick the point, but getting the recorded values in the manner I gave the example for is what is throwing me.  

       

      As a side question to the example above, if I get back a value for a period like stated above, would I get back averaged values, sampled values, or something else?  What I mean is, if the data collection rate is around 4 seconds, we will have lots of values in a 5 minute period, so will the returned value for the 5 minute period be a sample of the 4 second values, and average of the 4 second values, or something else?  Can I tell PI if I want average vs sample vs other?

       

      Thanks for the help.

       

       

       

      UPDATE:  I'm doing this in C#

        • Re: Values from time span with frequency
          Ahmad Fattahi

          James,

           

          The tasks you are trying to do are doable using PI SDK methods. I would like to invite you review PI SDK documentation for the following methods:

           

          RecordedValues (to retrieve compressed data from the archives)

           

          TimedValues (to retrieve interpolated samples from the PI Server)

           

          Summary and Summaries (to retrieve several summary information over a period of time)

            • Re: Values from time span with frequency

              Wouldn't it be appropriate to use an off-the-shelf product like PI Web Services in this case, as opposed to build your own custom app? This "service" you are trying to build is readily available as a Web service endpoint, when you install PI Web Services.

               

              I encourage you to look at the "PI Web Services 2010 and Beyond" webinar under the Auditorium, and initiate new threads in the "Web Services and PI" forum if you need additional information.

                • Re: Values from time span with frequency
                  jimmilton

                  The PI Web Services 2010 look great and would be a possible solution, but our customer is not using 2010 yet and they are not using the web services.  Also for our service which is an interface to another system, the web services require more code and configuration than the simple sdk calls.  So for this case, I think SDK is the the best solution and the path of least resistance.

                    • Re: Values from time span with frequency
                      jimmilton

                      I have done a little trial and error and reading on the suggested Methods and unless I am misunderstanding the use, none of them quite fit.  RecordedValues does not allow me to set intervals, so if I understand correctly, it simply returns a set of PIValue Objects that are raw captured data over the entire period from start time to end time.  The TimedValues returns a value for the time intervals I created, but these values are interpolated and not an average of a time period.  The closest seems to be the Summaries, but this does not return a set of PIValue Objects and the NamedValue objects do not give me the data I need.  I have found the results of the NamedValues to be very confusing.  From everything I have seen, it sounds like I need to break up the time period myself, and run individual RecordedValues calls for each sub interval and average the results myself.  Is this correct?  So in the example I used above, I would run RecordedValues Method 228 times to fill my set of 5 minute intervals?

                        • Re: Values from time span with frequency
                          andreas

                          James,

                           

                          the Summaries are the way to go. I'll get some code posted soon.

                            • Re: Values from time span with frequency
                              andreas

                              Does this solve your problem:

                               
                                          PISDK.PISDK mPISDK = new PISDK.PISDK();
                                          PISDK.Server mServer = mPISDK.Servers.DefaultServer;
                                          PISDK.PIPoint mPIPoint = mServer.PIPoints["SINUSOID"];
                              
                                          PISDKCommon.NamedValues mNVs;
                                          mNVs = mPIPoint.Data.Summaries("Y",
                                                                         "T",
                                                                         PISDK.BoundaryTypeConstants.btAuto,
                                                                         PISDK.ArchiveSummariesTypeConstants.asAverage,
                                                                         288,
                                                                         PISDK.CalculationBasisConstants.cbTimeWeighted,
                                                                         null);
                                          
                                          PISDK.PIValues mPVs = new PISDK.PIValues();
                                          mPVs = mNVs["Average"].Value;
                                          MessageBox.Show(mPVs.Count.ToString());