Problem defining metric with fileds from different sources


I have a ServicePoint that as two fields:

measurements: MeasurementSeries
motorData: [MotorData]

into the measurements i have PointMeasurement for status (bool) and for position [0.0, 1.0]
into the motorData i have the field consumption (int)

i need to create a metric for the type Facility that evaluate the sum of the expressions [status == 1 ? consumption * position : 0] for every ServicePoints.

The problem is that if i define the different simple metrics for consumption, status and position for type Facility i don’t obtain the correct value, ie:

                         consumption       status       position   _total_
     ServicePoint 1          10              1             0.5        5
     ServicePoint 2          10              1             0.5        5
     ServicePoint 3          10              0              1         0

if i call the metric on a Facility i want to obtain the value 10 (5+5+0)

so basically the idea is to evaluate the metric “by rows” instead “by columns”

my simple idea is to create SimpleMetrics for consumption, status and position and a CompoundMetric to evaluate the expression consumption * status * position but the problem is that the CompoundMetric only works for type ServicePoint and not for Facility (or better, it works but it multiplicate the aggregation of consumption, status and position. Instead i want to aggregate the multiplication between consumption, status and position over the several ServicePoints).

Any suggestions on how to do that??
Thank you


try using Facility.rollupMetrics like:

        filter: facilityId,
        expressions: ["consumption * status * position"],
        start: "2017-01-01",
        end: "2017-02-01",
        interval: "DAY",
        rollupFunc: "SUM"


Thanks Bachir,

it seems that the behavior of rollupMetrics keeps evaluate the multiplication AFTER the aggregation over the servicePoints and not before.


Try the following, define an aggregation function at Facility

remix type Facility {
  * rollupMetrics call for facility-level metrics
  aggregateMetric: function(obj: !Obj, spec: TSEvalSpec, metric: Metric, name: !string): Timeseries js server

In Facility.js

function aggregateMetric(obj, spec, metric, name) {
  return ServicePoint.rollupMetric({
    filter: Filter.eq('',,
    expressions: [name],
    start: spec.start,
    end: spec.end,
    interval: spec.interval,
    rollupFunc: 'SUM'

Then define the following SimpleMetric:

        "id": "AggregateConsumptionByStatusByPosition_Facility",
        "name": "AggregateConsumptionByStatusByPosition",
        "srcType": "Facility",
        "actionDecl": {
            "action": "aggregateMetric('ConsumptionByStatusByPosition')"

Now you can get the sum of all timesire of the metric ConsumptionByStatusByPosition (which you defined at ServicePoint level) with:

  expression: 'AggregateConsumptionByStatusByPosition',
  id: 'facility01',
  interval: ...,
  start: ...,
  end: ...


hei bachir, i tested your solution and works!!

One last question, now that i have:

  • SimpleMetric: AggregateConsumptionByStatusByPosition for Facility,
  • CompoundMetric ConsumptionByStatusByPosition for ServicePoint

Is the a way to unificate them?
Basically i tried to rename AggregateConsumptionByStatusByPosition into ConsumptionByStatusByPosition but when i call the metric on a Facility type it calls the CompoundMetric (the one for ServicePoint) and returns an error.

The error returned is:

“MetricEngine error :
Metric with name ‘Status’ for type ‘Facility’ not found! Check seed data!”

where ‘Status’ is a metric called into the CompoundMetric ConsumptionByStatusByPosition defined on ServicePoint type


It’s seems that when renaming AggregateConsumptionByStatusByPosition to ConsumptionByStatusByPosition then calling eval metric at Facility level, it actually starts evaluating the CompoundMetric which depends on the simple metrics we defined for ServicePoint (i.e. Status, Position, Consumption) and this is why it’s not able to find Status for Facility as we didn’t define one!