How does one develop a new metric expression


#1

How does one develop a new metric expression?
Is this something that one develops in an app package, so whoever provisions the package can use the express? Or does it have to be in the platform code?


#2

Do you mean an expression function like sum() min() or personCorrellation()?

If so, then most of them are developed in the platform on the type ExpressionEngineFunction. You can build new functions for use specifically in metrics by declaring a new type that mixes in MetricFunctionLibrary, and then any package with that type can use that function in metric expressions. Here find an example:

type AnomalyDetectionFunctionLibrary mixes MetricFunctionLibrary {

  /**
   * Given any number of input signals, return a Timeseries of anomaly scores in
   * [0,1] using a Gaussian Mixture Model.
   *
   * @param modelTs
   *     An identity Timeseries of a trained Gaussian Mixture Model
   *
   * @return a Timeseries of anomaly scores, based on a GMM model constructed from
   *         input Timeseries.
   */
  detectAnomalies: function(modelTs: !Timeseries): !Timeseries js server

the detectAnomalies function can be used in any package where this method exists