Analytics example


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 =;
    var m2 =;
    var timestamps = input.metric2Updated.dates();
    var alerts = FaultRuleAlert.array();
    // iterate over the data points
    m1.each(function(mode, index) {
      var m2Point =;
      var timestamp =;
      if(mode==="something that means you care about alerts") {
          source: input.source
          // set other alert fields
   return alerts;

Once code is provisioned, in your environment from console:

// check all DFEs
// check all analytics

Test the analytic with AnalyticsContainer capabilities, e.g.

var sources = [
    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"


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