diff --git a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Dtos/SavedState.cs b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Dtos/SavedState.cs index 9c42d3d1..253c5111 100644 --- a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Dtos/SavedState.cs +++ b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Dtos/SavedState.cs @@ -5,7 +5,7 @@ namespace WaterWatchPreProcessor.Dtos { public class SavedState { - public Dictionary LastSeenBySensorSerial { get; set; } = + public Dictionary NextMeasurementTimeBySensorSerial { get; set; } = new Dictionary(StringComparer.InvariantCultureIgnoreCase); } } diff --git a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Exporter.cs b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Exporter.cs index 521c9276..f563dfef 100644 --- a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Exporter.cs +++ b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Exporter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using ServiceStack; using ServiceStack.Text; using WaterWatchPreProcessor.Dtos; @@ -28,18 +29,28 @@ public void Run() var nameFilter = new Filter(Context.SensorNameFilters); var serialFilter = new Filter(Context.SensorSerialFilters); + Console.WriteLine("Iso8601UtcTime, SensorType, SensorSerial, Value"); + foreach (var sensor in sensors) { if (nameFilter.IsFiltered(f => f.Regex.IsMatch(sensor.Name)) || serialFilter.IsFiltered(f => f.Regex.IsMatch(sensor.Serial))) continue; - foreach (var measurement in GetSensorMeasurements(sensor)) + var measurements = GetSensorMeasurements(sensor) + .ToList(); + + var latestMeasurement = measurements.LastOrDefault(); + + if (latestMeasurement != null) { - Console.WriteLine($"{measurement.Time:yyyy-MM-ddTHH:mm:ss.fffZ}, {sensor.SensorType}, {sensor.Serial}, {GetSensorValue(sensor, measurement.RawDistance)}"); + SavedState.NextMeasurementTimeBySensorSerial[sensor.Serial] = latestMeasurement.Time.AddMilliseconds(1); } - SavedState.LastSeenBySensorSerial[sensor.Serial] = sensor.LatestData.LastSeen; + foreach (var measurement in measurements) + { + Console.WriteLine($"{measurement.Time:yyyy-MM-ddTHH:mm:ss.fffZ}, {sensor.SensorType}, {sensor.Serial}, {GetSensorValue(sensor, measurement.RawDistance)}"); + } } PersistSavedState(); @@ -78,7 +89,7 @@ private IList GetSensors() private IEnumerable GetSensorMeasurements(Sensor sensor) { - if (!SavedState.LastSeenBySensorSerial.TryGetValue(sensor.Serial, out var lastSeenTime)) + if (!SavedState.NextMeasurementTimeBySensorSerial.TryGetValue(sensor.Serial, out var lastSeenTime)) { lastSeenTime = DateTime.UtcNow.Date.AddDays(-Context.NewSensorSyncDays); } diff --git a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Readme.md b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Readme.md index dcea4715..a646b568 100644 --- a/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Readme.md +++ b/TimeSeries/PublicApis/SdkExamples/WaterWatchPreProcessor/Readme.md @@ -59,14 +59,12 @@ Use `/OutputMode=RawDistance` to always show the sensor's rawDistance value. Each time the tool runs, it queries the WatchWatch API for any new measurements. -`Iso8601UtcTime, SensorType, SensorSerial, Value` - Each new measurement will be output to standard out as the following CSV stream: - ```csv +Iso8601UtcTime, SensorType, SensorSerial, Value 2018-12-31T14:35:00.000Z, LS1, 418892, 92.23456 -2018-12-31T15:35:00.000Z, LS1, 418892, 89.47586 +2018-12-31T14:37:00.000Z, LS1, 40AD1C, 289.47586 ``` ## `/help` screen