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;
|
Defines |
|
|
|
Defines |
|
Partition the |
|
|
|
Identifies the trend of the temperature in a room |
|
Projects the lowest, highest and the first drop in the temperature trend |
|
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
]