0

I am looking for an EPL statement which fires an event each time a certain value has increased by a specified amount, with any number of events in between, for example: Considering a stream, which continuously provides new prices. I want to get a notification, e.g. if the price is greater than the first price + 100. Something like

select * from pattern[a=StockTick -> every b=StockTick(b.price>=a.price+100)];

But how to realize that I get the next event(s), if the increase is >= 200, >=300 and so forth?

Diverse tests with context and windows has not been successful so far, so I appreciate any help! Thanks!

mark
  • 1

1 Answers1

0

The contexts would be the right way to go. You could start by defining a start event like this:

create schema StartEvent(threshold int);

And then have context that uses the start event:

create context ThresholdContext inititiated by StartEvent as se
     terminated after 5 years

context ThresholdContext select * from pattern[a=StockTick -> every b=StockTick(b.price>=context.se.threshold)];

You can generate the StartEvent using "insert into" from the same pattern (probably want to remove the "every") or have the listener send in a StartEvent or declare another pattern that fires just once for creating a StartEvent.

user650839
  • 2,594
  • 1
  • 13
  • 9
  • Thank you for your answer. Unfortunately it is still not exactly clear to me. Consider the following values for prices - the event should always fire, where an x is: 0 StartEvent 30 99 100 X 101 103 130 199 200 X 201 260 301 X – mark Sep 29 '15 at 20:10
  • context ThresholdContext insert into StartEvent select a.price + 100 as price from pattern[a=StockTick -> b=StockTick(b.price>=context.se.threshold)] // i.e. when pattern matches use the price of "a" and add 100 and make that a new start event, also change the "terminated by" if needed – user650839 Oct 02 '15 at 21:35