private static double GetTotalByIdAndDay(TimeSeriesGroup data, string[] ids, DateTime startDateTime) { var endDateTime = startDateTime + TimeSpan.FromDays(1); if (ids.Length == 1) { var timeSeries = data[ids[0]]; if (timeSeries?.AnyBetween(startDateTime, endDateTime) == true) { return timeSeries.TotalUntil(endDateTime); } } else if (ids.Length > 1) { // create a sub group of all time series TimeSeriesGroup group = new TimeSeriesGroup(); foreach (var exId in ids) { var item = data[exId]; if (item != null) { group.Add(item); } } if (group.AnyBetween(startDateTime, endDateTime)) { return group.TotalUntil(endDateTime); } } return double.NaN; }
public void TimeSeriesGroup_Empty() { var group = new TimeSeriesGroup(); Assert.Equal(0, group.Count); Assert.Null(group.FirstDataPoint); Assert.Null(group.LastDataPoint); Assert.False(group.AnyBetween(DateTimeOffset.MinValue, DateTimeOffset.MaxValue)); Assert.InRange(group.Sum(DateTimeOffset.MinValue, DateTimeOffset.MaxValue), 0.0 - Accuracy, 0.0 + Accuracy); Assert.InRange(group.TotalUntil(DateTimeOffset.MaxValue), 0.0 - Accuracy, 0.0 + Accuracy); }
public void TimeSeriesGroup_OneEmptyTimeSeries() { var group = new TimeSeriesGroup(); var container = new SensorTimeSeries("1234"); group.Add(container); Assert.Equal(1, group.Count); Assert.Null(group.FirstDataPoint); Assert.Null(group.LastDataPoint); Assert.False(group.AnyBetween(DateTimeOffset.MinValue, DateTimeOffset.MaxValue)); Assert.InRange(group.Sum(DateTimeOffset.MinValue, DateTimeOffset.MaxValue), 0.0 - Accuracy, 0.0 + Accuracy); Assert.InRange(group.TotalUntil(DateTimeOffset.MaxValue), 0.0 - Accuracy, 0.0 + Accuracy); }