Analytics example


#1

1- Create a simple DFE for every metric that will be used in the analytics:

@DFE(period='Hour', interval='QUARTER_HOUR', metric='Metric1')
type Metric1Updated mixes TSDataFlowEvent<FixedAsset>

@DFE(period='Hour', interval='QUARTER_HOUR', metric='Metric2')
type Metric2Updated mixes TSDataFlowEvent<FixedAsset>
. . .

For more details on what could be set in the definition of a DFE, from console use c3ShowType(Ann.DFE). Most important fields are:

  • interval or granularity of the data (just like with evalmetric), e.g. QUARTER_HOUR, DAY, etc.
  • period the span on time of the data that will be used in the evaluation, e.g. DAY

2- Create a compound DFE that gathers one or many simple DFEs

@DFE(period='Hour', interval='QUARTER_HOUR')
type DFEInput mixes CompoundDataFlowEvent<FixedAsset> {

    metric1Updated: Metric1Updated
    metric2Updated: Metric2Updated
    . . .
}

3- Create the type that will represent the alert which will be generated by the analytics

type FaultRuleAlert extends Alert {

  source: FixedAsset
  mode: string
  ...
}

4- Create the analytics logic

type FaultRuleBrokenAlert mixes Analytic<DFEInput, FaultRuleAlert> {
    process : ~ js server
}
function process (input) {
    // data your logic needs
    var m1 = input.metric1Updated.data();
    var m2 = input.metric2Updated.data();
    var timestamps = input.metric2Updated.dates();
    var alerts = FaultRuleAlert.array();
    // iterate over the data points
    m1.each(function(mode, index) {
      var m2Point = m2.at(index);
      var timestamp = timestamps.at(index);
      if(mode==="something that means you care about alerts") {
        alerts.push(FaultRuleAlert.make({
          source: input.source
          // set other alert fields
        }));
      }
    })
   return alerts;
}

Once code is provisioned, in your environment from console:

// check all DFEs
c3Grid(AnalyticsContainer.allDFEs())
// check all analytics
c3Grid(AnalyticsContainer.allAnalytics())

Test the analytic with AnalyticsContainer capabilities, e.g.

var sources = [
  MetricGroupInvalidationSpec.make({
    typeId: Tag.getTypeId('MY_TENANT','FixedAsset'),
    objId: 'FixedAsset_ID',
    timeRanges: [{
      start: '2018-10-01T00:00:00',
      end: '2018-10-02T10:00:00'
    }]
  })
];
var analytics = ['FaultRuleBrokenAlert'];
var options = TriggerAnalyticsOptions.make({
  forceReEval: true
})
AnalyticsContainer.fireAnalytics(sources, analytics, options)

We the created alerts, we can create a metric as follows:

remix type FixedAsset {
  alerts: [FaultRuleAlert](source)
}

The metric on FixedAsset

{
    "id": "FaultRuleAlert_FixedAsset",
    "name": "FaultRuleAlert",
    "srcType": "FixedAsset",
    "tsDecl": {
        "data": "alerts",
        "value": "value",
        "treatment": "PREVIOUS",
        "start": "timestamp"
    }
}

References:

  • Application Alert Documentation - [https://{environment}/api/1/{tenant}/{tag}/documentation/topic/documentation-alerts]
  • Analytics Documentation - [https://{environment}/api/1/{tenant}/{tag}/documentation/topic/ace]