Get variables used for each metric result with multiple bindings


#1

When doing evalMetrics with multiple bindings is there any way to get the values of variables used for each metric result? Calling something like

FixedAsset.evalMetrics({
    ids: ['0001'],
    expressions: ['SmartMeterMeasurementSumOverObjsSumOverTime'],
    start: DateTime.nowWithoutZone().toDateMidnight().plusDays(-1),
    end: DateTime.nowWithoutZone().toDateMidnight().plusDays(1),
    interval: 'DAY',
	include: 'bindings',
	bindings: [{r: 'Electricity', mt: 'consumption'},
             {r: 'naturalgas', mt: 'consumption'},
             {r: 'h_water', mt: 'consumption'},
             {r: 'Cooling_Water', mt: 'consumption'},
             {r: 'steam', mt: 'consumption'}]
})

gives a result of

"result" : {
    "0001" : {
      "SmartMeterMeasurementSumOverObjsSumOverTime__INTERNAL__1" : {
        "type" : "NormTimeseriesDouble",
        "m_start" : "2018-09-17T00:00:00",
        "m_end" : "2018-09-19T00:00:00",
        "m_missing" : [ 100, 100 ],
        "m_interval" : "DAY",
        "m_timeZone" : "NONE",
        "m_sourceInfo" : {
          "source" : {
            "id" : "0001",
            "moduleName" : "-type-FixedAsset",
            "typeName" : "FixedAsset"
          },
          "expr" : "SmartMeterMeasurementSumOverObjsSumOverTime__INTERNAL__1"
        }
      }
...

but I don’t see any information associated to the variables used for each result.

Side question - calling evalMetrics on multiple CompoundMetrics that all use the same parameterized SimpleMetric results in the following error:

The variable name 'r' occurs multiple times in different compound metrics. This is currently not supported. You can temporarily change the variable name

Is this a feature that is planned to be supported soon?


#2

Yes this feature is supported in v7.8

For the INTERNAL__1 replace see @resultKey on EvalMetricsSpec based on the input you can construct the key in the format that you desire


#3

Should have kept reading @romain.juban’s post I linked :slight_smile:

For future reference here’s an example:

function resultKey(expression, bindings) {
  return bindings['r'] + '_' + bindings['mt'];
}

FixedAsset.evalMetrics({
    ids: ['0001'],
    expressions: ['SmartMeterMeasurementSumOverObjsSumOverTime'],
    start: DateTime.nowWithoutZone().toDateMidnight().plusDays(-1),
    end: DateTime.nowWithoutZone().toDateMidnight().plusDays(1),
    resultKey: Lambda.fromJavaScript(resultKey),
    interval: 'DAY',
	include: 'bindings',
	bindings: [{r: 'Electricity', mt: 'consumption'},
             {r: 'naturalgas', mt: 'consumption'},
             {r: 'h_water', mt: 'consumption'},
             {r: 'Cooling_Water', mt: 'consumption'},
             {r: 'steam', mt: 'consumption'}]
})

would result in:

{
  "result" : {
    "0001" : {
      "h_water_consumption" : { ... },
      "steam_consumption" : { ... },
      "Cooling_Water_consumption" : { ... },
      "naturalgas_consumption" : { ... },
      "Electricity_consumption" : { ... }
    }
  }
}