Aggregation samplepoint examples
  • 18 May 2021
  • 5 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Aggregation samplepoint examples

  • Dark
    Light
  • PDF

Article Summary

The purpose of this article is to illustrate a few aggregation examples to enable the user to perform some simple pre-calculations and manipulation of the data with DCM.

An aggregation is inserted in any collector, just as any other sample point. 

The aggregation in DCM uses Reverse Polish Notation (RPN)


Let's start with an example of event-based logging:

Here is a very special example. 

This is an entire collector example where we have 3 sample points and 1 aggregation. It monitors the input 1 (I/O port 1, the green connector at the bottom of the SiteManager)

The sample points CPULoad and SystemTemperature are configured with "SampleInterval": 0  which means they are not sampled by default. 

The sample point IO_1 samples every second, but "SamplesSaved": 0 means that the values are not sent to the cloud, but can be used for aggregation.

The important factor in this example is the aggregation sample point.

It monitors the IO_1 sample point and when Input 1 is "1" or "High" it changes the SampleInterval of the CPULoad and sample points. 

So they are only sampled when input 1 is "High".

Summary: This example will only collect and deliver data to the cloud when I/O port 1 is set to high.

Entire collector example

{
  "CollectorDescription": "Internal SM collector",
  "CollectorName": "InternalCollector",
  "ConnectRetryMax": 60,
  "ConnectRetryMin": 5,
  "Protocol": "Internal",
  "SamplePoints": [
    {
      "InternalData": {
        "InternalFunction": "SystemTemperature",
        "InternalSampleInterval": 0
      },
      "SampleDataType": "float",
      "SampleDescription": "System Temperature",
      "SampleName": "SystemTemperature"
    },
    {
      "InternalData": {
        "InternalFunction": "CPULoad",
        "InternalSampleInterval": 0
      },
      "SampleDataType": "double",
      "SampleDescription": "CPU Load",
      "SampleName": "CPULoad"
    },
    {
      "InternalData": {
        "InternalFunction": "DigitalInput",
        "InternalSampleInterval": 1,
        "InternalIndex": 0
      },
      "SampleDataType": "bool",
      "SampleDescription": "I/O port 1 state",
      "SampleName": "IO_1",
      "SampleUnit": "On/Off",
      "SamplesSaved": 1
    },
    {
      "Aggregation": {
        "Expression": "IO_1,0,>",
        "Function": "eventcompute",
        "Values": [
          "CPULoad",
          "SystemTemperature"
        ],
        "TriggerNewInterval": 1,
        "TriggerSample": "IO_1"
      },
      "SampleDataType": "double",
      "SampleDescription": "Trigger on IO_1",
      "SampleName": "EventTrigger"
    }
  ]
}

In the following examples calculations will be done on 4 sample points

  • Triangle
  • Sine
  • OnOff
  • Counter

In this example, the aim is to obtain an average of each sample of the sample points Counter & Triangle.

This is achieved by adding the two values and dividing the result by 2.

The function is normal calculation so the function type is compute.

The expression "Counter, Triangle,+,2,/" produces the calculation:

(Counter+Triangle)/2

Counter, Triangle , + is equal to (Counter+Triangle)

Then 2,/ is equal to (Counter + Triangle)/2

Aggregation sample point only 

{
  "SampleName": "PressureNozzle",
  "SampleDescription": "Pressure/Nozzleflow avg ",
  "SamplesSaved": 3,
  "SampleDataType": "int32",
  "SampleUnit": "hPA/s",
  "Aggregation": {
    "Function": "compute",
    "Expression": "Counter, Triangle,+,2,/",
    "TriggerSample": "Triangle"
  }
}


The below example is another example of event-based logging where data is logged when a certain condition is true.

The function used is eventcompute.

The expression "OnOff,35,>" defines the condition, the values are the sample points that are sampled when the condition is true.

The condition is checked every time the TriggerSample is sampled.

When the condition is true a new sample interval is set with TriggerNewInterval.

Here the sample points Counter, Sine & Triangle are sampled (sample interval changed from 0(never) to 1(every second)) when the sample point OnOff is above 35.

{
  "SampleName": "EventValue",
  "SampleDescription": "When OnOff > 35, sample Counter,Sine and Triangle every second",
  "SamplesSaved": 0,
  "SampleDataType": "double",
  "Aggregation": {
    "Function": "eventcompute",
    "Expression": "OnOff,35,>",
    "Values": [
      "Counter",
      "Sine",
      "Triangle"
    ],
    "TriggerSample": "OnOff",
    "TriggerNewInterval": 1
  }
}


Possible aggregation functions:

  • max
  • min
  • avg
  • mavg
  • derived
  • compute
  • eventcompute

Possible aggregation RPN expression operators:

  • sampleref which pushes the newest value of the designated value onto the stack.
  • Constant, which pushes the constant onto the stack.
  • "+" (addition), which pops the top 2 values off the stack, adds them and pushes the result onto the stack.
  • "-" (subtraction), which pops the top 2 values off the stack, subtracts them and pushes the result onto the stack.
  • "*" (multiplication), which pops the top 2 values off the stack, multiplies them and pushes the result onto the stack.
  • "/" (division), which pops the top 2 values off the stack, divides them and pushes the result onto the stack.
  • "%" (modulo), which pops the top 2 values off the stack, calculates the modulo of them and pushes the result onto the stack.
  • "^" (exponential), which pops the top 2 values off the stack, calculates the exponential of them and pushes the result onto the stack.
  • "sqrt" (square-root), which pops the top 1 value off the stack, calculates the square-root of it and pushes the result onto the stack.
  • "abs" (absolute), which pops the top 1 value off the stack, calculates the absolute value of it and pushes the result onto the stack.
  • "max" (maximum), which pops the top 2 values off the stack, calculates the maximum of them and pushes the result onto the stack.
  • "min" (minimum), which pops the top 2 values off the stack, calculates the minimum of them and pushes the result onto the stack.
  • "&&" (logical and), which pops the top 2 values off the stack, calculates the logical AND of them and pushes the result onto the stack.
  • "||" (logical or), which pops the top 2 values off the stack, calculates the logical OR of them and pushes the result onto the stack.
  • ">" (greater than), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if greater than and 0 otherwise.
  • ">=" (greater than or equal to), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if greater than or equal to and 0 otherwise.
  • "<" (less than), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if less than and 0 otherwise.
  • "<=" (less than or equal to), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if less than or equal to and 0 otherwise.
  • "==" (equal to), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if they are equal and 0 otherwise.
  • "!=" (not equal to), which pops the top 2 values off the stack, compares them and pushes 1 onto the stack if they are not equal and 0 otherwise.
  • "if" (3 values), which pops the top 3 values off the stack, pushes top-1 value if top value is non-zero, otherwise top-2 value is pushed.
  • "dropif" (1 value), which pops the top value and if it is non-zero, execution of expression will stop and no new value will be stored. NOTE: Does not push any result.

The RPN expression uses these operands:

The aggregation functions compute and eventcompute both have a string with an arithmetic expression that is evaluated whenever the TriggerSample value is updated. This expression is represented in RPN (Reverse Polish Notation), which operates on a stack (max 32 values). All calculations are done in either signed 64bit integer, unsigned 64bit integer or double floating point, depending on the datatype of the aggregation sample. Once the result is stored, any overflow is ignored. The RPN is a list of operators separated by commas. 

When the RPN expression ends, the top value is the new value of the aggregation sample. If the aggregation is an "eventcompute" aggregation and the new value is non-zero, the Values list will be collected. This is known as event-driven data collection.

If an expression results in a run-time error, (compilation error, divide by zero, stack overflow, insufficient operands for operator or empty stack on completion), the execution is suspended until DCM is restarted.


Was this article helpful?