CEP raw data processing

First we will generate some data for the Function node. Here is the sensor script that we will use in the example, which returns one of 6 states, depending on the random number:

var randomValue = Math.random(); 
var state;
if(randomValue > 0.85)
  state = "ONE";
else if(randomValue > 0.7)
  state = "TWO";
else if(randomValue > 0.55)
  state = "THREE";
else if(randomValue > 0.4)
  state = "FOUR";
else if(randomValue > 0.25)
  state = "FIVE";
  state = "SIX";
value = {  
    observedState:  state, 
    rawData : {  randomValue: randomValue}  

In this example, we will learn how to use rawData which can also be ‘produced’ by the sensors. This is the extract from the script above:

value = {  
    observedState:  state, 
    rawData : {  randomValue: randomValue}  

In order to access the node rawData, CEP Function node uses this format: (<dice_1.randomValue> . That way you can build formulas like this: <node1.rawdat1> OPER <node2.rawdat2> etc.. Function node has about 40-50 built-in functions.

Our Formula nodes are defined like this:

  • <avg(diceSensor_1.randomValue)>
  • <min(diceSensor_1.randomValue)>
  • <max(diceSensor_1.randomValue)>
  • <avg(3, samples, diceSensor_1.randomValue)>
  • <avg(5, samples, diceSensor_1.randomValue)>
  • <Max.formulaValue> - <Min.formulaValue>
  • <Avg3Samples.formulaValue> - <Avg5Samples.formulaValue>

Where the last two Formula nodes (sequence 3) calculate on top of other formula nodes (formulaValue is the rawData of the Formula node itself - result of the formula computation). Formula node is just like any other sensor, it prodices 3 states (Below, Equal, Above) and rawData. Input arguments for the Formula node are formula definition and the threshold, which is used for the state evaluation.

So, let’s create the template:


So, let’s roll the dice and see what happens!

Debug mode, raw data:


Debug mode, states view: