see on GitHub

Operations: Append & Delete Time Series


To Append and Delete multiple time series entries, use TimeSeriesBatchOperation.


TimeSeriesBatchOperation

TimeSeriesBatchOperation executes a list of time series entries Append and Delete actions.
The list is prepared in advance in a TimeSeriesOperation instance using TimeSeriesOperation.Append and TimeSeriesOperation.Delete, and is passed to TimeSeriesBatchOperation as an argument.

Syntax

  • TimeSeriesBatchOperation
    This is the operation you need to execute to append and delete time series entries.

    • Definition

      public TimeSeriesBatchOperation(string documentId, TimeSeriesOperation operation)
    • Parameters

      Parameters Type Description
      documentId string ID of the document to append TS data to
      operation TimeSeriesOperation Operation configuration class:
      Which Append/Delete actions to perform
  • TimeSeriesOperation
    This is the configuration class provided to TimeSeriesBatchOperation as an argument, with a list of time series entries Append and Delete actions.

    public class TimeSeriesOperation
          {
              public string Name;
              public void Append(AppendOperation appendOperation)
              public void Delete(DeleteOperation deleteOperation)
    
              //..
          }
    Property Type Description
    Name string Time Series name
    Append method Add an Append action to the list
    Delete method Add a Delete action to the list

  • To add a time series entry Append action, call TimeSeriesOperation.Append.

    public void Append(AppendOperation appendOperation)
    public class AppendOperation
          {
              public DateTime Timestamp;
              public double[] Values;
              public string Tag;
    
              //..
          }
    Property Type Description
    Timestamp DateTime The TS entry will be appended at this timestamp
    Values double[] Entry values
    Tag string Entry tag (optional)

  • To add a time series entry Delete action, call TimeSeriesOperation.Delete.

    public void Delete(DeleteOperation deleteOperation)
    public class DeleteOperation
          {
              public DateTime? From, To;
    
              //..
          }
    Property Type Description
    From (optional) DateTime? Range start
    Entries will be deleted starting at this timestamp
    To (optional) DateTime? Range end
    Entries will be deleted up to this timestamp

Usage Flow

  • Create an instance of TimeSeriesOperation

    • Add it the time series name.
  • Prepare the Append and Delete sequence.

    • Call TimeSeriesOperation.Append to add an Append action
    • Call TimeSeriesOperation.Delete to add a Delete action

      NOTE: Delete actions will be executed before Append actions.

  • Create a TimeSeriesBatchOperation instance.
    Pass it the document ID and your TimeSeriesOperation instance

  • Call store.Operations.Send with your TimeSeriesBatchOperation instance to execute the operation.

Usage Samples

  • In this sample, we append two entries to a time series using TimeSeriesBatchOperation.

    var baseline = DateTime.Today;
    
    var timeSeriesExerciseHeartRate = new TimeSeriesOperation
    {
        Name = "RoutineHeartRate"
    };
    
    timeSeriesExerciseHeartRate.Append(new TimeSeriesOperation.AppendOperation { Tag = "watches/fitbit", Timestamp = baseline.AddMinutes(1), Values = new[] { 79d } });
    timeSeriesExerciseHeartRate.Append(new TimeSeriesOperation.AppendOperation { Tag = "watches/fitbit", Timestamp = baseline.AddMinutes(2), Values = new[] { 82d } });
    timeSeriesExerciseHeartRate.Append(new TimeSeriesOperation.AppendOperation { Tag = "watches/fitbit", Timestamp = baseline.AddMinutes(3), Values = new[] { 80d } });
    timeSeriesExerciseHeartRate.Append(new TimeSeriesOperation.AppendOperation { Tag = "watches/fitbit", Timestamp = baseline.AddMinutes(4), Values = new[] { 78d } });
    
    var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesExerciseHeartRate);
    
    store.Operations.Send(timeSeriesBatch);
  • In this sample, we delete two ranges of entries from a time series.

    var removeEntries = new TimeSeriesOperation
    {
        Name = "RoutineHeartRate"
    };
    
    removeEntries.Delete(new TimeSeriesOperation.DeleteOperation { From = baseline.AddMinutes(2), To = baseline.AddMinutes(3) });
    
    var removeEntriesBatch = new TimeSeriesBatchOperation(documentId, removeEntries);
    
    store.Operations.Send(removeEntriesBatch);