evalMetrics each seconds


#1

Hi,
I have a cronJob which trigger a function to generate a value for each second in the last 10 minutes.
I want to check the value of this data and for each second I try to run an evalMetrics:

var value;
var x=myType.evalMetrics({

         start: inputTimestamp,

         end:inputTimestamp,

         ids:[val.id],

         interval: "SECOND",

         expressions: [val.my_metric]

         });
var result=x.result.get(val.id).my_metric.m_data[0];
if(result==0){
		value=1
	}else{
		value=-1
	}
	 

Where my_metric.json :

{
  "name":"my_metric_name",
  "id":"my_metric",
  "expression":"costomSimpleMetric > 0"
}

If I run manually the code to generate value for a specific timerange I obtain the correct value but if I use the cronJob don’t work.

If I remove all the code (the eval metric)and I set statically var value=1; also with cronJob it works.

Thanks


#2
  1. Your snippet indicates that you are using the same start and end, so the result (if any) isn’t meaningful. Keep in mind that throughout C3 timeRanges are always end-exclusive (only way to capture the very last instant before a given date)
  2. Why do you need to run this evalMetrics every second, why not run it for the entire period?
  3. I don’t understand what your cronjob does: it evaluates a metric, then what happens?

#3

I used the same value for start and end in order to retrive a value for inputTimestamp second.
I need to run for every second because I need to validate value for each second with if condition, in a timerange I can have different value for my_metric .
The cronJob call a function which get value a priori. After I need to validate it (the function for validation is called by the function to get value)


#4
  1. Not entirely sure why it works, I suspect it should not: if you want 1 second of data, evaluate between start and start.plusSeconds(1)
  2. I recommend you do a single evalMetrics for the entire period, and then iterate on the .data() array, it will be much much (much) more efficient
  3. I still don’t understand the cronJob function, but that’s not the point of your message

#5

I change my code, actually I run the evalMetric only once for a specific timerange.
For each second I get the value from it and check it.

//code executed only once for a validTimeRange
var flame = my_type.evalMetrics({
    start: validTimeRange.start,
    end: validTimeRange.end,
    ids:[val.id],
    interval: "SECOND",
    expressions: [val.my_metric]
  });
  flame=Dataset.fromEvalMetricsResult(flame)

[...]

//code executed for each value in values/flame (length is the same)
_.each(_.zip(values.data,flame.data), function (tuple) {
      var value= (tuple[1] > 0) ? tuple[0]: -0.1 ;
      callback(value);
  });

The problem persist.

EDIT: I fixed the index (copy&paste problem


#7

Ok looks fine now, anything else?