Incremental Time Series: JavaScript Support

The timeseries Interface

  • Use timeseries (doc, name) to choose a time series by the ID of its owner document and by the series name.

    Parameter Type Description
    doc string
    or
    document instance
    Document ID, e.g. users/1-A

    e.g. this
    name string Incremental time series Name (e.g. INC:StockPrice)
  • Use one of the following methods to access the chosen time series:

timeseries.increment

  • There are four Increment methods:

    • Increment a time series entry's array of values at the provided timestamp.
      // Increment a time series entry's array of values at the provided timestamp
      void Increment(DateTime timestamp, IEnumerable<double> values);
    • Increment a time series entry's array of values at the current time.
      // Increment a time series entry's array of values at the current time
      void Increment(IEnumerable<double> values);
    • Increment an entry value at the provided timestamp.
      (If the entry exists and has more than one value, only the first value in its list will be incremented by the passed value.)
      // Increment an entry value at the provided timestamp
      void Increment(DateTime timestamp, double value);
    • Increment an entry value at the current time.
      (If the entry exists and has more than one value, only the first value in its list will be incremented by the passed value.)
      // Increment an entry value at the current time
      void Increment(double value);
  • Parameters

    Parameters Type Description
    timestamp DateTime Time series entry's timestamp
    values IEnumerable A list of delta values to increment the entry values by
    value double The delta to increment the entry value by
  • Exceptions
    If the document doesn't exist, a DocumentDoesNotExistException exception is thrown.

Usage Sample

In this sample we use session.Advanced.Defer to patch an incremental time series.
We go through a series of collected stock prices, and add a 2 factor to each collected stock price, that has been originally miscalculated.

session.Advanced.Defer(new PatchCommandData("users/1-A", null,
    new PatchRequest
    {
        Script = @"
            var i = 0;
            for(i = 0; i < $timeStamps.length; i++)
            {
                timeseries(id(this), $timeseries)
                .increment (
                    new Date($timeStamps[i]), 
                    $factor);
            }",

        Values =
        {
            { "timeseries", "INC:StockPrice" },
            { "timeStamps", timeStamps},
            { "factor", 2 },
        }
    }, null));