简体   繁体   English

比较 WSO2 Stream 处理器中的批次平均值

[英]Compare batches of average values with each other in WSO2 Stream Processor

I've written some code in Siddhi that logs/prints the average of a batch of the last 100 events.我在 Siddhi 中编写了一些代码,用于记录/打印一批最后 100 个事件的平均值。 So the average for event 0-100, 101-200, etc. I now want to compare these averages with each other to find some kind of trend.所以事件 0-100、101-200 等的平均值。我现在想将这些平均值相互比较以找到某种趋势。 In first place I just want to see if there is some simple downward of upward trend for a certain amount of averages.首先,我只想看看对于一定数量的平均值是否存在一些简单的下降趋势。 For example I want to compare all average values with all upcoming 1-10 average values.例如,我想将所有平均值与所有即将到来的 1-10 平均值进行比较。

I've looked into Siddhi documentation but I did not find the answer that I wanted.我查看了 Siddhi 文档,但没有找到我想要的答案。 I tried some solutions with partitioning, but this did not work.我尝试了一些分区解决方案,但这不起作用。 The below code is what I have right now.下面的代码是我现在所拥有的。

define stream HBStream(ID int, DateTime String, Result double);

@info(name = 'Average100Query')
from HBStream#window.lengthBatch(100)
select ID, DateTime, Result, avg(Result)
insert into OutputStream;

Siddhi sequences can be used to match the averages and to identify a trend, https://siddhi.io/en/v5.1/docs/query-guide/#sequence Siddhi 序列可用于匹配平均值并识别趋势, https://siddhi.io/en/v5.1/docs/query-guide/#sequence

from every e1=HBStream, e2=HBStream[e2.avgResult > e1.avgResult], e3=HBStream[e3.avgResult > e2.avgResult]
select e1.ID, e3.avgResult - e1.avgResult as tempDiff
insert into TempDiffStream; 

Please note you have to use partition to decide this patter per ID is you need averages to be calculated per Sensor.请注意,您必须使用分区来确定每个 ID 的这种模式,您需要计算每个传感器的平均值。 In your app, also use group by if you need average per sensor在您的应用中,如果您需要每个传感器的平均值,也可以使用 group by

@info(name = 'Average100Query')
from HBStream#window.lengthBatch(100)
select ID, DateTime, Result, avg(Result) as avgResult
group by ID
insert into OutputStream;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM