Calculate Metric Values Using Ontology Functions

You can create metric instances (and populate their fields) using certain ontology functions in rules or rule functions.

The ontology functions for creating metric instances:

  • The compute() function
  • The createOrUpdateMetric function, which is an XSLT Mapper function

Advanced users familiar with XSLT Mapper may prefer working in that interface.

To understand how fields that use complex aggregation types are computed, see Complex Aggregation Types with Auxiliary Fields.

To ensure that a metric can receive data from an entity, ensure that your rule has the entity in its scope and set any necessary conditions.

Using the Compute Function

The arguments of the compute function are the metric fields, including tracking fields. To see the function arguments, open the Ontology Function catalog, or view the tooltip for the metric’s compute function when configuring it in the rule editor.

Note:
Disabling metric tracking does not affect ontology functions
 Even if metric tracking is disabled, tracking fields are still listed in the ontology functions that compute metric data. This means that you can enable and disable tracking without having to reconfigure compute functions in rules.

Here is a sample rule with the compute function ensuring that the metric receives data from the Ticker event:

rule Rules.onTicker {
  attribute {
    priority = 5;
    forwardChain = true;
  }
  declare {
    Events.Ticker ticker;
  }
  when {
  }
  then {
    //compute the M_Ticker metric
    Dashboards.M_TickerTracker tickerTracker = Dashboards.M_TickerTracker.compute(ticker.ticker,ticker.price,ticker.volume);