Customs Functions for MetricFunctionLibrary

#1

I am trying to create a custom function for the Metric Expression Engine.
I added these two files:

HelperLibrary.js:

type HelperLibrary mixes MetricFunctionLibrary {
  
  /**
   * bla bla
   *
  * @param value
   *        input value
   * @return absolute value of the input value.
   */
  compareStringTs: function(strA: Timeseries, strA: Timeseries): Timeseries js server
}

HelperLibrary.c3typ:

function compareStringTs(strA, strB){
    var dataA = strA.data()
    var dataB = strB.data()

    var result = []

    for(var i=0;i<dataA.length;i++){
        if (dataA[i] == dataB[i]){
            result.push(1);
        }
        else {result.push(0);}
        
    }

    return Timeseries.makeNorm(NormTimeseriesDoubleSpec.make({
    start: strA.start(),
    end: strA.end(),
    interval: strA.interval(),
    data: result
  }));

When Trying to evaluate:

var results1 = BusinessCreditApplication.evalMetrics({
        expression: "compareStringTs(BorrowerDomicileCountry, BorrowerDomicileCountry)",
        id: "test_BCA_5",
        start: "2016-12-31",
        end: "2017-02-01",
        interval: "DAY"
      });

I get the following error:

c3.love.exceptions.C3RuntimeException: c3.love.exceptions.C3RuntimeException: wrapped org.mozilla.javascript.EcmaError: TypeError: Cannot call method “data” of undefined (HelperLibrary_compareStringTs.js#2)↵↵ at org.mozilla.javascript.ScriptRuntime.constructError↵ …↵ at c3.engine.action.RhinoActionEngine.callFunk (RhinoActionEngine.java:732)↵↵ from ScbHelperLibrary_compareStringTs.js, line 2↵ 1 (function(global$) {var $ScbHelperLibrary$functions = (funct…↵ > 2 var dataA = strA.data()↵ 3 var dataB = strB.data()↵

The input metrics have been tested and returns correct results.
Why are the two inputs received by the functions Undefined?

Thank you

0 Likes

#2

First issue I can see is that the evalMetrics API takes an EvalMetricsSpec argument which only has the plural fields ids and expressions, not id and expression. Can you update that and confirm you’re getting the same error?

0 Likes