Bulk data processing

Sometimes you have already data logs against which you might want to run a rule, using a template that you have created upfront. This can be either part of the debugging process (before for instance you deploy stream rules in production), or when you want to use this feature directly in your product (e.g. from the laptop to run machine data logs to verify the health of connected appliances). Full API is described here.

For this use case, we will use the following template: image

and its simplified JSON representation:

{
  "sensors": [
    {
      "label": "sensor1",
      "name": "streamingDataSensor",
      "version": "1.1.4",
      "dataTrigger": true,
      "tickTrigger": false,
      "position": [
        613,
        230
      ],
      "sequence": 1,
      "properties": {
        "parameter": "temperature",
        "threshold": "20"
      }
    },
    {
      "label": "sensor2",
      "name": "Function",
      "version": "1.0.1",
      "dataTrigger": true,
      "tickTrigger": false,
      "position": [
        640,
        406
      ],
      "sequence": 1,
      "properties": {
        "formula": "<GLOBAL.temperature>",
        "threshold": "21"
      }
    }
  ],
  "actuators": [
    {
      "label": "debugDialog_1",
      "name": "debugDialog",
      "version": "1.0.4",
      "position": [
        1090,
        219
      ],
      "properties": {
        "message": "Hello world"
      }
    }
  ],
  "relations": [
    {
      "label": "ANDGate_1",
      "type": "AND",
      "position": [
        877,
        283
      ],
      "parentLabels": [
        "sensor1",
        "sensor2"
      ],
      "combinations": [
        [
          "Above",
          "Above"
        ]
      ]
    }
  ],
  "triggers": [
    {
      "destinationLabel": "debugDialog_1",
      "sourceLabel": "ANDGate_1",
      "invocationPolicy": 0,
      "statesTrigger": [
        "TRUE"
      ]
    }
  ],
  "name": "Bulk_test"
}

curl --user apiKey:apiSecret  -H "Content-Type:application/json" -X POST -d '{
      "data": [[{"resource": "resource1", "temperature" :21}, {"resource": "resource2", "temperature" :22}
        ],[{"resource": "resource1", "temperature" :21}, {"resource": "resource2", "temperature" :21}
        ]],
      "conf": {
        "resource": "resource1",
        "resetObservations": false,
        "executeActuators": true,
         "nodes":[
          {
            "name": "sensor1",
            "properties": {
              "resource":  "resource1"
            }
          },
          {
            "name": "sensor2",
            "properties": {
              "resource":  "resource2"
            }
          }]
      }
    }' "https://sandbox.waylay.io/api/templates/Bulk_test/run"

The results are returned as an application/x-ndjson stream. Whenever an invocation ends you will receive a new json concatenated with a newline. The request will end once all data has been worked through. In case of a single invocation this response can also be parsed as application/json

In our case we will receive two results, first data stream will trigger actuation (Hello World), while the second data stream will not, since the second node was in the Equal state and therefore AND gate didn’t triggered the actuation.

Output of the first data stream [{"resource": "resource1", "temperature" :21}, {"resource": "resource2", "temperature" :22}]

image

Output of the second data stream [{"resource": "resource1", "temperature" :21}, {"resource": "resource2", "temperature" :21}]. Actuator is not triggered.

image