Appending points to a basic time series - AquaticInformatics/aquarius-sdk-net GitHub Wiki
Uses the Acquisition API to queue up an append request job and poll the server until the append completes.
AppendPoints()
The AppendPoints()
method below will append points to a time-series and wait for the points to be appended.
Basic logic:
- Use the GetTimeSeriesUniqueId() example method to the get the unique ID of the target time-series
- Create a "fake" list of single point in time. Here we use March 22nd, World Water Day.
- Use the
RequestAndPollUntilComplete()
method to efficiently queue the job and poll until it completes. See Adaptive Polling for details - Throw an exception when something goes wrong
using Aquarius.TimeSeries.Client;
using NodaTime;
using TimeSeriesPoint = Aquarius.TimeSeries.Client.ServiceModels.Acquisition.TimeSeriesPoint;
private IAquariusClient _client;
private void AppendPoints(string timeSeriesIdentifier)
{
var uniqueId = GetTimeSeriesUniqueId(timeSeriesIdentifier);
var points = new List<TimeSeriesPoint>
{
// World Water Day is March 22nd of every year. 2017 was the 24th celebration
new TimeSeriesPoint { Time = Instant.FromUtc(2017, 3, 22, 0, 0, 0), Value = 24}
};
Console.WriteLine($"Appending {points.Count} to timeSeriesUniqueId={uniqueId:N} starting at {points.First().Time}");
var stopwatch = Stopwatch.StartNew();
var result = _client.Acquisition.RequestAndPollUntilComplete(
client => client.Post(new PostTimeSeriesAppend { UniqueId = uniqueId, Points = points }),
(client, response) => client.Get(new GetTimeSeriesAppendStatus { AppendRequestIdentifier = response.AppendRequestIdentifier }),
polledStatus => polledStatus.AppendStatus != AppendStatusCode.Pending);
if (result.AppendStatus != AppendStatusCode.Completed)
throw new Exception($"Unexpected append status={result.AppendStatus}");
Console.WriteLine($"Appended {result.NumberOfPointsAppended} points (deleting {result.NumberOfPointsDeleted} points) in {stopwatch.ElapsedMilliseconds / 1000.0:F1} seconds.");
}