public void TestIntTimeSeriesOddResampling() { var timeseries = new TimeSeriesStream <int>(new TimeSeriesSpan(begin, end, 5)); timeseries[0] = 7; timeseries[1] = 10; timeseries[2] = 23; timeseries[3] = 50; timeseries[4] = 12; // Resample with slightly later start and slightly earlier end var resampler1 = new TimeSeriesResampler <TimeSeriesStream <int>, int>( new TimeSeriesSpan(begin.AddSeconds(5), end.AddSeconds(-5), 5)); resampler1.SampleAggregate(timeseries, x => (int)x.Average()); Assert.Equal(new List <int>() { 10, 23, -1, 50, 12 }, resampler1.Resampled.Trimmed(-1)); // Resample with slightly earlier start and slightly later end var resampler2 = new TimeSeriesResampler <TimeSeriesStream <int>, int>( new TimeSeriesSpan(begin.AddSeconds(-5), end.AddSeconds(5), 5)); resampler2.SampleAggregate(timeseries, x => (int)x.Average()); Assert.Equal(new List <int>() { 7, 10, 36, 12 }, resampler2.Resampled.Trimmed(-1)); }
public void TestDoubleTimeSeriesSampleAverage() { var timeseries = new TimeSeriesStream <double>(span); timeseries[0] = 0d; timeseries[1] = 10d; timeseries[2] = 0.0; timeseries[3] = 0.5; timeseries[4] = 0.01; timeseries[5] = 0.02; timeseries[6] = 50.7; timeseries[7] = 60.7; timeseries[8] = 50000; timeseries[9] = 100000; var resampler = new TimeSeriesResampler <TimeSeriesStream <double>, double>(spanDownsampling); resampler.SampleAggregate(timeseries, x => x.Average()); // results get cropped to 1 decimal place and to a max of short.MaxValue / 10 Assert.Equal(new List <double>() { 5d, 0.2, 0.0, 55.7, 3276.7 }, resampler.Resampled.Trimmed(-1d)); }
public void TestIntTimeSeriesDownsampling() { var timeseries = new TimeSeriesStream <int>(span); timeseries[0] = 1; timeseries[3] = 23; timeseries[7] = 43; timeseries[8] = 5; timeseries[9] = 99; var resampler = new TimeSeriesResampler <TimeSeriesStream <int>, int>(spanDownsampling); resampler.SampleAccumulate(timeseries); Assert.Equal(new List <int>() { 1, 23, -1, 43, 104 }, resampler.Resampled.Trimmed(-1)); }
public void TestIntTimeSeriesUpsampling() { var timeseries = new TimeSeriesStream <int>(span); timeseries[0] = 1; timeseries[3] = 23; timeseries[7] = 43; timeseries[8] = 5; timeseries[9] = 99; var resampler = new TimeSeriesResampler <TimeSeriesStream <int>, int>(spanUpsampling); resampler.SampleAccumulate(timeseries); // should upsample, because no oversample constraint was set Assert.Equal(new List <int>() { 1, -1, -1, -1, -1, -1, 23, -1, -1, -1, -1, -1, -1, -1, 43, -1, 5, -1, 99 }, resampler.Resampled.Trimmed(-1)); }
public void TestIntTimeSeriesDownsamplingNoOversampling() { var timeseries = new TimeSeriesStream <int>(span); timeseries[0] = 1; timeseries[3] = 23; timeseries[7] = 43; timeseries[8] = 5; timeseries[9] = 99; var resampler = new TimeSeriesResampler <TimeSeriesStream <int>, int>(spanDownsampling, SamplingConstraint.NoOversampling); resampler.SampleAccumulate(timeseries); // should downsample, because oversampling only happens while upsampling Assert.Equal(new List <int>() { 1, 23, -1, 43, 104 }, resampler.Resampled.Trimmed(-1)); }
public void TestIntTimeSeriesUpDownsampling() { var timeseries = new TimeSeriesStream <int>(span); timeseries[0] = 1; timeseries[3] = 23; timeseries[7] = 43; timeseries[8] = 5; timeseries[9] = 99; // upsample var resampler = new TimeSeriesResampler <TimeSeriesStream <int>, int>(spanUpsampling); resampler.SampleAccumulate(timeseries); // downsample to the original var resampler2 = new TimeSeriesResampler <TimeSeriesStream <int>, int>(span); resampler2.SampleAccumulate(resampler.Resampled); Assert.Equal(timeseries.Trimmed(-1), resampler2.Resampled.Trimmed(-1)); }
public void TestIntTimeSeriesSampleAverage() { var timeseries = new TimeSeriesStream <int>(span); timeseries[0] = 0; timeseries[1] = 10; timeseries[2] = 0; timeseries[3] = 50; timeseries[4] = 10; timeseries[5] = 20; timeseries[6] = 50; timeseries[7] = 60; timeseries[8] = 5; timeseries[9] = 10; var resampler = new TimeSeriesResampler <TimeSeriesStream <int>, int>(spanDownsampling); resampler.SampleAggregate(timeseries, x => (int)x.Average()); Assert.Equal(new List <int>() { 5, 25, 15, 55, 7 }, resampler.Resampled.Trimmed(-1)); }