How to fix value when is missing


#1

Hi,
I would like to set values to 10 from simple metric when values are missing for a specific timerange.

I tried with Tsdecl :

ts=TSDecl.make({
    "data": "data",
    "start": "start",
    "treatment": "AVG",
    "value": "fillMissing(value,10)" 
})

result= my_type.evalMetricsWithMetadata({
"interval":"SECOND",
"start": time.start,
"end": time.end,
"include":"start, end, dates, data",
"ids": [my_ids],
"expressions": ["expr_name"]

},[
SimpleMetric.make({name:"expr_name", 
                     id:"expr_name", 
                     srcType : my_type,
	             path: my_path,
                     tsDecl : ts}),
])

If I see x with c3Viz(x) all values are 0, if I see the m_missing in x all values are 100.

How I can achieve my goal?

Thanks


#2

You need to wrap your simple metric in a compound one and check for missing or not using the available expression function, e.g.

{
    "name": "compound_metric_name", 
    "id": "compound_metric_name", 
    "expression": "available(expr_name)? expr_name: 10"
}

#3

Ok, good, but there is a way to avoid use of another compound metric and do all of things in a simple metric?


#4

Yes you can add all this in your simple metric, so in your TSDecl metric, use transform to do the checking. In your case, replacing missings by a constant should be like this:

{
  "id" : "expr_name",
  "name" : "expr_name",
  "srcType" : my_type,
  "tsDecl" : {
    .....
    "transform" : "fillMissing(this, 10)"
  },
  "path" : "my_path"
}

But it;s a good practice to split custom logic (like here returning a constant for missing) from the actual raw timeseries.


#5

Thank you, but neither in this way the code works.

ts=TSDecl.make({
    "data": "data",
    "start": "start",
    "transform": "fillMissing(this, 10)",
    "treatment" : "AVG"
})

result=my_type.evalMetricsWithMetadata({
"interval":"SECOND",
"start": time.start,
"end": time.end,
"include":"start, end, dates, data",
"ids": [my_ids],
"expressions": ["pred"]

},[
SimpleMetric.make({name:"pred", 
                     id:"pred", 
                     srcType : "my_type",
    tsDecl : ts,
path: "my_path"})
])


#6

what do you mean does not work? you see missings (i.e. all 0s)?
Can you share the structure of your type?