- GateManager Own - Datalogging Scenarios
- LogTunnel Scenarios
- SiteManager Embedded Scenarios
- SiteManger Scenarios

# DCM config file - Aggregation examples

Purpose of this article is to show a few aggregation examples to enabled the user to do simple pre-calculations and manipulation of the data with DCM.

The aggregation in DCM is using Reverse Polish Notation ( RPN )

The Aggregation object contains the following fields:Function | Type | Importance | Description |
---|---|---|---|

Function | string-enum | mandatory | This is the aggregation function to be performed. The currently possible values are: "max", "min", "avg", "mavg", "derived", "compute" and "eventcompute". |

Values | array of strings | maybe-optional | This is a list of sampleref references, whose values will be arguments to the aggregation function. Mandatory for all values of Function except "compute". |

TriggerSample | string | mandatory | This is a sampleref to the sample that will trigger the evaluation of the aggregation function. Only when the sample is updated (either by sampling from a device or from another aggregation), will this aggregation function evaluate and create a new sample value itself. |

Expression | string | maybe-optional | This is an arithmetic expression using Reverse Polish Notation (RPN) with sampleref , numeric constants and operators separated by commas. See the section on RPN expressions. This field is mandatory if Function is "compute" or "eventcompute". |

TriggerNewInterval | integer > 0 | optional | This is a new sample interval (in secs) for the TriggerSample that should be in effect when the event is triggered. When the event is not triggered, the TriggerSample s normal interval is used. Only used when the Function is "eventcompute". If more than one "eventcompute" event forces a new sample interval for the same sample, the lowest new interval is used. |

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

Triangle, Sine, OnOff & Counter

In this example the goal is to have an average of each sample of the sample-points Counter & Triangle.

It is achieved by adding the two values and divide the result by 2.

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

The
**
Expression
**
"Counter, Triangle,+,2,/" gives the calculation:

(Counter+Triangle)/2

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

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

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

This example is an 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,
**Values**are the sample-points that is sampled when 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 } }

{ "SampleName": "AveragePressureNozzle", "SampleDescription": "Pressure/Nozzleflow avg ", "SampleDataType": "int32", "SampleUnit": "hPA/s", "Aggregation": { "Function": "avg", "Values": [ "PressureNozzle" ], "TriggerSample": "OnOff" } }

Here is a very special example.

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

The samplepoints CPULoad and Systemtemperature are configured with *"SampleInterval": 0 *which means they are not sampled by default.

The samplepoint IO_1 is sampling every second, but the *"SamplesSaved": 0* means that the values are not sent to the cloud, but can be used for aggregation.

The important in this example is the Aggregation samplepoint.

It monitors the IO_1 samplepoint and when the Input 1 is "1" or "High" it changes the SampleInterval of CPULoad and SystemTemperature samplepoints.

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 held high.

{ "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", "SampleUnit": "C", "SampleDBPriority": 100 }, { "InternalData": { "InternalFunction": "CPULoad", "InternalSampleInterval": 0 }, "SampleDataType": "double", "SampleDescription": "CPU Load", "SampleName": "CPULoad", "SampleUnit": "%", "SampleDBPriority": 100 }, { "InternalData": { "InternalFunction": "DigitalInput", "InternalSampleInterval": 1, "InternalIndex": 0 }, "SampleDataType": "bool", "SampleDescription": "I/O port 1 state", "SampleName": "IO_1", "SampleUnit": "On/Off", "SamplesSaved": 1, "SampleDBPriority": 100 }, { "Aggregation": { "Expression": "IO_1,0,>", "Function": "eventcompute", "Values": [ "CPULoad", "SystemTemperature" ], "TriggerNewInterval": 1, "TriggerSample": "IO_1" }, "SampleDataType": "double", "SampleDescription": "Trigger on IO_1", "SampleName": "Test1_REG108_trigger", "SamplesSaved": 100 } ] }