Implementation of Causal or temporal events.

已答覆 Implementation of Causal or temporal events.

  • Thursday, February 21, 2013 4:40 AM
     
     

    Hi,

    Are there any examples in StreamInsight showing the causal or temporal events implementation?

    Any references or ideas would be of great help.

    Thanks,

    YogiP

All Replies

  • Thursday, February 21, 2013 2:28 PM
     
     

    The biggest collection of StreamInsight examples is located on CodePlex here: http://streaminsight.codeplex.com/. You can also find more query pattern type samples in LinqPad that are easily downloadable through LinqPad's "Download/import more samples" link. LinqPad is available here: http://www.linqpad.net/.

    Does that help or am I misunderstanding what you are looking for?

  • Monday, February 25, 2013 4:34 AM
     
     

    Hi TXPower125,

    Thanks a lot for the references. I had downloaded a few samples from codeplex before. Those are really good examples. But, i was not able to find an example with the demonstration of some patterns like Causal event or Temporal event. For example: In a tool like Esper, they have out-of-box implementation for some patterns like:

    For Causal, they have a '->' symbol which indicates a 'followed by' case

    For Temporal, 'every' and 'timer' keywords are used.

    I was looking for something similar in StreamInsight, which i did not see. So, i am searching for some examples here which shows any implementations of such events.

    Thanks,

    YogiP 

  • Monday, February 25, 2013 3:21 PM
     
     Answered

    Ok, this makes sense now. Query logic in StreamInsight is done with LINQ. There are not many built in operators for those types of patterns, but LINQ's composable nature let's us build macros to accomplish this.

    For the example of A not followed by B within 5 minues, take a look at the "18. Not Followed By Macro" sample in the 101 StreamInsight Queries  that can be downloaded within LinqPad.

    • Marked As Answer by YogiP Tuesday, February 26, 2013 4:26 AM
    •  
  • Tuesday, February 26, 2013 4:26 AM
     
     

    Thanks a lot TXPower125, that was very helpful. I downloaded LINQPAD and the streaminsight LINQ samples from LINQPAD.

    I am going through the sample 101 StreamInsight queries package. Will get back in case of any doubts.

    Thanks & Regards,

    YogiP

  • Tuesday, February 26, 2013 6:24 AM
     
     

    Hi TXPower125,

    I just went through the example "Not Followed By Macro" which detects an event that was not followed by another event. Any idea how can i tweak it to do the opposite i.e detect an event that caused some other event within a specified timespan.

    For Example: Event A happened and this caused Event B to happen within a span of 10 seconds.

    Thanks & Regards,

    YogiP

  • Tuesday, February 26, 2013 7:11 AM
     
      Has Code

    Hi TXPower125,

    Another query relating to temporal event. I followed the example under Basic Patterns example "

    How do I detect if A, B and C occur within 5 minutes of each other?

    "

    I created my own sample with my own data. I wrote the following query:

    var queryTemporalEvent = from e1 in inputTemporalEvent.AlterEventDuration(e => TimeSpan.FromSeconds(20)) from e2 in inputTemporalEvent.AlterEventDuration(e => TimeSpan.FromSeconds(20)) where (Convert.ToDouble(e1.A) > 10 && Convert.ToDouble(e1.B) > 15) && (Convert.ToDouble(e2.A) > 10 && Convert.ToDouble(e2.B) > 15) select new { Temporal_A_1 = e1.A, Temporal_B_1 = e1.B, Temporal_A_2 = e2.A, Temporal_B_2 = e2.B};

    I am getting the output as:

    CTI - 06:35:00.046
    CTI - 06:35:01.060
    CTI - 06:35:02.073
    CTI - 06:35:03.087
    CTI - 06:35:04.101
    CTI - 06:35:05.115
    CTI - 06:35:06.130
    POINT(06:35:07.144)
            Temporal_A_1:                13
            Temporal_A_2:                75
            Temporal_B_1:           73
            Temporal_B_2:           71
    POINT(06:35:07.144)
            Temporal_A_1:                75
            Temporal_A_2:                13
            Temporal_B_1:           71
            Temporal_B_2:           73
    POINT(06:35:07.144)
            Temporal_A_1:                75
            Temporal_A_2:                75
            Temporal_B_1:           71
            Temporal_B_2:           71
    CTI - 06:35:07.144
    CTI - 06:35:08.158
    CTI - 06:35:09.172
    CTI - 06:35:10.186
    CTI - 06:35:11.200
    CTI - 06:35:12.214
    CTI - 06:35:13.228

    I am not sure why it is showing me 3 points at a time. I want only this:

    POINT(06:35:07.144)
            Temporal_A_1:                13
            Temporal_A_2:                75
            Temporal_B_1:           73
            Temporal_B_2:           71

    But it is swapping and showing it again. Any ideas what i am missing in the query?

    Thanks & Regards,

    Yogi P

  • Tuesday, February 26, 2013 5:17 PM
     
      Has Code

    Off the top of my head, I would say that it looks like some of your events are overlapping when you alter the event duration. Remember that your streams join on not just criteria you specify (ON or WHERE clauses) but also in time.

    Consider the following events:
    StartTime, Id, Value
    00, A, 23
    01, A, 24
    02, A, 25
    05, A, 60
    23, A, 34

    If I extend each event by 20 seconds, my stream will look like this:
    StartTime, EndTime, Id, Value
    00, 20, A, 23
    01, 21, A, 24
    02, 22, A, 25
    05, 25, A, 60
    23, 43, A, 34

    As you can see, there are more than 1 instance of A events that are valid at the same time. You can fix this by clipping the event duration.

    var stream = from s in sourceStream
    .AlterEventDuration(e => TimeSpan.FromSeconds(20))
    .ClipEventDuration(sourceStream, (e1, e2) => e1.Id == e2.Id)
    select s;

    That would give you something like the following:
    StartTime, EndTime, Id, Value
    00, 01.9, A, 23
    01, 02.9, A, 24
    02, 04.9, A, 25
    05, 22.9, A, 60
    23, 43, A, 34

    Does that help?

  • Tuesday, February 26, 2013 5:22 PM
     
     
    1. Get/Create a stream of A events.
    2. Get/Create a stream of B events.
    3. Extend the event lifetime of the A events by 10 seconds.
    4. Optionally, clip the event duration of the A events to itself so that only 1 instance of an A event is valid at any given time.
    5. Join the A event stream to the B event stream.
    6. Project the result into your payload of choice.
    7. Stream on...