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
| Property | Returns | Description |
|---|---|---|
| additive | 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. |
| fields | List<ExtraField> | The configurable fields that a metric using this metric type can be given values for. |
| id | String | The unique identifier of this metric type, used to reference it from Metric definitions. |
| title | String | The 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.
| Parameter | Description |
|---|---|
ruleParams | the metric's configured parameters |
entity | the entity being measured |
startDate | the start of the period to calculate over |
endDate | the end of the period to calculate over |
calcContext | holds 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.
| Parameter | Description |
|---|---|
ruleParams | the 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.
| Parameter | Description |
|---|---|
m | the 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.