public void FilterTest() { // Creates a basic filter for even-timestamped events, punctuations var inputSubject = new Subject <StreamEvent <int> >(); var qc = new QueryContainer(); var input = qc.RegisterInput(inputSubject, this.disorderPolicy, this.flushPolicy, this.punctuationPolicy, this.completedPolicy); IStreamable <Empty, int> query = input; // Add a no-op operator that isn't simply a batch-in-batch-out operator query = query.ClipEventDuration(IntervalLength); query = query.Where(this.FilterExpression); query = query.ClipEventDuration(IntervalLength); var filtered = qc.RegisterOutput(query).ForEachAsync(o => OnEgress(o)); var process = qc.Restore(); for (int i = 0; i < IngressEventCount; i++) { OnIngress(inputSubject, StreamEvent.CreateInterval(i, i + IntervalLength, i)); if (i > 0 && i % PunctuationGenerationPeriod == 0) { OnIngress(inputSubject, StreamEvent.CreatePunctuation <int>(i)); } // Make sure we don't have any pending events we expected to be egressed at this point Assert.IsTrue(this.expectedOutput.Count == 0); } OnCompleted(inputSubject); }
public void ExtendTest2() { // nothing interesting happens here var inputList = new[] { StreamEvent.CreateInterval(1, 5, "A"), StreamEvent.CreateInterval(2, 10, "A"), StreamEvent.CreateInterval(3, 8, "A"), StreamEvent.CreateInterval(4, 6, "A"), StreamEvent.CreateInterval(8, 9, "A"), }; var compareTo = new[] { StreamEvent.CreateInterval(1, 15, "A"), StreamEvent.CreateInterval(2, 20, "A"), StreamEvent.CreateInterval(3, 18, "A"), StreamEvent.CreateInterval(4, 16, "A"), StreamEvent.CreateInterval(8, 19, "A"), END }; var input = inputList.ToList().ToObservable().ToStreamable(); var outputStream = input.ExtendLifetime(10); Assert.IsTrue(outputStream.IsEquivalentTo(compareTo)); }
public void TestSumAggregate_Double() { /* * Time: 1 2 3 4 5 * Input: 1 |---------------| * 2 |-------| * 4 |---| * 8 |-------| * 16 |---| * Output: 3 15 25 1 0 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 1.0), StreamEvent.CreateInterval(1, 3, 2.0), StreamEvent.CreatePunctuation <double>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Sum(v => v); var correct = new[] { StreamEvent.CreateStart(1, 3.0), StreamEvent.CreateEnd(3, 1, 3.0), StreamEvent.CreateStart(3, 1.0), StreamEvent.CreateEnd(5, 3, 1.0), StreamEvent.CreatePunctuation <double>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void ExtendTest3() { var payload = StructTuple.Create("A", 3); var inputList = new[] { StreamEvent.CreateInterval(1, 5, payload), StreamEvent.CreateInterval(2, 10, payload), StreamEvent.CreateInterval(3, 8, payload), StreamEvent.CreateInterval(4, 6, payload), StreamEvent.CreateInterval(8, 9, payload), }; var compareTo = new StreamEvent <StructTuple <string, int> >[] { StreamEvent.CreateInterval(1, 15, payload), StreamEvent.CreateInterval(2, 20, payload), StreamEvent.CreateInterval(3, 18, payload), StreamEvent.CreateInterval(4, 16, payload), StreamEvent.CreateInterval(8, 19, payload), END2 }; var input = inputList.ToList().ToObservable().ToStreamable(); var outputStream = input.ExtendLifetime(10); Assert.IsTrue(outputStream.Select(r => r.Item1).IsEquivalentTo(compareTo.Select(r => r.IsData ? StreamEvent.CreateInterval(r.SyncTime, r.OtherTime, r.Payload.Item1) : END).ToArray())); }
public void PointAtEndTest2() { // nothing interesting happens here var inputList = new[] { StreamEvent.CreateInterval(1, 5, "A"), StreamEvent.CreateInterval(2, 10, "A"), StreamEvent.CreateInterval(3, 8, "A"), StreamEvent.CreateInterval(4, 6, "A"), StreamEvent.CreateInterval(8, 9, "A"), }; var compareTo = new[] { StreamEvent.CreatePoint(5, "A"), StreamEvent.CreatePoint(6, "A"), StreamEvent.CreatePoint(8, "A"), StreamEvent.CreatePoint(9, "A"), StreamEvent.CreatePoint(10, "A"), END }; var inputObservable = inputList.ToList().ToObservable(); var container = new QueryContainer(); var input = container.RegisterInput(inputObservable); var outputStream = input.PointAtEnd(); var output = container.RegisterOutput(outputStream); var result = new List <StreamEvent <string> >(); output.Subscribe(t => result.Add(t)); container.Restore(null); Assert.IsTrue(result.SequenceEqual(compareTo)); }
public static IEnumerable <StreamEvent <T> > ToEvents <T>(this IEnumerable <T> input, Func <T, long> vsSelector, Func <T, long> veSelector) { foreach (var e in input) { yield return(StreamEvent.CreateInterval(vsSelector(e), veSelector(e), e)); } }
private static void JoinIntervalsTest() { var input1 = new[] { StreamEvent.CreateInterval(100, 110, "A1"), StreamEvent.CreateInterval(101, 111, "B1"), StreamEvent.CreateInterval(102, 112, "C1"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var input2 = new[] { StreamEvent.CreateInterval(105, 115, "A2"), StreamEvent.CreateInterval(106, 116, "B2"), StreamEvent.CreateInterval(107, 117, "D2"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var inputStream1 = input1.ToCleanStreamable(); var inputStream2 = input2.ToCleanStreamable(); var outputStream = inputStream1.Join( inputStream2, l => (l != null ? l[0].ToString() : null), r => (r != null ? r[0].ToString() : null), (l, r) => l + "," + r); var correct = new[] { StreamEvent.CreateInterval(105, 110, "A1,A2"), StreamEvent.CreateInterval(106, 111, "B1,B2"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(outputStream.IsEquivalentTo(correct)); }
public void PointAtEndTest5() { var payload = StructTuple.Create("A", 3); var inputList = new[] { StreamEvent.CreateInterval(1, 5, payload), StreamEvent.CreateInterval(2, 10, payload), StreamEvent.CreateInterval(3, 8, payload), StreamEvent.CreateInterval(4, 6, payload), StreamEvent.CreateInterval(8, 9, payload), }; var compareTo = new StreamEvent <StructTuple <string, int> >[] { StreamEvent.CreatePoint(5, payload), StreamEvent.CreatePoint(6, payload), StreamEvent.CreatePoint(8, payload), StreamEvent.CreatePoint(9, payload), StreamEvent.CreatePoint(10, payload), END2 }; var input = inputList.ToList().ToObservable().ToStreamable(); var outputStream = input.PointAtEnd(); Assert.IsTrue(outputStream.Select(r => r.Item1).IsEquivalentTo(compareTo.Select(r => r.IsData ? StreamEvent.CreatePoint(r.SyncTime, r.Payload.Item1) : END).ToArray())); }
private static void JoinIntervalsTest(bool fixedInterval = false) { const long duration = 10; var input1 = new StreamEvent <string>[] { StreamEvent.CreateInterval(100, 100 + duration, "A1"), StreamEvent.CreateInterval(101, 101 + duration, "B1"), StreamEvent.CreateInterval(102, 102 + duration, "C1"), StreamEvent.CreateInterval(120, 120 + duration, "A3"), StreamEvent.CreateInterval(121, 121 + duration, "B3"), StreamEvent.CreateInterval(122, 122 + duration, "C3"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var input2 = new[] { StreamEvent.CreateInterval(105, 105 + duration, "A2"), StreamEvent.CreateInterval(106, 106 + duration, "B2"), StreamEvent.CreateInterval(107, 107 + duration, "D2"), StreamEvent.CreateInterval(125, 125 + duration, "A4"), StreamEvent.CreateInterval(126, 126 + duration, "B4"), StreamEvent.CreateInterval(127, 127 + duration, "C4"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var inputStream1 = input1.ToStreamable(); var inputStream2 = input2.ToStreamable(); if (fixedInterval) { inputStream1 = inputStream1.AlterEventDuration(duration); inputStream2 = inputStream2.AlterEventDuration(duration); } var outputStream = inputStream1.Join( inputStream2, l => (l != null ? l[0].ToString() : null), r => (r != null ? r[0].ToString() : null), (l, r) => $"{l},{r}"); var correct = new[] { StreamEvent.CreateInterval(105, 110, "A1,A2"), StreamEvent.CreateInterval(106, 111, "B1,B2"), StreamEvent.CreateInterval(125, 130, "A3,A4"), StreamEvent.CreateInterval(126, 131, "B3,B4"), StreamEvent.CreateInterval(127, 132, "C3,C4"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(outputStream.IsEquivalentTo(correct)); }
public void TestTopKRobsBug() { /* * Time: 1 2 3 4 5 * Input: 10 |-----------| * 20 |-----| * 30 |--| * 40 |-----| * 50 |--| * Output: 20 40 50 10 * 10 30 40 * 20 10 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 10), StreamEvent.CreateInterval(1, 3, 20), StreamEvent.CreateInterval(2, 3, 30), StreamEvent.CreateInterval(2, 4, 40), StreamEvent.CreateInterval(3, 4, 50), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Aggregate(a => a.TopK(v => v, 3), b => b.Count(), (a, b) => a.Select(v => v.Payload)).SelectMany(v => v); var correct = new[] { StreamEvent.CreateStart(1, 20), StreamEvent.CreateEnd(2, 1, 20), StreamEvent.CreateStart(1, 10), StreamEvent.CreateEnd(2, 1, 10), StreamEvent.CreateStart(2, 40), StreamEvent.CreateEnd(3, 2, 40), StreamEvent.CreateStart(2, 30), StreamEvent.CreateEnd(3, 2, 30), StreamEvent.CreateStart(2, 20), StreamEvent.CreateEnd(3, 2, 20), StreamEvent.CreateStart(3, 50), StreamEvent.CreateEnd(4, 3, 50), StreamEvent.CreateStart(3, 40), StreamEvent.CreateEnd(4, 3, 40), StreamEvent.CreateStart(3, 10), StreamEvent.CreateEnd(4, 3, 10), StreamEvent.CreateStart(4, 10), StreamEvent.CreateEnd(5, 4, 10), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
private void Sample() { var limit = duration * freq; for (int i = 0; i < limit; i++) { var sig = new Signal(this.counter, this.counter); data.Add(StreamEvent.CreateInterval(sig.ts, sig.ts + (1000 / freq), sig)); this.counter += (1000 / freq); } }
private static IStreamable <Empty, SensorReading> CreateStream(bool isRealTime) { if (isRealTime) { return(SimulateLiveData() .Select(r => StreamEvent.CreateInterval(r.Time, r.Time + 1, r)) .ToStreamable(OnCompletedPolicy.EndOfStream(), PeriodicPunctuationPolicy.Count(1))); } return(HistoricData.ToObservable().Select(r => StreamEvent.CreateInterval(r.Time, r.Time + 1, r)).ToStreamable(OnCompletedPolicy.None())); }
private static void LeftAntiSemiJoinIntervalsTest() { var input1 = new[] { StreamEvent.CreateInterval(100, 101, "A3"), StreamEvent.CreateInterval(100, 110, "A1"), StreamEvent.CreateInterval(101, 105, "A2"), StreamEvent.CreateInterval(109, 112, "A4"), StreamEvent.CreateInterval(102, 112, "B1"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var input2 = new[] { StreamEvent.CreateInterval(101, 103, "A"), StreamEvent.CreateInterval(106, 108, "A"), StreamEvent.CreateInterval(106, 109, "A"), StreamEvent.CreateInterval(100, 110, "C"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; var inputStream1 = input1.ToCleanStreamable(); var inputStream2 = input2.ToCleanStreamable(); var outputStream = inputStream1.WhereNotExists( inputStream2, l => (l != null ? l[0].ToString() : null), r => (r != null ? r[0].ToString() : null)); var correct = new[] { StreamEvent.CreateStart(100, "A1"), StreamEvent.CreateEnd(101, 100, "A1"), StreamEvent.CreateStart(103, "A1"), StreamEvent.CreateEnd(106, 103, "A1"), StreamEvent.CreateInterval(109, 110, "A1"), StreamEvent.CreateInterval(103, 105, "A2"), StreamEvent.CreateInterval(100, 101, "A3"), StreamEvent.CreateInterval(109, 112, "A4"), StreamEvent.CreateStart(102, "B1"), StreamEvent.CreateEnd(112, 102, "B1"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(outputStream.IsEquivalentTo(correct)); }
private static void ArrayBasedIngressExample() { // Create the first array segment. StreamEvent <Point>[] values1 = { StreamEvent.CreateInterval(1, 10, new Point { x = 1, y = 2 }), StreamEvent.CreateInterval(2, 10, new Point { x = 2, y = 4 }), StreamEvent.CreateInterval(3, 10, new Point { x = 3, y = 6 }), StreamEvent.CreateInterval(4, 10, new Point { x = 4, y = 8 }), StreamEvent.CreateInterval(5, 10, new Point { x = 5, y = 10 }) }; // Create the second array segment. StreamEvent <Point>[] values2 = { StreamEvent.CreateInterval(6, 10, new Point { x = 6, y = 12 }), StreamEvent.CreateInterval(7, 10, new Point { x = 7, y = 14 }), StreamEvent.CreateInterval(8, 10, new Point { x = 8, y = 16 }), StreamEvent.CreateInterval(9, 10, new Point { x = 9, y = 18 }), StreamEvent.CreatePunctuation <Point>(StreamEvent.InfinitySyncTime) }; var segment1 = new ArraySegment <StreamEvent <Point> >(values1); var segment2 = new ArraySegment <StreamEvent <Point> >(values2); var segments = new ArraySegment <StreamEvent <Point> >[] { segment1, segment2 }; // Array-based ingress. var input = segments.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static IStreamable <Empty, SensorReading> CreateStream(bool isRealTime) { if (isRealTime) { return(SimulateLiveData() .Select(r => StreamEvent.CreateInterval(r.Time, r.Time + 1, r)) .ToStreamable()); } return(HistoricData .ToObservable() .Select(r => StreamEvent.CreateInterval(r.Time, r.Time + 1, r)) .ToStreamable()); }
private static void WhereExample10() { StreamEvent <ValueTuple <int, int> >[] values2 = { StreamEvent.CreateInterval(1, 10, new ValueTuple <int, int> { Item1 = 1, Item2 = 2 }), StreamEvent.CreateInterval(2, 10, new ValueTuple <int, int> { Item1 = 2, Item2 = 4 }), StreamEvent.CreateInterval(3, 10, new ValueTuple <int, int> { Item1 = 3, Item2 = 6 }), StreamEvent.CreateInterval(4, 10, new ValueTuple <int, int> { Item1 = 4, Item2 = 8 }), StreamEvent.CreateInterval(5, 10, new ValueTuple <int, int> { Item1 = 5, Item2 = 10 }), StreamEvent.CreateInterval(6, 10, new ValueTuple <int, int> { Item1 = 6, Item2 = 12 }), StreamEvent.CreateInterval(7, 10, new ValueTuple <int, int> { Item1 = 7, Item2 = 14 }), StreamEvent.CreateInterval(8, 10, new ValueTuple <int, int> { Item1 = 8, Item2 = 16 }), StreamEvent.CreateInterval(9, 10, new ValueTuple <int, int> { Item1 = 9, Item2 = 18 }), StreamEvent.CreatePunctuation <ValueTuple <int, int> >(StreamEvent.InfinitySyncTime) }; var input = values2.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Apply a filter on one field. Console.WriteLine(); Console.WriteLine("Query: input.Where(p => p.x > 5)"); var output = input.Where(p => p.Item1 > 5); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
public static StreamEvent <int>[] Get() { return(new[] { StreamEvent.CreateInterval(1, 10, 1), StreamEvent.CreateInterval(2, 10, 2), StreamEvent.CreateInterval(3, 10, 3), StreamEvent.CreateInterval(4, 10, 4), StreamEvent.CreateInterval(5, 10, 5), StreamEvent.CreateInterval(6, 10, 6), StreamEvent.CreateInterval(7, 10, 7), StreamEvent.CreateInterval(8, 10, 8), StreamEvent.CreateInterval(9, 10, 9), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }); }
private void EquiJoinWorker(long?constantDuration = null) { var left = new[] { StreamEvent.CreateStart(0, 100), StreamEvent.CreateStart(0, 110), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var right = new[] { StreamEvent.CreateStart(0, 200), StreamEvent.CreateStart(0, 210), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); if (constantDuration.HasValue) { left = left.AlterEventDuration(constantDuration.Value); right = right.AlterEventDuration(constantDuration.Value); } var output = new List <StreamEvent <(int, int)> >(); left.Join(right, (l, r) => CreateValueTuple(l, r)) .ToStreamEventObservable() .ForEachAsync(e => output.Add(e)) .Wait(); var correct = new[] { StreamEvent.CreateStart(0, ValueTuple.Create(110, 200)), StreamEvent.CreateStart(0, ValueTuple.Create(100, 200)), StreamEvent.CreateStart(0, ValueTuple.Create(110, 210)), StreamEvent.CreateStart(0, ValueTuple.Create(100, 210)), StreamEvent.CreatePunctuation <ValueTuple <int, int> >(StreamEvent.InfinitySyncTime) }; if (constantDuration.HasValue && constantDuration.Value != StreamEvent.InfinitySyncTime) { correct = correct .Select(e => e.IsPunctuation ? e : StreamEvent.CreateInterval(e.StartTime, e.StartTime + constantDuration.Value, e.Payload)) .ToArray(); } Assert.IsTrue(correct.SequenceEqual(output)); }
private static void ArrayBasedEgressExample() { StreamEvent <Point>[] values = { StreamEvent.CreateInterval(1, 10, new Point { x = 1, y = 2 }), StreamEvent.CreateInterval(2, 10, new Point { x = 2, y = 4 }), StreamEvent.CreateInterval(3, 10, new Point { x = 3, y = 6 }), StreamEvent.CreateInterval(4, 10, new Point { x = 4, y = 8 }), StreamEvent.CreateInterval(5, 10, new Point { x = 5, y = 10 }), StreamEvent.CreateInterval(6, 10, new Point { x = 6, y = 12 }), StreamEvent.CreateInterval(7, 10, new Point { x = 7, y = 14 }), StreamEvent.CreateInterval(8, 10, new Point { x = 8, y = 16 }), StreamEvent.CreateInterval(9, 10, new Point { x = 9, y = 18 }), StreamEvent.CreatePunctuation <Point>(StreamEvent.InfinitySyncTime) }; var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Array-based egress. Console.WriteLine(); Console.WriteLine("Output ="); input.ToStreamEventArrayObservable().ForEachAsync( e => e.ToObservable().ForEachAsync(w => Console.WriteLine(w))).Wait(); Console.ReadLine(); }
public void TestWhereAggregate() { /* * Time: 1 2 3 4 5 * Input: 10 |-------| * 20 |---| * 30 |-| * 40 |---| * 50 |-| * Output: 2 4 3 1 0 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 10), StreamEvent.CreateInterval(1, 3, 20), StreamEvent.CreateInterval(2, 3, 30), StreamEvent.CreateInterval(2, 4, 40), StreamEvent.CreateInterval(3, 4, 50), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Aggregate( a => a.Count(), b => b.Where(v => v >= 30).Count(), b => b.Where(v => v >= 30).Where(v => v <= 40).Count(), (a, b, c) => (a * 100) + (b * 10) + c); var correct = new[] { StreamEvent.CreateStart <ulong>(1, 200), StreamEvent.CreateEnd <ulong>(2, 1, 200), StreamEvent.CreateStart <ulong>(2, 422), StreamEvent.CreateEnd <ulong>(3, 2, 422), StreamEvent.CreateStart <ulong>(3, 321), StreamEvent.CreateEnd <ulong>(4, 3, 321), StreamEvent.CreateStart <ulong>(4, 100), StreamEvent.CreateEnd <ulong>(5, 4, 100), StreamEvent.CreatePunctuation <ulong>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void PercentileContAggregate() { /* * Time: 1 2 3 4 5 * Input: 10 |-----------| * 20 |-----| * 30 |--| * 40 |-----| * 50 |--| * Output: 16 28 42 10 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 10), StreamEvent.CreateInterval(1, 3, 20), StreamEvent.CreateInterval(2, 3, 30), StreamEvent.CreateInterval(2, 4, 40), StreamEvent.CreateInterval(3, 4, 50), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var correct = new[] { StreamEvent.CreateStart(1, 16.0), StreamEvent.CreateEnd(2, 1, 16.0), StreamEvent.CreateStart(2, 28.0), StreamEvent.CreateEnd(3, 2, 28.0), StreamEvent.CreateStart(3, 42.0), StreamEvent.CreateEnd(4, 3, 42.0), StreamEvent.CreateStart(4, 10.0), StreamEvent.CreateEnd(5, 4, 10.0), StreamEvent.CreatePunctuation <double>(StreamEvent.InfinitySyncTime) }; var output = input.Aggregate(w => w.PercentileContinuous(0.6, e => e)); Assert.IsTrue(output.IsEquivalentTo(correct)); // And with reverse order... output = input.Aggregate(w => w.PercentileContinuous((x, y) => y.CompareTo(x), 0.4, e => e)); Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestAverageAggregate_Double() { /* * Time: 1 2 3 4 5 * Input: 1 |---------------| * 2 |-------| * 4 |---| * 8 |-------| * 16 |---| * Output: 3 15 25 1 * - -- -- - * 2 4 3 1 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 1d), StreamEvent.CreateInterval(1, 3, 2d), StreamEvent.CreateInterval(2, 3, 4d), StreamEvent.CreateInterval(2, 4, 8d), StreamEvent.CreateInterval(3, 4, 16d), StreamEvent.CreatePunctuation <double>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Average(v => v); var correct = new[] { StreamEvent.CreateStart(1, 3.0 / 2), StreamEvent.CreateEnd(2, 1, 3.0 / 2), StreamEvent.CreateStart(2, 15.0 / 4), StreamEvent.CreateEnd(3, 2, 15.0 / 4), StreamEvent.CreateStart(3, 25.0 / 3), StreamEvent.CreateEnd(4, 3, 25.0 / 3), StreamEvent.CreateStart(4, 1.0), StreamEvent.CreateEnd(5, 4, 1.0), StreamEvent.CreatePunctuation <double>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestCountAggregate_WithNulls() { /* * Time: 1 2 3 4 5 * Input: 10 |-------| * 20 |---| * 30 |-| * 40 |---| * 50 |-| * Output: 2 4 3 1 0 */ var input = new[] { StreamEvent.CreateInterval(1, 5, "10"), StreamEvent.CreateInterval <string>(1, 3, null), StreamEvent.CreateInterval(2, 3, "30"), StreamEvent.CreateInterval(2, 4, "40"), StreamEvent.CreateInterval(3, 4, "50"), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Count(); var correct = new[] { StreamEvent.CreateStart <ulong>(1, 2), StreamEvent.CreateEnd <ulong>(2, 1, 2), StreamEvent.CreateStart <ulong>(2, 4), StreamEvent.CreateEnd <ulong>(3, 2, 4), StreamEvent.CreateStart <ulong>(3, 3), StreamEvent.CreateEnd <ulong>(4, 3, 3), StreamEvent.CreateStart <ulong>(4, 1), StreamEvent.CreateEnd <ulong>(5, 4, 1), StreamEvent.CreatePunctuation <ulong>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestMaxAggregate() { /* * Time: 1 2 3 4 5 * Input: 10 |-----------| * 20 |-----| * 30 |--| * 40 |-----| * 50 |--| * Output: 10 40 50 10 0 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 10), StreamEvent.CreateInterval(1, 3, 20), StreamEvent.CreateInterval(2, 3, 30), StreamEvent.CreateInterval(2, 4, 40), StreamEvent.CreateInterval(3, 4, 50), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Max(v => v); var correct = new[] { StreamEvent.CreateStart(1, 20), StreamEvent.CreateEnd(2, 1, 20), StreamEvent.CreateStart(2, 40), StreamEvent.CreateEnd(3, 2, 40), StreamEvent.CreateStart(3, 50), StreamEvent.CreateEnd(4, 3, 50), StreamEvent.CreateStart(4, 10), StreamEvent.CreateEnd(5, 4, 10), StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestSumAggregate_Long() { /* * Time: 1 2 3 4 5 * Input: 1 |---------------| * 2 |-------| * 4 |---| * 8 |-------| * 16 |---| * Output: 3 15 25 1 0 */ var input = new[] { StreamEvent.CreateInterval <long>(1, 5, 1), StreamEvent.CreateInterval <long>(1, 3, 2), StreamEvent.CreateInterval <long>(2, 3, 4), StreamEvent.CreateInterval <long>(2, 4, 8), StreamEvent.CreateInterval <long>(3, 4, 16), StreamEvent.CreatePunctuation <long>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Sum(v => v); var correct = new[] { StreamEvent.CreateStart <long>(1, 3), StreamEvent.CreateEnd <long>(2, 1, 3), StreamEvent.CreateStart <long>(2, 15), StreamEvent.CreateEnd <long>(3, 2, 15), StreamEvent.CreateStart <long>(3, 25), StreamEvent.CreateEnd <long>(4, 3, 25), StreamEvent.CreateStart <long>(4, 1), StreamEvent.CreateEnd <long>(5, 4, 1), StreamEvent.CreatePunctuation <long>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestSumAggregate_Decimal() { /* * Time: 1 2 3 4 5 * Input: 1 |---------------| * 2 |-------| * 4 |---| * 8 |-------| * 16 |---| * Output: 3 15 25 1 0 */ var input = new[] { StreamEvent.CreateInterval(1, 5, 1.5m), StreamEvent.CreateInterval(1, 3, 2m), StreamEvent.CreateInterval(2, 3, 3.6m), StreamEvent.CreateInterval(2, 4, 8.2m), StreamEvent.CreateInterval(3, 4, 16m), StreamEvent.CreatePunctuation <decimal>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Sum(v => v); var correct = new[] { StreamEvent.CreateStart(1, 3.5m), StreamEvent.CreateEnd(2, 1, 3.5m), StreamEvent.CreateStart(2, 15.3m), StreamEvent.CreateEnd(3, 2, 15.3m), StreamEvent.CreateStart(3, 25.7m), StreamEvent.CreateEnd(4, 3, 25.7m), StreamEvent.CreateStart(4, 1.5m), StreamEvent.CreateEnd(5, 4, 1.5m), StreamEvent.CreatePunctuation <decimal>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void TestCountNotNullAggregate_AllNulls() { /* * Time: 1 2 3 4 5 * Input: 10 |-------| * 20 |---| * 30 |-| * 40 |---| * 50 |-| * Output: 0 0 0 0 0 */ var input = new[] { StreamEvent.CreateInterval <string>(1, 5, null), StreamEvent.CreateInterval <string>(1, 3, null), StreamEvent.CreateInterval <string>(2, 3, null), StreamEvent.CreateInterval <string>(2, 4, null), StreamEvent.CreateInterval <string>(3, 4, null), StreamEvent.CreatePunctuation <string>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.CountNotNull(v => v); var correct = new[] { StreamEvent.CreateStart <ulong>(1, 0), StreamEvent.CreateEnd <ulong>(2, 1, 0), StreamEvent.CreateStart <ulong>(2, 0), StreamEvent.CreateEnd <ulong>(3, 2, 0), StreamEvent.CreateStart <ulong>(3, 0), StreamEvent.CreateEnd <ulong>(4, 3, 0), StreamEvent.CreateStart <ulong>(4, 0), StreamEvent.CreateEnd <ulong>(5, 4, 0), StreamEvent.CreatePunctuation <ulong>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
private static IStreamable <Empty, SensorReading> CreateStream() { return(ToObservableInterval( new[] { new SensorReading { Time = 1, Value = 0 }, new SensorReading { Time = 2, Value = 20 }, new SensorReading { Time = 3, Value = 15 }, new SensorReading { Time = 4, Value = 30 }, new SensorReading { Time = 5, Value = 45 }, // here we crossed the threshold upward new SensorReading { Time = 6, Value = 50 }, new SensorReading { Time = 7, Value = 30 }, // here we crossed downward // **** note that the current query logic only detects upward swings. ****/ new SensorReading { Time = 8, Value = 35 }, new SensorReading { Time = 9, Value = 60 }, // here we crossed upward again new SensorReading { Time = 10, Value = 20 } }, TimeSpan.FromMilliseconds(1000)) .Select(r => StreamEvent.CreateInterval(r.Time, r.Time + 1, r)) .ToStreamable()); }
public void TestSumAggregate_Float() { var input = new[] { StreamEvent.CreateInterval(1, 5, 1.0f), StreamEvent.CreateInterval(1, 3, 2.0f), StreamEvent.CreatePunctuation <float>(StreamEvent.InfinitySyncTime) }.ToStreamable(); var output = input.Sum(v => v); var correct = new[] { StreamEvent.CreateStart(1, 3.0f), StreamEvent.CreateEnd(3, 1, 3.0f), StreamEvent.CreateStart(3, 1.0f), StreamEvent.CreateEnd(5, 3, 1.0f), StreamEvent.CreatePunctuation <float>(StreamEvent.InfinitySyncTime) }; Assert.IsTrue(output.IsEquivalentTo(correct)); }
public void ExtendTestNegative5() { var payload = StructTuple.Create("A", 3); // nothing interesting happens here var inputList = new[] { StreamEvent.CreateInterval(1, 15, payload), StreamEvent.CreateInterval(2, 20, payload), StreamEvent.CreateInterval(3, 18, payload), StreamEvent.CreateInterval(4, 16, payload), StreamEvent.CreateInterval(8, 19, payload), }; var compareTo = new[] { StreamEvent.CreateInterval(2, 5, payload), END2 }; var input = inputList.ToList().ToObservable().ToStreamable(); var outputStream = input.ExtendLifetime(-15); Assert.IsTrue(outputStream.Select(r => r.Item1).IsEquivalentTo(compareTo.Select(r => r.IsData ? StreamEvent.CreateInterval(r.SyncTime, r.OtherTime, r.Payload.Item1) : END).ToArray())); }