public void Calculate_the_EWMA_for_multiple_variable_datastreams()
{
var streamingDataSet = ImmutableDictionary.Create<string, Metric>();
var usedMemory = new byte[0];
foreach (var i in Enumerable.Range(1, 50))
{
// wait a while between each message to give the metrics a chance to change
Thread.Sleep(100);
usedMemory =
usedMemory.Concat(Enumerable.Repeat(Convert.ToByte(ThreadLocalRandom.Current.Next(127)), 1024))
.ToArray();
var changes = _collector.Sample().Metrics.Select(latest =>
{
Metric previous;
if (!streamingDataSet.TryGetValue(latest.Name, out previous)) return latest;
if (latest.IsSmooth && latest.Value != previous.Value)
{
var updated = previous + latest;
updated.IsSmooth.ShouldBeTrue();
Assert.False(Math.Abs(updated.SmoothValue - previous.SmoothValue) < 0.01);
return updated;
}
else return latest;
});
streamingDataSet = streamingDataSet.Union(changes.ToDictionary(metric => metric.Name, metric => metric)).ToImmutableDictionary(pair => pair.Key, pair => pair.Value);
}
}