2011-05-27 73 views
0

我開始使用StreamInsight,並將其用作wcf服務。 我已經試過在「微軟StreamInsight查詢搭便車指南」中尋求幫助,並試用了codeplex中的示例以及示例。StreamInsight - 定義正確窗口的問題

我的問題是這樣的:

我的活動飼料生產與AlertEvent的適配器:

public sealed class AlertEvent 
{ 
    public DateTime Date { get; set; } 
    public long IDGroup { get; set; } 
    public bool IsToNormalize { get; set; } 
    public bool IsError { get; set; } 
} 

當AlertEvent具有ISERROR =假,標誌IsToNormalize是真實的;

我試圖實現的行爲是當我收到一個帶有IsError的流時,我想看看在接下來的'x'分鐘內是否到達任何帶有IsToNormalize的alertEvent。然後我發送輸出開始搜索的IsError AlarmEvent。

我所做的是,當我收到一個對應於過濾器的輸入時,我將其生命週期延長到'x'分鐘並創建一個TumblingWindow,以查看在該時期另一個AlertEvent是否到達另一個標誌(使用一個ExtensionMethod遍歷窗口中的所有有效載荷)。

var stream= from item in input 
      where item.IsError 
      group item by item.IdGroup into eachGroup 
      from window in eachDigital.AlterEventDuration(e => TimeSpan.FromMinutes((double)1.5)).TumblingWindow(TimeSpan.FromSeconds(15), HoppingWindowOutputPolicy.ClipToWindowEnd) 
      select new 
      { 
       Id = eachDigital.Key, 
       NormEvents = window.HasNormalizationEvents(), 
       Count = window.Count() 
      }; 

然後,要獲得觸發TumblingWindow的AlarmEvent,我已經與原始輸入進行了連接。

var resultStream = from e1 in stream 
        join e2 in input 
        on e1.Id equals e2.DigitalTag 
        where e1.NormEvents != 0 
        select e2; 

這根本不工作...:/任何想法來幫助解決這個問題?

我的另一個疑問是,如果將爲每個通過過濾器的輸入創建一個新的窗口,併爲其創建一個tumblingWindow。

謝謝。

+0

@米奇小麥:爲什麼你需要的是一種激勵,以幫助他人?如果你不想幫忙,那就不要。我沒有看到問題... – Megacan 2011-05-27 15:19:33

+0

@Megacan:每個人都需要獎勵。 – 2011-05-28 01:54:03

回答

2

試試這個:

// Move all error events 
// to the point where the potential timeout would occur. 
var timedOut = input 
        .Where(e => e.IsError == true) 
        .ShiftEventTime(e => e.StartTime + TimeSpan.FromMinutes(5)); 

// Extend all events IsToNormalize by the timeout. 
var following = input 
        .Where(e => e. IsToNormalize == true) 
        .AlterEventDuration(e => TimeSpan.FromMinutes(5)); 

// Mask away the potential timeout events by the extended events. 
// - If IsToNormalize did not occur within the timeout, then the shifted error event 
// will remain unchanged by the left-anti-semi-join and represent 
// the desired output. 
var result = from t in timedOut 
      where (from c in following 
        where t.IdGroup == c.IdGroup 
        select c).IsEmpty() 
      select t; // or some projection on t