I've defined the input stream below. The Datetime string is like 2010-09-01 06:59:00.000
, the result is a double like 157,382
and the UnixDateTime is in type long like 1283324340111
.
define stream HStream(ID int, DateTime String, Result double, UnixDateTime long);
I want to make length batches for 100 events that display an average for the result
column and I want to compare these batches with each other. I want to do this sliding comparison for the next 5 batches (that all include 100 events each). So I want to compare the first batch (0-100 event) to the second batch (101-200), untill the sixth batch (501-600). And I want the second batch to compare untill the 7th batch. What I want to achieve with the comparison is that when 4 or more (from the 5) batches have a batch average result that is all bigger or all smaller than 1 (compared to the average result from the original batch), then I want to log the info about the original batch.
My code is below. The problem I don't know the exact syntax. I've looked at the tutorials and documentation at WSO2 and Siddhi, but I cannot solve the problem.
@info(name = 'MovingAverageQuery')
from every e1=HStream, e2=HStream[e1.avg(Result) <= avg(Result))+, e2=HStream[e2[last].avg(Result) <= avg(Result)]
select ID, DateTime, Result,
avg(Result), UnixDateTime
output last every 100 events
insert into OutputStream;
@sink(type='log', prefix='LOGGER')
define stream OutputStream(Nr ID, DateTime String, Result double, Avg double, UnixDateTime long);