Siddhi 5,比较之前的价值

Siddhi 5, compare value before

我需要当温度高于存储的最高温度或低于存储的最低温度时,我会向警报流发送包含新温度的警报。

当我得到更高或更低的温度时,首先将其添加到最大值和/或最小值然后进行检查的问题,所以我从不跳过警报。

我该怎么做才能首先比较出现在我身上的新温度并立即警觉?

@App:name("MaxTenMinutesApp")
define stream CargoStream (temperature int);

@sink(type='log', prefix='ouput >')
define stream OutputStream(temperature int, temperatureMax int, temperatureMin int);

@sink(type='log', prefix='alert >')
define stream AlertStream(temperature int);

@info(name='Alert')
from OutputStream[temperatureMax < temperature or temperatureMin > temperature ]
select temperature
insert into AlertStream;

@info(name='MaxTenMinutes')
from CargoStream#window.time(5 min)
select temperature, max(temperature) as temperatureMax, min(temperature) as temperatureMin
insert into OutputStream;

//日志

[2020-02-26_10-41-49_404] INFO {org.wso2.siddhi.core.stream.output.sink.LogSink} - ouput > : Event{timestamp=1582710109402, data=[10, 10, 10], isExpired=false} (Encoded)
[2020-02-26_10-41-54_600] INFO {org.wso2.siddhi.core.stream.output.sink.LogSink} - ouput > : Event{timestamp=1582710114596, data=[11, 11, 10], isExpired=false} (Encoded)
[2020-02-26_10-41-59_462] INFO {org.wso2.siddhi.core.stream.output.sink.LogSink} - ouput > : Event{timestamp=1582710119461, data=[9, 11, 9], isExpired=false} (Encoded)

// 示例

VALUE   TEM MAX MIN  EVENT
5         5   5   5  SENT ALARM NEW MAX Y MIN
10       10  10   5  SENT ALARM NEW MAX
6         6  10   5  NOTHING
3         3  10   3  SENT ALARM NEW MIN

您必须保留一个包含最后最高和最低温度的占位符,并在输入温度时使用它。

请参考示例代码

@App:name("MaxTenMinutesApp")

define stream CargoStream (temperature int);

define table tempValueHolder (index int, temperatureMax int, temperatureMin int);

-- Sets initial value
define trigger triggerAtStart at 'start';

@sink(type='log', prefix='ouput >')
define stream OutputStream(temperature int, temperatureMax int, temperatureMin int);

@sink(type='log', prefix='alert >')
define stream AlertStream(temperature int);

@info(name='Sets initial value')
from triggerAtStart
select 0 as index, 0 as temperatureMax, 0 as temperatureMin
insert into tempValueHolder;

@info(name='Alert')
from CargoStream as strm
join tempValueHolder as tbl
select strm.temperature, tbl.temperatureMax, tbl.temperatureMin
insert into OutputStream;

from OutputStream[temperatureMax < temperature or temperatureMin > temperature ]
select temperature
insert into AlertStream;


@info(name='MaxTenMinutes')
from OutputStream#window.time(5 min)
select max(temperature) as temperatureMax, min(temperature) as temperatureMin
update tempValueHolder
on tempValueHolder.index == 0;