6 Replies Latest reply on Dec 11, 2015 3:38 PM by Jeevan

    Retrieving historical data for multiple tags in one call

    Jeevan

      Hi,

       

      I am trying to retrieve historical values, for about 70,000 tags. At the moment I'm using the following method:

       

                var points = new PISDK.PISDK().Servers["my-server"];

                List<PIValues> history = new List<PIValues>();

                foreach(PIPoint point in points)

                  {

                      history.Add(point.Data.RecordedValues(DateTime.Now.AddDays(-5), DateTime.Now, BoundaryTypeConstants.btInside));

                  }

       

      This is needless to say very expensive because it is making a call to the PI Server for each item. Does anyone know if there is a way to get these values in one call?

        • Re: Retrieving historical data for multiple tags in one call
          Marcos Vainer Loeff

          Hi Jeevan,

           

          Yes, it is possible to make data request in bulk for getting recorded values. Here is an example:

           

                      NamedValues nvErrors = null;
                      filteredPIPointList = piServer.GetPointsSQL("PIpoint.tag = 'cdt158'");
                      Console.WriteLine(filteredPIPointList.Count);
                      var pvLists = filteredPIPointList.Data.RecordedValues("*-1d", "*", BoundaryTypeConstants.btAuto, "", FilteredViewConstants.fvShowFilteredState, out nvErrors);
                      foreach (PointValueList pvList in pvLists)
                      {
                          PIPoint piPoint = pvList.PIPoint;
                          PIValues values = pvList.PIValues;
                          Console.WriteLine(values.Count);
                      }
           PIValues values = pvList.PIValues;
                      }
          

           

          Can you check if this works for you?

          • Re: Retrieving historical data for multiple tags in one call
            Marcos Vainer Loeff

            Hi Jeevan,

             

            I tried to run the code above but I was receiving an NotImplementedException. At first, I thought it was something wrong with my system but after some search I found out that this method is not yet implemented. Therefore, it is not possible to optimize your code.

             

            I think the reason is that the development team has decided to focus the new enhancements on PI AF SDK instead of PI SDK. If you use PI AF SDK, you will be able to make a similar call that actually works.

             

            This is a great example of why you should migrate your application from PI SDK to PI AF SDK in order to have better performance.

             

            Hope it helps!