Operations: Append & Delete Time Series
To Append and Delete multiple time series entries, use TimeSeriesBatchOperation
.
- In this page:
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 toTimeSeriesBatchOperation
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 actionNOTE: Delete actions will be executed before Append actions.
-
-
Create a
TimeSeriesBatchOperation
instance.
Pass it the document ID and yourTimeSeriesOperation
instance -
Call
store.Operations.Send
with yourTimeSeriesBatchOperation
instance to execute the operation.
Usage Samples
- In this sample, we append two entries to a time series using
TimeSeriesBatchOperation
.
var baseTime = DateTime.Today;
// Define the Append operations:
// =============================
var appendOp1 = new TimeSeriesOperation.AppendOperation
{
Timestamp = baseTime.AddMinutes(1), Values = new[] {79d}, Tag = "watches/fitbit"
};
var appendOp2 = new TimeSeriesOperation.AppendOperation
{
Timestamp = baseTime.AddMinutes(2), Values = new[] {82d}, Tag = "watches/fitbit"
};
var appendOp3 = new TimeSeriesOperation.AppendOperation
{
Timestamp = baseTime.AddMinutes(3), Values = new[] {80d}, Tag = "watches/fitbit"
};
var appendOp4 = new TimeSeriesOperation.AppendOperation
{
Timestamp = baseTime.AddMinutes(4), Values = new[] {78d}, Tag = "watches/fitbit"
};
// Define 'TimeSeriesOperation' and add the Append operations:
// ===========================================================
var timeSeriesOp = new TimeSeriesOperation
{
Name = "HeartRates"
};
timeSeriesOp.Append(appendOp1);
timeSeriesOp.Append(appendOp2);
timeSeriesOp.Append(appendOp3);
timeSeriesOp.Append(appendOp4);
// Define 'TimeSeriesBatchOperation' and execute:
// ==============================================
var timeSeriesBatchOp = new TimeSeriesBatchOperation("users/john", timeSeriesOp);
store.Operations.Send(timeSeriesBatchOp);
- In this sample, we delete two ranges of entries from a time series.
var baseTime = DateTime.Today;
var deleteOp = new TimeSeriesOperation.DeleteOperation
{
From = baseTime.AddMinutes(2), To = baseTime.AddMinutes(3)
};
var timeSeriesOp = new TimeSeriesOperation
{
Name = "HeartRates"
};
timeSeriesOp.Delete(deleteOp);
var timeSeriesBatchOp = new TimeSeriesBatchOperation("users/john", timeSeriesOp);
store.Operations.Send(timeSeriesBatchOp);