Roger Palmen

Unexplained number of results returned in call to AFData.InterpolatedValues

Discussion created by Roger Palmen on Aug 29, 2013
Latest reply on Aug 29, 2013 by RJKSolutions

Hi All,


Continuing my development, i stumbled upon some behaviour i cannot explain. I use a call to AFData.InterpolatedValues but that always returns one more result than expected based on the AFSDK documentation. Examples:

  • A full year, with a one day interval: Timerange * to *-1y, and interval = 1d. Returns 366 values, expecting 365 (non-leap year).
  • Maybe it's a boundary issue: let's drop a second: Timerange *-1s to *-1y, and interval = 1d. Returns 366 values, expecting 365 (non-leap year).
  • Well, lets drive it down to the extreme: Timerange * to *, and interval = 1d. Returns 2 values, expecting 1.
Based on the documentation, i cannot explain the results and it even looks like a bug because one of the two results in the last case has a timestamp outside the given boundary. Anyone any ideas?
        private void btnCalculateSummaries_Click(object sender, EventArgs e)
            //Get parameters from GUI
            AFElement targetElement = (AFElement) afBasePicker1.AFSelection;
            AFTimeRange timerange = new AFTimeRange(txtTimeRangeStart.Text, txtTimeRangeEnd.Text);
            AFTimeSpan interval = new AFTimeSpan();
            interval = AFTimeSpan.Parse(txtInterval.Text);
            //Get the attribute
                //Get Element of selected TreeNode
                AFElement treeElement = (AFElement)afTreeSelection;
                txtElement.Text = treeElement.Name;
                //Get attribute from Attribute selectionbox
                string AttributePath = treeElement.GetPath() + "|" + txtInputForSum_Attribute.Text;      
                AFAttribute attr = AFObject.FindObject(AttributePath) as AFAttribute;

                AFValues results = attr.Data.InterpolatedValues(timerange, interval, null, null, false);
                double sumResult = 0;
                foreach (AFValue result in results)
                    sumResult = sumResult + (double) result.Value;
                string firstResultTime = results.First().Timestamp.ToString();
                string lastResultTime = results.Last().Timestamp.ToString();
                txtResult_CalculateSummaries.Text = sumResult.ToString();
                txtResultStats.Text = "# of results: " + results.Count.ToString();
                txtResultStats.Text =  txtResultStats.Text + Environment.NewLine + "First result: " + firstResultTime;
                txtResultStats.Text = txtResultStats.Text + Environment.NewLine + "Last result: " + lastResultTime;
            catch (Exception Ex)