Can I use MetricEvaluatable.evalMetricsWithMetadata for a tsdecl metric?


#1

If so how do I do it? couldn’t find examples.


#2

Yes you can pass any metric (simple or compound) in evalMetricsWithMetadata

var exprs = ["MyTsDeclMetric"]
var sms =  [SimpleMetric.make({
    id: "MyTsDeclMetric_SrcType",
    name: "MyTsDeclMetric",
    srcType: "SrcType",
    tsDecl: {
      "data": "fkeyField",
      "treatment" : "INTEGRAL",
      "start": "timestamp",
      "value" : "myValueField" 
   }
})]
emr = SrcType.evalMetricsWithMetadata({
    ids:["MY_ID"], 
    expressions:exprs, 
    start: "2017-01-01T00:00:00.000Z", 
    end: "2018-01-01T00:00:00.000Z", 
    interval: "QUARTER_HOUR", 
}, sms); 

Also see the description for evalMetricsWithMetadata, the second argument is [Metric] which means it can be any Metric object, either SimpleMetric or CompoundMetric.

  /**
   * The api should be used only for debugging and the metrics supplied here will be used during evaluation, even if they already exist in the system
   * If a certain metric used in the expression is not supplied in the list, the fetched copy will be used for evaluation
   * @param spec
   *          The spec which specifies all the sourceIds / metrics with the corresponding start / end / interval
   * @param overrideMetrics
   *          The list of metrics that need to be overriden during evaluation
   * @return the result which contains the result of metric evaluations for various sources
   */
  evalMetricsWithMetadata: function(spec: EvalMetricsSpec, overrideMetrics: [Metric]): EvalMetricsResult


#3

Thank you very much. This was definitely a human error on my part.

I was passing in

[{
    id: "MyTsDeclMetric_SrcType",
    name: "MyTsDeclMetric",
    srcType: "SrcType",
    tsDecl: {
      "data": "fkeyField",
      "treatment" : "INTEGRAL",
      "start": "timestamp",
      "value" : "myValueField" 
   }
}]

instead of

[SimpleMetric.make({
    id: "MyTsDeclMetric_SrcType",
    name: "MyTsDeclMetric",
    srcType: "SrcType",
    tsDecl: {
      "data": "fkeyField",
      "treatment" : "INTEGRAL",
      "start": "timestamp",
      "value" : "myValueField" 
   }
})]