Testing Expression Engine Functions in DS server

#1

Hi There,

I am trying to test a new expression engine function for the first time.
This is for the purpose of doing a rolling window correlation.
How do I test its working in the Data Science Server and Console.
Expression Engine Function type:

type SimpleCorrelationMetricLibrary mixes MetricFunctionLibrary {

  /**
   *  Calculates correlation across inputs
   *
   * @param Y
   *           The dependant variable of interest.
   * @param x
   *           The independant variable that is believed to have some causality on Y.
   * 
   * @return Pearson R score for measure of correlation.
   */

  simpleCorrelation: function( Y:Timeseries,
                           x: Timeseries
                                        ): Timeseries py server
}

Python File

def simpleCorrelation(Y,x):
    a = (np.corrcoef(Y, x))
    flat_list = [item for sublist in a for item in sublist]
    r = (flat_list[1])

    return transformToTimeseries(r)

metric?

{
  "id" : "CalculatedCorrelation",
  "name" : "CalculatedCorrelation",
  "expression" : "simpleCorrelation(Y, x)"
}

How do I test it to see if it works in the Data Science server and the Console?
also could someone stand me up with a generic print function so I can see what data I am passing in?

GasIsIncreasing = c3.CompoundMetric(
    id="GasWaterCorrelation",
    name="GasWaterCorrelation",
    expression="(window('simpleCorrelation', WellMeasurementGasRate, WellMeasurementWaterRate)"
)
0 Likes

#2

You should be able to test your function by directly but calling:

SimpleCorrelationMetricLibrary.simpleCorrelation(Y, X)

As you defined in your function both Y and X are of type Timeseries. So you need to create those Timeseries by, for example, running the evalMetric() API, which returns a Timeseries. I know that this works in the JS console and believe it should still function in DS server.

One other point on the last code block you posted, I believe you mean to create the following metric:

GasIsIncreasing = c3.CompoundMetric(
    id="GasWaterCorrelation",
    name="GasWaterCorrelation",
    expression="'simpleCorrelation(WellMeasurementGasRate, WellMeasurementWaterRate)"
)
0 Likes

#3

Of course, best practice is to formalize your test script by writing a jasmine test

You can also create arbitrary Timeseries locally w/o calling evalMetric using Timeseries.makeNorm or Timeseries.fromObjs

0 Likes