Metric evaluation in date range

#1

Hello,

i have this ServicePoint type:

remix entity type ServicePoint {
...
operationalAttr: [OperationalAttribute](servicePoint)
...
}

operationAttr is a measurement series:

entity type OperationalAttribute schema name "OPER_ATTR" {
  
  servicePoint          : ServicePoint

  startInactivePeriod   : string
  endInactivePeriod    : string

  start                 : datetime
  end                  : datetime
}

i need to create a metric that returns 1 if this metric is evaluate inside the “no working period” starting from startInactivePeriod to endInactivePeriod, 0 otherwise.

the metric should be something like that:

noWorkingPeriod = SimpleMetric.make({
    "id": "noWorkingPeriod_ServicePoint",
    "name": "noWorkingPeriod",
    "srcType": {
        "moduleName": "structure",
        "typeName": "ServicePoint"
    },
    "tsDecl": {
        "data": "operationalAttr",
        "treatment": "OR",
        "start": "start",
        "end": "end",
        "value": "_?????_"
    },
    "description": "noWorkingPeriod"
})

Hope someone can help me, thanks!

#2

What you can do is have simple metrics for the start and end of your period then combine them.

  1. SimpleMetric for start of inactivity
{
  "id": "noWorkingPeriodStart_ServicePoint",
  "name": "noWorkingPeriodStart",
  "srcType": "ServicePoint",
  "tsDecl": {
        "data": "operationalAttr",
        "treatment": "OR",
        "start": "start",
        "end": "end",
        "value": "dateTime(startInactivePeriod)"
  }
}
  1. SimpleMetric for end of inactivity
{
  "id": "noWorkingPeriodEnd_ServicePoint",
  "name": "noWorkingPeriodEnd",
  "srcType": "ServicePoint",
  "tsDecl": {
        "data": "operationalAttr",
        "treatment": "OR",
        "start": "start",
        "end": "end",
        "value": "dateTime(endInactivePeriod)"
  }
}
  1. CompoundMetric that combine both previous metrics to return 1 in case we are in the interval
{
  "id": "noWorkingPeriodEnd_ServicePoint",
  "name": "noWorkingPeriodEnd",
  "expression": "start() >= noWorkingPeriodStart && start() < noWorkingPeriodEnd"
}
#3

thanks Bachir, i found this solution:

nowork = SimpleMetric.make({
    "id": "nowork_ServicePoint",
    "name": "nowork",
    "srcType": "ServicePoint",
    "tsDecl": {
        "data": "operationalAttr",
        "treatment": "OR",
        "start": "dateTime(startInactivePeriod)",
        "end": "dateTime(endInactivePeriod)",
        "value": "1"
    },
    "description": "No Working Period"
})