A MetricType whose calculation is delegated to a JS function, registered by an app through controllerMappings.newMetricTypeBuilder(). This is how apps contribute custom measures (for example, counts, totals or averages of domain data) that can be referenced by id from Metric definitions used in dashboards, rewards and reports. The JS function named by calcFn is invoked with the rule parameters, the entity being measured, the start and end dates, and a CalcContext, and must return a numeric value. Persisted metric type definitions of this kind are serialised to XML under the element name "metric-type".

Group: Queries

Implements: MetricType


Properties

PropertyReturnsDescription
additivebooleanWhether values calculated by this metric type for different periods can be meaningfully added together, such as sums and counts, as opposed to averages, mins or maxes.
fieldsList<ExtraField>The configurable fields that a metric using this metric type can be given values for.
idStringThe unique identifier of this metric type, used to reference it from Metric definitions.
titleStringThe display title of this metric type.

Methods

calcMetric(Map<String,String> ruleParams, BaseEntity entity, Date startDate, Date endDate, CalcContext calcContext)

Returns: BigDecimal

Calculates the metric value by invoking the JS calculation function named by calcFn, passing it the entity, rule parameters, start and end dates and the calc context. This is an expensive call, since it invokes into the JS engine.

ParameterDescription
ruleParamsthe metric's configured parameters
entitythe entity being measured
startDatethe start of the period to calculate over
endDatethe end of the period to calculate over
calcContextholds information about the calculation to assist with UI presentation

getId()

Returns: String

The unique identifier of this metric type, used to reference it from Metric definitions.

getTitle()

Returns: String

The display title of this metric type.

getFields()

Returns: List<ExtraField>

The configurable fields that a metric using this metric type can be given values for.

applicableEntityTypes(Map<String,String> ruleParams)

Returns: List<MetricEntity>

The entity types (profile, org, or both) this metric type applies to. The rule parameters are accepted for interface compatibility but are not used by this implementation, which always returns the entity types configured on the builder.

ParameterDescription
ruleParamsthe metric's configured parameters, not used by this implementation

description(Metric m)

Returns: String

The descriptive text configured on this metric type. The given metric is accepted for interface compatibility but is not used by this implementation, which always returns the same description regardless of the metric.

ParameterDescription
mthe metric to describe, not used by this implementation

isAdditive()

Returns: boolean

Whether values calculated by this metric type for different periods can be meaningfully added together, such as sums and counts, as opposed to averages, mins or maxes.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.