Sequence with Count

Sequence query does expect the matching events to occur immediately after each other, and it can successfully correlate the events who do not have other events in between. Here, sequence can count event occurrences.

Refer the Siddhi query guide for more information.

define stream TemperatureStream(roomNo int, temp double);

@sink(type='log') 
define stream PeekTemperatureStream(roomNo int,
    initialTemp double, peekTemp double, firstDropTemp double);

partition with (roomNo of TemperatureStream)
begin
    @info(name = 'temperature-trend-analyzer')
    from every e1=TemperatureStream,
         e2=TemperatureStream[ifThenElse(e2[last].temp is null,
                e1.temp <= temp, e2[last].temp <= temp)]+,
         e3=TemperatureStream[e2[last].temp > temp]
    select e1.roomNo, e1.temp as initialTemp,
        e2[last].temp as peekTemp, e3.temp as firstDropTemp

    insert into PeekTemperatureStream ;
end;
define stream TemperatureStream(roomNo int, temp double);

Defines TemperatureStream having information on room temperatures such as roomNo and temp.

@sink(type='log') 
define stream PeekTemperatureStream(roomNo int,
    initialTemp double, peekTemp double, firstDropTemp double);

Defines PeekTemperatureStream which contains events related to peak temperature trends.

partition with (roomNo of TemperatureStream)
begin

Partition the TemperatureStream events by roomNo

    @info(name = 'temperature-trend-analyzer')
    from every e1=TemperatureStream,
         e2=TemperatureStream[ifThenElse(e2[last].temp is null,
                e1.temp <= temp, e2[last].temp <= temp)]+,
         e3=TemperatureStream[e2[last].temp > temp]

Identifies the trend of the temperature in a room

    select e1.roomNo, e1.temp as initialTemp,
        e2[last].temp as peekTemp, e3.temp as firstDropTemp

    insert into PeekTemperatureStream ;

Projects the lowest, highest and the first drop in the temperature trend

end;

This application identifies temperature peeks by monitoring continuous increases in temp attribute and alerts upon the first drop.

Input

  • Below events are sent to TemperatureStream,

    [20, 29] [10, 28] [20, 30] [20, 32] [20, 35] [20, 33]

Output

After processing the above input events, the event arriving at PeekTemperatureStream will be as follows:

[20, 29.0, 35.0, 33.0]

Top