-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c18340
commit 9af80e5
Showing
14 changed files
with
151 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
ManagedCode.TimeSeries.Sample/ManagedCode.TimeSeries.Sample.csproj
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,76 @@ | ||
global using Xunit; | ||
global using Xunit; | ||
using FluentAssertions; | ||
using ManagedCode.TimeSeries.Sample; | ||
using Newtonsoft.Json; | ||
|
||
public class TimeSeriesTests | ||
{ | ||
[Fact] | ||
public async Task Accumulator() | ||
{ | ||
var series = new IntTimeSeriesAccumulator(TimeSpan.FromSeconds(0.1)); | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
await Task.Delay(new Random().Next(1, 5)); | ||
series.AddNewData(i); | ||
} | ||
|
||
series.DataCount.Should().Be(1000); | ||
|
||
int step = 0; | ||
foreach (var queue in series.Samples) | ||
{ | ||
foreach (var item in queue.Value) | ||
{ | ||
item.Should().Be(step); | ||
step++; | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task AccumulatorLimit() | ||
{ | ||
var series = new IntTimeSeriesAccumulator(TimeSpan.FromSeconds(0.1), 10); | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
await Task.Delay(new Random().Next(1, 5)); | ||
series.AddNewData(i); | ||
} | ||
|
||
series.SamplesCount.Should().Be(10); | ||
} | ||
|
||
[Fact] | ||
public void IntTimeSeriesSummerIncrementDecrement() | ||
{ | ||
var series = new IntTimeSeriesSummer(TimeSpan.FromMinutes(1), 10); | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
series.Increment(); | ||
} | ||
|
||
for (int i = 0; i < 50; i++) | ||
{ | ||
series.Decrement(); | ||
} | ||
|
||
series.DataCount.Should().Be(150); | ||
series.Samples.First().Value.Should().Be(50); | ||
} | ||
|
||
[Fact] | ||
public async Task Summer() | ||
{ | ||
var series = new IntTimeSeriesSummer(TimeSpan.FromSeconds(0.1)); | ||
int count = 0; | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
await Task.Delay(new Random().Next(10, 50)); | ||
series.AddNewData(i); | ||
count++; | ||
} | ||
|
||
series.DataCount.Should().Be((ulong)count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
ManagedCode.TimeSeries/Accumulators/DoubleTimeSeriesAccumulator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ManagedCode.TimeSeries.Accumulators; | ||
|
||
public class DoubleTimeSeriesAccumulator : BaseTimeSeriesAccumulator<double> | ||
{ | ||
public DoubleTimeSeriesAccumulator(TimeSpan sampleInterval, int samplesCount = 0) : base(sampleInterval, samplesCount) | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
ManagedCode.TimeSeries/Accumulators/FloatTimeSeriesAccumulator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ManagedCode.TimeSeries.Accumulators; | ||
|
||
public class FloatTimeSeriesAccumulator : BaseTimeSeriesAccumulator<float> | ||
{ | ||
public FloatTimeSeriesAccumulator(TimeSpan sampleInterval, int samplesCount = 0) : base(sampleInterval, samplesCount) | ||
{ | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace ManagedCode.TimeSeries.Summers; | ||
|
||
public class DoubleTimeSeriesSummer : BaseTimeSeriesSummer<double> | ||
{ | ||
public DoubleTimeSeriesSummer(TimeSpan sampleInterval, int samplesCount = 0) : base(sampleInterval, samplesCount) | ||
{ | ||
} | ||
|
||
protected override double Plus(double left, double right) | ||
{ | ||
return left + right; | ||
} | ||
|
||
public virtual void Increment() | ||
{ | ||
AddNewData(1); | ||
} | ||
|
||
public virtual void Decrement() | ||
{ | ||
AddNewData(-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace ManagedCode.TimeSeries.Summers; | ||
|
||
public class FloatTimeSeriesSummer : BaseTimeSeriesSummer<float> | ||
{ | ||
public FloatTimeSeriesSummer(TimeSpan sampleInterval, int samplesCount = 0) : base(sampleInterval, samplesCount) | ||
{ | ||
} | ||
|
||
protected override float Plus(float left, float right) | ||
{ | ||
return left + right; | ||
} | ||
|
||
public virtual void Increment() | ||
{ | ||
AddNewData(1); | ||
} | ||
|
||
public virtual void Decrement() | ||
{ | ||
AddNewData(-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters