none
How can I take X seconds of events before and X second after a trigger event?

    Question

  • Hi,
    My purpose is to have in output of a query 5 seconds before and 5 seconds after a trigger event...
    I wrote this code...

    // Get signal stream
    CepStream<SignalLog> SignalStream = this.GetCepStream("Temp1");
    
    // Get Reference stream
    CepStream<SignalLog> ReferenceStream1 = this.GetCepStream("Trigger");
    
    // Convert the point events from the reference stream into edge events
    CepStream<SignalLog> ReferenceCepStreamEdged1 = from e in ReferenceStream1
                            .AlterEventDuration(e => TimeSpan.MaxValue)
                            .ClipEventDuration(ReferenceStream1, (e1, e2) => (e1.SignalID == e2.SignalID))
                            select e;
    
    // Query for TimeStamp of trigger event
     var QueryTimeStamp =
                    from Trigger in ReferenceCepStreamEdged1
                    where BitConverter.ToInt32(Trigger.SignalsLogValue, 0) == 1
                    select Trigger.SignalsLogTimeStamp;
    
    // return stream
    return from Temperature in SignalStream
           from TimeStamp in QueryTimeStamp
           where Temperature.SignalsLogTimeStamp >= TimeStamp - TimeSpan.TicksPerSecond * 5 || Temperature.SignalsLogTimeStamp <= TimeStamp + TimeSpan.TicksPerSecond * 5
           select new SignalLog() { SignalID = this.SignalID, SignalsLogTimeStamp = Temperature.SignalsLogTimeStamp, SignalsLogValue = Temperature.SignalsLogValue };

    but clearly the last "where" condition didn't work for "past" events...

    Any suggestion?

    thanks

    Gianluca




    • Edited by BosePR Friday, June 14, 2013 3:50 PM
    Friday, June 14, 2013 3:49 PM

Answers

  • OK, you'll do this by altering durations and joining.

    So ... you have an "Alarm Value" stream. These are your raw alarms and likely going to a sink, correct?

    So, send to the sink BUT also then extend the duration for an additional 5 seconds (AlterEventDuration). Note that this is AFTER it goes to your output.

    For your data stream, extend the event duration for an additional 5 seconds. Join with your alarm stream. You'll then get the events from 5 seconds before and 5 seconds after. In this case, your start time will be the event time; you don't need anything additional in the payload.


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    • Marked as answer by BosePR Tuesday, June 18, 2013 9:40 AM
    Monday, June 17, 2013 7:02 PM
    Moderator

All replies

  • What, exactly, are you trying to accomplish?

    Also, you really shouldn't be using timestamps in your payloads for query filters ... use the temporal properties of the events. Every event has a start and end time (yes, even point events) and you can manipulate those temporal headers with operators like AlterEventDuration. This is how you filter/select/join based on timestamps.

    It's very different from how we traditionally do queries in relational systems where time is an attribute. In StreamInsight temporal queries, time is a dimension.


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    Saturday, June 15, 2013 1:49 PM
    Moderator
  • Hi,
    I have a principal stream of data in a query and another stream of alarm data in a second query.

    the second stream it's my reference signal and so i trasformed it in edge event for capture only "alarm value".

    at this time, what i want... if it's possible, is a third query that has in output 5 second of data before and 5 seconds of data after the timestamp of the alarm event.

    Thanks
    Gianluca

    Monday, June 17, 2013 10:56 AM
  • OK, you'll do this by altering durations and joining.

    So ... you have an "Alarm Value" stream. These are your raw alarms and likely going to a sink, correct?

    So, send to the sink BUT also then extend the duration for an additional 5 seconds (AlterEventDuration). Note that this is AFTER it goes to your output.

    For your data stream, extend the event duration for an additional 5 seconds. Join with your alarm stream. You'll then get the events from 5 seconds before and 5 seconds after. In this case, your start time will be the event time; you don't need anything additional in the payload.


    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)


    Ruminations of J.net


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    • Marked as answer by BosePR Tuesday, June 18, 2013 9:40 AM
    Monday, June 17, 2013 7:02 PM
    Moderator