SimpleMetric/tsDecl: `value` before `filter`


#1

We have the following metric:

{
  ...
  "tsDecl": {
    ...
    "filter": "name==ServicePointCharacteristicKey.KPCS &&
               exists(evalAt) ? (compareTo(meta.created, evalAt) <= 0) : true",
    "value": "number(value)",
    ...
  },
  "srcType": "Facility",
  ...
  "variables": [{ "name": "evalAt" }]
}

whereas for filtered ServicePointCharacteristicSet objects, value has a number as a string (declared so in c3typ), but it is not a number for all objects. We get an error saying that some string cannot be converted to a number. This is happening in v7.6.1.

We will try some workarounds, but we would like to know if there are recommendations. For example, should we define a subtype of ServicePointCharacteristicSet and redefine value to be number?

EDIT: It could be a conversion inside the metric engine, not the above number function. For another kind of ServicePointCharacteristicSet, values are strings that are not numbers inside, and instead of a run-time error, such strings are converted into big numbers (probably cast from string poiners).

EDIT2: No workaround yet, but if we roll back and leave only name==ServicePointCharacteristicKey.KPCS in filter, apparently there are no problems.

Thanks


#2

There is a problem with your filter, in the case your ServicePointCharacteristicKey.KPCS is false the filter will be set to true. This means you will get other stuff and this is why number(value) throw an error as other ServicePointCharacteristicKey may have values which are not number.


#3

You nailed it! I added parentheses around the ternary and it does what I mean:

    "filter": "name==ServicePointCharacteristicKey.KPCS &&
               (exists(evalAt) ? (compareTo(meta.created, evalAt) <= 0) : true)",

Thanks,
Lisper

PS. A useful link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table