3 Replies Latest reply on Jul 10, 2015 6:47 PM by mdspath

    AFTimeSpan create equal divisions



      I'm trying to allow the user of our custom app (built using the AF SDK) to subdivide the timeframe into equal chunks. I know it has to be converted to ticks, how to get a new AFTimeSpan from a Tick value? IN the code below I'm using 10 as my divisor.


                // Set the Time Range

                  AFTimeRange myTimeRange = new AFTimeRange();

                  myTimeRange.StartTime = new AFTime(gbRealStart);

                  myTimeRange.EndTime = new AFTime(gbRealEnd);



                  // find the span to use based on how many chunks of data

                  //AFTimeSpan span = AFTimeSpan.Parse("5s");

                  AFTimeSpan span = new AFTimeSpan(myTimeRange.Span);



                  // we will call the interpolated values method just to show user the number of data points

                  // now divide the AFTimeSpan into egual parts

                  long NumTicks = span.Ticks / 10;



        • Re: AFTimeSpan create equal divisions
          Dan Fishman

          I'm not exactly sure what you are trying to do.  There are methods to obtain interpolated values by count such as PIPoint.InterpolatedValuesbyCount and AFData.GetValues.


          Here is code to obtain the first AFTimeRange that is a tenth of the original AFTimeRange.  I basically convert to a DateTime object by using the UtcTime method.


            AFTimeRange myNextRange = new AFTimeRange(myTimeRange.StartTime, myTimeRange.StartTime.UtcTime.AddTicks(NumTicks));



          Hope this is what you are looking for.




          1 of 1 people found this helpful
          • Re: AFTimeSpan create equal divisions
            Rick Davin

            The AFTimeSpan has a GetIntervalTimes method that accepts an AFTimeRange as input.


            IList<AFTime> timestamps = span.GetIntervalTimes(myTimeRange);
            foreach (var time in timestamps)
                // do something


            Of course that creates a collection, so you might have a million objects returned, whereas using Dan Fishman 's answer uses less memory.  So now you have 2 ways to do what you want to do.

            1 of 1 people found this helpful
            • Re: AFTimeSpan create equal divisions

              Thank you for your responses, I think I will end up trying to use the PiPoinList Summaries method to do what I need. I will have the user dictate the span in each of these calls. It seems to work for the averaging, but I'm getting errors when trying to use summaries() for standard deviation. I will have to keep playing with it.