[Original] streaminsight query series (18)-query mode trend discovery

Source: Internet
Author: User

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:

    1. Expand each vertex event and edit it to the next corresponding event;
    2. Move each interval event back to a scale to ensure that it can overlap with the next event;
    3. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.