The previous article introduced how to deal with transient and alarm flooding in the query mode. This article will introduce the trend discovery in streaminsight.
Test data preparation
To facilitate test query, we first prepare a static test data source:
VaR Sourcedata = New [] { New {Sourceid = "" , Value = 22 , Status = 1 , Timestamp = datetime. parse ( "10/23/2009 4:12:00" )}, New {Sourceid = "" , Value = 24 , Status = 0 , Timestamp = datetime. parse ( "10/23/2009 4:13:00" )}, New {Sourceid = "" , Value = 31 , Status = 1 , Timestamp = datetime. parse ( "10/23/2009 4:14:00" )}, New {Sourceid = "" , Value = 67 , Status = 0 , Timestamp = datetime. parse ( "10/23/2009 4:15:00" )}, New {Sourceid = "" , Value = 54 , Status = 0 , Timestamp = datetime. parse ( "10/23/2009 4:16:00" )}, New {Sourceid = "" , Value = 50 , Status = 1 , Timestamp = datetime. parse ( "10/23/2009 4:30:00" )}, New {Sourceid = "" , Value = 87 , Status = 0 , Timestamp = datetime. parse ( "10/23/2009 4:35:00" )},};
NextData SourceTransform to a complex event stream of point type:
VaRSource = sourcedata. topointstream (application, ev =>Pointevent. Createinsert (EV. timestamp. tolocaltime (), Ev ),Advancetimesettings. Strictlyincreasingstarttime );
Trend discovery
Q: How can we change the point-type event stream to an interval-type event stream and ensure that each interval contains the current point event and the previous point event?
It turns a point-type event stream into a continuous interval event stream (or "Signal Stream"), which can be achieved by editing events. Clipeventduration is a function that is closely related to editing events. It uses two streams as parameters and changes the lifetime of each event in the first stream according to the start time of the next matching event in the second stream.
To solve this problem, we can take three steps:
- Expand each vertex event and edit it to the next corresponding event;
- Move each interval event back to a scale to ensure that it can overlap with the next event;
- Join with the original event stream to put the loads of two point events together
The specific implementation is as follows:
VaRResult =FromSInSource. altereventduration (S =>Timespan. Maxvalue). clipeventduration (source, (S, e) => S. sourceid = E. sourceid). shifteventtime (E => E. starttime +Timespan. Fromticks (1 ))JoinEInSourceOnS. sourceidEqualsE. sourceidSelect New{Startvalue = S. Value, endvalue = E. Value, Delta = E. Value-S. Value, duration = E. timestamp-S. timestamp };
The result is as follows:
The next article describes how to detect exceptions in the streaminsight query mode.