Chris
Chris

Reputation: 279

Linq usage in StreamInsight

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!!

Upvotes: 0

Views: 309

Answers (1)

TXPower275
TXPower275

Reputation: 511

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?

Upvotes: 1

Related Questions