public async Task MultipleProducersBufferTest(params int[] delays) { int N = delays.Length; Task[] producers = new Task[N]; var finalBlock = new BufferBlock <int>(new() { BoundedCapacity = 1 }); for (int i = 0; i < N; i++) { var block = new DelayBlock <int>(delays[i]); block.LinkTo(finalBlock, new() { PropagateCompletion = false }); var t = block.ProduceDataAsync(i, 300).ContinueWith(x => block.Complete()); producers[i] = block.Completion; } var keys = Enumerable.Range(0, N).ToArray(); var measTask = finalBlock.MeasureDataAsync(keys); var prods = Task.WhenAll(producers).ContinueWith(x => finalBlock.Complete()); var meas = await measTask; var delaysCollection = meas.Delays.Values.ToArray(); OxyPlotExporter.ToPNG("MultipleProducersBufferTest.png", $"target delays ({string.Join(", ", delays)}) ms", delaysCollection); foreach (var kvp in meas.Delays) { var calcDelay = delays[kvp.Key]; _helper.AssertStats(kvp.Value, calcDelay, calcDelay * 0.1, skip: 10); } }
public DelayBlock <MessageType> CreateDelayBlock <MessageType>(double IntervalMS, string name) { var block = new DelayBlock <MessageType>(EventProcessor, IntervalMS); SetDebugName(block, name); return(block); }
public async Task SingleDelayBlockTest(int delay) { var block = new DelayBlock <int>(delay); var t = block.ProduceDataAsync(0, 1500).ContinueWith(x => block.Complete()); var res = await block.MeasureDataAsync(); var delays = res.Delays[-1]; OxyPlotExporter.ToPNG($"SingleDelayBlockTest_{delay}.png", $"target delay: {delay} ms", delays); _helper.AssertStats(delays, delay, delay + 10, skip: 3); }
public ObjectModel(double k, double T1, double T2, double delayTime, double noize, double dt) { K10 = new GainBlock(k); K11 = new GainBlock(k); K12 = new GainBlock(k); K13 = new GainBlock(k); K14 = new GainBlock(k); K15 = new GainBlock(k); AperiodicBlockZ1 = new AperiodicBlock(T1, dt); AperiodicBlockZ2 = new AperiodicBlock(T2, dt); Z2Delay = new DelayBlock(delayTime, dt); Z2Noize = new NoizeBlock(noize); Z1Delay = new DelayBlock(delayTime, dt); Z1Noize = new NoizeBlock(noize); }
public async Task ParallelOneToOneDelayBlock(params int[] delays) { int N = delays.Length; Task <MeasurmentsData>[] measurments = new Task <MeasurmentsData> [N]; for (int i = 0; i < N; i++) { var delay = delays[i]; var block = new DelayBlock <int>(delay); measurments[i] = block.MeasureDataAsync(); var t = block.ProduceDataAsync(i, 100).ContinueWith(x => block.Complete()); } var measCollection = await Task.WhenAll(measurments); var statCollection = measCollection.Select(x => x.Delays[-1]).ToArray(); OxyPlotExporter.ToPNG("ParallelOneToOneDelayBlock.png", $"target delays ({string.Join(", ", delays)}) ms", statCollection); foreach (var(delay, st) in delays.Zip(statCollection, (d, s) => (d, s))) { _helper.AssertStats(st, delay, delay * 0.1, skip: 10); } }