0

I want to detect a pattern with Flink CEP, here my use case: I should raise an event when i got the speed of my vehicle above a speedLimit for a laps of time.

Example1: (speedlimit = 100, period=60 seconds)

event1: speed = 50, eventtime=0
event1: speed = 100, eventtime=10
event1: speed = 120, eventtime=30
event1: speed = 150, eventtime=40
event1: speed = 120, eventtime=70
event1: speed = 50, eventtime=90

=> raise 1 event

Example1: (speedlimit = 100, period=60 seconds)

event1: speed = 50, eventtime=0
event1: speed = 100, eventtime=10
event1: speed = 120, eventtime=30
event1: speed = 150, eventtime=40
event1: speed = 60, eventtime=70

=> raise 0 event

Please, your help.

Khairy
  • 81
  • 1
  • 10

1 Answers1

0

I would approach this by looking for a sequence of 2 or more events where the speed is greater than or equal to 100 for all of them, and where the timestamp of the last one minus the timestamp of the first one is greater than or equal to 60.

By the way, you may find MATCH_RECOGNIZE is easier to work with, but either it or CEP should be fine for this use case.

David Anderson
  • 39,434
  • 4
  • 33
  • 60
  • Thanks David for your response, Yes, this a good approach, i have implemented it but without checking the interval when detecting the pattern. I have an other idea that i need to give me your opinion about it: I can use `Within(120)` and treat the timeout handler, calculate the number of the events that are above the speedlimit – Khairy Jul 21 '20 at 08:21
  • Yes, I guess I can see how that could work. Possibly a clever solution. – David Anderson Jul 21 '20 at 11:35