0

In StreamInsight, many samples address the linq usages of count, sum, filter of a stream.

var cepStream = enumerable.ToPointStream(application, e =>  PointEvent<Car>.CreateInsert(new DateTimeOffset(e.TimeStamp, TimeSpan.Zero), e), AdvanceTimeSettings.IncreasingStartTime);

var step1 = from e in cepStream
                    where e.Color == "RedCar"
                    select e;

Have some difficulties to define query that extracts records occurred within certain time length. For example, step1 stores points events that are "RedCar", but how to extract events of two consecutive "RedCar"occurred within 10 mins??

Really got stuck here and any help is greatly appreciated!!

Chris
  • 259
  • 1
  • 4
  • 14

1 Answers1

1

To determine if 2 events occur within a certain time of each other, we have to manipulate their event lifetimes so that they are both valid at the same time. We can determine if 2 events are valid at the same time by using a join.

  1. Shift the event time for step1 as step2.

    var step2 = from e in step1.ShiftEventTime(e => TimeSpan.FromMinutes(10)) select e;

  2. Alter the event duration of step1 as step3.

    var step3 = from e in step1.AlterEventDuration(e => TimeSpan.FromMinutes(10)) select e;

  3. Join step2 and step3 as step4.

    var step4 = from l in step2 join r in step3 on l equals r select l;

Does that help?

TXPower275
  • 511
  • 2
  • 9
  • Hi TXPower275 That helps me a lot. Just wonder if checking endTime-startTime of Snapshot windows (PointEvents) is more common and easier? – Chris Mar 24 '13 at 02:41
  • Depends on what you are doing, but based on what you originally asked, I don't think it will help. A snapshot window is defined according to the start and end times of events in the stream instead of a fixed grid along the timeline. – TXPower275 Mar 24 '13 at 06:18
  • By using snapshot window I can calculate the time diff=endTime-startTime and check to see if this value is less than 10mins. If Im wrong, please point out. – Chris Mar 24 '13 at 21:33
  • You could do that procedurally with a UDO or UDSO if you didn't want to use the StreamInsight event processing engine. I'm partial to using the event processing engine when it comes to working with event start and end times. – TXPower275 Mar 25 '13 at 15:46
  • I have so many "HowTo" kind of questions of SI LINQ. Where can I find more LINQ examples and hot to accquire problem-solving skills? I searched around and only found a few examples and documentations. No books about SI yet are sold on amazon. – Chris Mar 30 '13 at 22:16
  • Have you seen the StreamInsight examples in LinqPad? If not, download a copy of LinqPad and download the samples. That'll help you with some of the query patterns. For other questions, post your questions here or the MSDN StreamInsight Forum and we'll try to help. – TXPower275 Apr 01 '13 at 03:32
  • Thank you TXPower275, I really dont know how to appreaciate your help more. I see quite a lot people use LinqPad for testing their LINQ. What is the advantage of using LinqPad over debugging on Visual Studio? – Chris Apr 01 '13 at 11:06
  • LinqPad lets you sandbox queries, dump values at different points, and iterate more rapidly than you otherwise would be able to with an application. – TXPower275 Apr 01 '13 at 14:10