0

First of all let me description my requirement:

data.csv: column one is id,column two is vlaue.

1,0
2,0
3,0
4,86
5,87
6,88
7,89
8,86
9,0
10,0
11,0
12,0
13,0
14,86
15,87
16,88
17,89
18,0
19,0
20,0

here is my InputStream and my OutPutStream:

id int,value int

data.csv will insert into InputStream by using Event Stream Simulator.

If there are five consecutive value>=85, I would record the first id,value into OutPutStream. For example,I will record id=4,value=86 ,but id=14 to id=17 i will ignore it.

So how can i write siddhi script in execution plans to implement it?

==========================================================================

data2.csv:

1,0
2,0
3,0
4,86
5,87
6,88
7,89
8,86
9,87
10,88
11,89
12,90
13,91
14,86
15,87
16,88
17,89
18,90
19,90
20,90
21,0
22,0,
23,87
24,85
25,86
26,0
27,17
...
200,91
201,0
Community
  • 1
  • 1
willxiang
  • 291
  • 3
  • 6

2 Answers2

1

For exactly five consecutive values >= 85

from every a1=InputStream[value>=85], a2=InputStream[value>=85]+, a3=InputStream[value<85]
select a1.id, a1.value
having (not (a2[3] is null)) and (a2[4] is null)
insert into OutPutStream;

For more than five consecutive values >= 85

from every a1=InputStream[value>=85], a2=InputStream[value>=85]+, a3=InputStream[value<85]
select a1.id, a1.value
having (not (a2[3] is null))
insert into OutPutStream;
Grainier
  • 1,634
  • 2
  • 17
  • 30
  • Hi Grainier,i use the second siddhi query (**for more than five consecutive value >=85**) because i'm not sure what time the value will smaller that 85 in actual situation.But i meet another problem:if i want insert data when:id=8,value=86(i'm not sure what time the value will smaller that 85 but i need insert when five consecutive values >= 85...). – willxiang Aug 15 '16 at 10:07
  • So i made some fake data like data2.scv and test it,i must wait the data running out and then insert into OutPutStream.I want if have **5** consecutive value >=85(but not exactly five,could be more than five), for example from id=4,value=86 to id=8,value=86 then i want insert id=8,value=86 to OutPutStream.I hope you can understand what i say because my english is sucks. – willxiang Aug 15 '16 at 10:07
  • I'm not quite clear with the requirement here, do you want to output **every** five consecutive value >= 85? (i.e at event 8,86: output 4,86 / at event 9,87: output 5,87 / ...). Basically this will output 4,86 / 5,87 / 6,88 / 7,89 / 8,86 / ... since each of them were followed by five consecutive events with value >=85. Then again, when you say "for example from id=4,value=86 to id=8,value=86 then i want insert id=8,value=86 to OutPutStream", it doesn't match your initial requirement of emitting **first** id, value to OutPutStream, right? – Grainier Aug 16 '16 at 01:40
  • Thank you for your patience!Let me explain what i wanna do.I wanna monitor the event ,if i found value >=85(assume the id = 4),i will begin counting,if the next four consecutive event value >=85 too(assume the id = 5/6/7/8),i will record the 5th event (value>=85,i.e id=8).And then i will wait the value of event decrease ,lower than 85,at the time i will monitor again ,wait the value of event >=85 and counting... and again... – willxiang Aug 16 '16 at 02:15
  • Plz look up the data2.scv(i updated it),when i found id=23,value=87, i will counting, and waiting the next four consecutive value >=85,but the id=26,value=0,so i will clear the counting,wait next value >=85 and restart to counting. – willxiang Aug 16 '16 at 02:15
  • My question now is, if the value has been greater than 85, for a long period of time greater than 85, I had to wait until the value in order to record a piece of data is less than 85, there is a continuous five records over 85 when I should immediately record, I need this effect.this comment by using google translate,i hope you can understand :) – willxiang Aug 16 '16 at 02:36
  • @willxiang Please refer to my answer for http://stackoverflow.com/q/39009292/1805178 – Grainier Aug 23 '16 at 14:41
0
from every a1=InputStream[value>=85], a1=InputStream[value>=85]<4> 
select a1.id, a1.value
insert into OutPutStream;

Should work!

suho
  • 912
  • 6
  • 12