wso2siddhiwso2-cep

Time interval events


I am playing with the externalTime / externalTimeBatch in order to calculate average value for events that happen within a certain time interval as below

from sensorStream#window.externalTimeBatch(meta_timestamp, 60 sec, meta_timestamp, 60 sec)  [sensorValue > 100]

select meta_timestamp, avg(sensorValue) as sensorValue

insert into filteredStream

The issue I am having is that the average is always calculated for all events from the begining, rather then getting reset on the time interval.

Whats the best way to use it.

Thanks.


Solution

  • Below query seems to do the proper averaging using tumbling time interval. Once I moved my time holder attribute "meta_timestamp" to cross my time window it worked properly.

    from sensorStream#window.externalTimeBatch(meta_timestamp, 1 min, 0, 1 min)  [sensorValue > 100]
    select meta_timestamp, meta_sensorName, correlation_longitude, correlation_latitude, avg(sensorValue) as sensorValue
    insert current events into filteredStream
    

    example POST message sent for testing

    { 
    "event":
    { 
        "metaData":
        { 
            "timestamp":1514801340000,
            "isPowerSaverEnabled": false, 
            "sensorId": 701, 
            "sensorName": "temperature"
        }, 
        "correlationData":
        { 
            "longitude": 4.504343, 
            "latitude": 20.44345 
    
        }, 
        "payloadData":
        { 
            "humidity": 2.3,
            "sensorValue": 150
        }
    
    }
    

    }

    Thanks for listening !!