2016-06-30 5 views
0

저는 모델화하는 데 아주 간단한 문제가 있으며 Esper에서 경험이 없으므로 잘못된 길로 향할 수 있으므로 약간의 통찰력을 얻으실 수 있습니다.Esper 매우 간단한 컨텍스트 및 집합

여기 시나리오가 있습니다 : "SpotTaken"과 "SpotFree"의 두 가지 유형의 이벤트가있는 "ParkingEvent"이벤트 스트림이 하나 있습니다. 그래서 저는 Esper 컨텍스트을 ID로 분할하고 "SpotTaken"유형의 시작 이벤트와 "SpotFree"유형의 종료 이벤트로 경계를 잡았습니다. 아이디어는 센서로 주차 장소를 모니터링 한 다음 데이터를 수집하여 현장을 찍은 횟수와 시간 직업을 계산하는 것입니다.

그렇습니다. 시간대가 없기 때문에 매우 간단합니다. 그러나 나는 데이터를 수집하는 데 어려움을 겪고 있습니다. 여기에 지금까지 가지고 코드는 다음과 같습니다

create context ParkingSpotOccupation 
    context PartionBySource 
    partition by source from SmartParkingEvent, 

    context ContextBorders 
    initiated by SmartParkingEvent(
     type = "SpotTaken") as startEvent 

    terminated by SmartParkingEvent(
     type = "SpotFree") as endEvent; 

@Name("measurement_occupation") 
context ParkingSpotOccupation 
insert into CreateMeasurement 
select 
    e.source as source, 
    "ParkingSpotOccupation" as type, 
    { 
    "startDate", min(e.time), 
    "endDate", max(e.time), 
    "duration", dateDifferenceInSec(max(e.time), min(e.time)) 
    } as fragments 
from 
    SmartParkingEvent e 
output 
    snapshot when terminated; 

내가 내가 내가 잘못 뭔가를해야만하고 있어요 추측하고있어 최소 및 최대 동일한 데이터를 얻었다.

min 및 max 대신 context.ContextBorders.startEvent.time 및 context.ContextBorders.endEvent.time을 사용하면 measurement_occupation 문이 트리거되지 않습니다.

+0

많은 SmartParkindEvents이 만들어진 어떻게 문맥이 열려있는 동안? 거기에 하나만 있다면 결과가 의미가있을 것입니다. 마지막 줄을 출력과 함께 제거한 다음 몇 가지 SmartParkingEvents를 만들 수 있습니까? 매번 출력해야합니다. – TyrManuZ

답변

0

는 측정이 이미 제공 한 EPL에 의해 계산 된 점을 감안,이 자리가 촬영 (및 해제) 된 횟수를 계산하고 기간까지 합계 :

select source, count(*), sum(duration) from CreateMeasurement group by source