Evaluate parametric metric with multiple bindings parameters

#1

Did you know you can now evaluate a parametric metric with multiple values for the same variable?

Let’s suppose you have a metric with 2 variables variable1 and variable2

{
“id”: “MyParametricMetric_BaseAsset”,
“name”: “MyParametricMetric”,
“srcType”: “BaseAsset”,
“expression”: “variable1 * identity(2) + variable2”,
“variables”: [ {
“name” : “variable1”,
“dataType” : “Double”
}, {
“name” : “variable2”,
“dataType” : “Double”
} ]
}

You can call MyParametricMetric with two sets of variables in one call:

BaseAsset.evalMetrics({
expressions: [“MyParametricMetric”],
ids: [“foo”],
start: “2018-01-01”,
end: “2018-01-02”,
interval: “DAY”,
bindings: [{“variable1”: 1, “variable2”: 1}, {“variable1”: 2, “variable2”: 2}]
});
You would get 2 time-series in the result: (1,1) and (2,2)

You can also generate a cartesian product of all the binding parameters like this:

BaseAsset.evalMetrics({
expressions: [“MyParametricMetric”],
ids: [“foo”],
start: “2018-01-01”,
end: “2018-01-02”,
interval: “DAY”,
bindingsCartesianProduct: true,
bindings: [{“variable1”: 1}, {“variable1”: 2}, {“variable2”: 1}, {“variable2”: 2}]
});
You would get 4 time-series in the result: (1,1), (1,2), (2,1), and (2,2)

Finally you can provide a lambda function to rename the keys of your EvalMetricsResult based on the bindings parameters:

function resultKey (expression, bindings) {
var bindingsExpression = .reduce(.map(.keys(bindings), function(key) {return key + "" + bindings[key]}), function(s1, s2) {return s1 + “" + s2;})
return expression + "
” + bindingsExpression;
}

BaseAsset.evalMetrics({
expressions: [“MyParametricMetric”],
ids: [“foo”],
start: “2018-01-01”,
end: “2018-01-02”,
interval: “DAY”,
bindingsCartesianProduct: true,
bindings: [{“variable1”: 1}, {“variable1”: 2}, {“variable2”: 1}, {“variable2”: 2}],
resultKey: Lambda.fromJavaScript(resultKey)
});
You would get 4 time-series in the result named:
MyParametricMetric_variable2_1_variable1_1
MyParametricMetric_variable2_1_variable1_2
MyParametricMetric_variable2_2_variable1_1
MyParametricMetric_variable2_2_variable1_2

3 Likes

How to include a configurable value in a metric?
Get variables used for each metric result with multiple bindings
Setup metrics for an entity that has distinct measurement series for each instance