Create a tsDecl metric for spikes


I’ve a remix of ServiceAgreementCharacteristicSet as follows:

 remix type ServiceAgreementCharacteristicSet {
  code: string
  start: datetime
  end: datetime

The values of this ServiceAgreementCharacteristicSet is of this form:

    parent: { id: },
    code: "crc04",
    value: "09-01",
    start: "2017-06-11",
    end: "2018-06-20"

The value field is a concatenation of month/day, i.e. MM-dd.

I need to create a SimpleMetric that has:

  • 1 when the datetime of the data point has a month && day that match the value field, (i.e. 09-01) && inside the start and end of the ServiceAgreementCharacteristicSet,
  • otherwise 0 everywhere else.

I tried the following but it’s not working:

    "id": "Spike_Facility",
    "name": "Spike",
    "description": "",
    "srcType": "Facility",
    "path": "servicePoints.serviceAgreements",
    "tsDecl": {
        "data": "characteristics",
        "filter": "code=='crc04'",
        "value": "1",
        "transform": "compareTo(concat(month(this.dates()), '-', day(this.dates())), value)>=0 ? 1: 0",
        "treatment": "OR",
        "start": "start",
        "end": "!empty(end) ? end : start + period(1, interval())"

Any suggestions on how to achieve this?


I don’t know if you need a tsDecl for that if everything in the path is correctly extending Timed* types
path would be “servicePoints.serviceAgreements.characteristics.(code == ‘crc04’)”
expression would be something like “(number(substring(value, 0, 2)) == month(start())) && (number(substring(value, 3, 5)) == day(start()))”

I would test it because it is a complicated metric


Yes you’re right, I should have been using the expression, don’t know why I was thinking ServiceAgreementCharacteristicSet is not timed !!
The expression seems to work but it’s returning one point for the entire interval which is expected because there’s 1 data point. But I need the start/end of the characteristic to be respected!! I will try to work on it.


Yes, this is a good lead, thanks. It should be noted that EEFs like substring and number work in tsDecl but not in pure expressions; on the other hand, start() works in pure expressions but not in tsDecl (perhaps to be implemented).

I managed to get this kind of thing to work to some extent. We now need to implement a stack-like metric: given a series of timestamped characteristics that have their validity periods, a characteristic is superseded by one with a higher timestamp, but when the latter expires, the previous one should be active again (unless it expired, too). Can you point to some complex metrics that could be useful in figuring out how to do this?

We need a non-actionDecl solution. Perhaps preprocessing the characteristics to “flatten the stack” is an option.



Could you try using something that mixes TimedIntervalCharacteristic(History) to get the start/end combined with dataVersion to get the overlap treatment you need?