The custom calculation formula language is based on VB and can be extended with LINQ. Use LINQ if the pre-defined CC functions are not sufficient to do your calculations.
Please refer to Microsoft Visual basic LINQ documentation for more details.
The principle of filters is to filter a given list of items according to a predicate. To apply filter, you need:
a list to filter
a predicate (function taking a list item and returning a boolean)
The result is a new list with some of the items of input list.
NOTE
The number of items in the new list is smaller than in the input list.
Syntax:
InputList.Where(Function(x) predicate)
Where: to call the filter
Function: to write the predicate
Example:
CurrentSignal.AllPeaks.Where(Function(p) p.Peak_Area>1.2 and p.Peak_Height<1000) returns a list of peaks with an area greater than 1.2 and height lower than 1000.
You can use this list in a formula to do the sum of the areas of all peaks in the list:
Sum("Peak_Area", CurrentSignal.AllPeaks.Where(Function(p) p.Peak_Area>1.2 And p.Peak_Height<1000))
The principle of projection is to create a list from a given list of items by transforming every item. To apply projection, you need:
A list to transform
A projection function (function taking a list item and returning a new item)
NOTE
The result is a new list of same length as input list. Item types can be different!
Syntax:
InputList.Select(Function(x) projection)
Select: to call the transformation
Function: to write the projection function
Example:
CurrentSignal.AllPeaks.Select(Function(p) p.Peak_Area) returns a list of Peak_Area values from a list of peaks.
You can then do the sum: CurrentSignal.AllPeaks.Select(Function(p) p.Peak_Area).Sum()
Note that this is equivalent to the predefined Custom Calculation function Sum(“Peak_Area”, CurrentSignal.AllPeaks).
The principle of aggregate is to compute a single value from a list. To apply aggregation, you need:
InputList.Select(Function(x) projection)
A list to aggregate
An accumulation function (function taking aggregate and current item)
An initial value for aggregate
NOTE
The result is a unique aggregated value. The type of aggregated value can be different from item type.
Syntax:
InputList.Aggregate(initial value,Function(acc,x) accumulation)
Aggregate: to call the aggregation
Function: to write the accumulation function
Examples:
(CurrentSignal.AllPeaks.Select(Function(p) p.Peak_Area)).Aggregate("", Function(acc,x) acc+" ; "&x) returns the list of all peaks area separated with a " ; ".
Note that this is equivalent to a VB function: string.join(" ; " ,CurrentSignal.AllPeaks.Select(Function(p) p.Peak_Area)).
(CurrentSignal.AllPeaks.Select(Function(p) p.Peak_Area)).Aggregate(0.0, Function(acc,x) acc+x) returns the sum of the peak areas.
Note that it is equivalent to the predefined Custom Calculation function Sum("Peak_Area", CurrentSignal.AllPeaks).
base-id: 9501815947
id: 9007208756556939