Search code examples
fiwarecomplex-event-processing

How to detect sudden increase or decrease in value for an event using proton run time?


I am developing an application using proton CEP and Orion Context Broker. I have sensor that updates the temperature and CEP gets the temperature update as an event. I want the CEP to produce an alert if there is a difference of 10 in two consecutive updates.

For example: Last update from sensor is 35. If the next update is less than 26 or greater than 44 I need CEP to produce an alert.

How can I write a rule to achieve this?


Solution

  • The CEP strongly refers to time windows. You didn't mention what is the time window in which you would like to detect the differences between two sensor events. Lets assume that you want to detect a difference between events that arrived within 10 minutes.

    In the CEP you need to define a temporal context, that will have your input event as initiator and a relative time terminator of 10 minutes. Make sure to set the Correlation Policy of the event initiator to Add, so that every input event will initiate a context instance even if another is already opened.

    Then, you can define an EPA (event processing agent) of type Sequence. And set it to use the temporal context you defined.

    This EPA will have two participant events, both from the type of your input event. Each participant event should have a different alias (say sensor1, sensor2), both should have instance selection policy of First, and consumption policy of Consume.

    In the condition of the EPA you need to set your condition:

    sensor2.temperature >= sensor1.temperature + 10 OR sensor2.temperature <= sensor1.temperature - 10
    

    Set the evaluation policy to Immediate, and cardinality policy to Single.

    As always, you need to set a derived event that will be generated if the pattern is detected.

    As for the integration of the CEP with Orion context broker, refer to Appendix A in the CEP user guide.