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)

**Aggreation**

The Aggregation object contains the following fields:

**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 is 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 TriggerSamples 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": 1000,

"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 ",

"SamplesSaved": 1000,

"SampleDataType": "int32",

"SampleUnit": "hPA/s",

"Aggregation": {

"Function": "avg",

"Values": ["PressureNozzle"],

"TriggerSample": "OnOff"

}

},

## Comments

0 comments