Global event aggregate syntax

You use a global event aggregate to define a variable that stores the result of an aggregation of a set of events.

Purpose

You define a global event aggregate in a .agg file to store a value from the aggregated values of an event type within a solution. Create a separate .agg file for each global aggregate variable.

For example, a variable can store the number of occurrences of an event type, or an aggregated value of an attribute of the event, such as the total value, the average, the maximum, or the minimum.

For event aggregates, the value of the variable is calculated and updated locally after an event arrives. Because updates occur on all nodes in the system, the value becomes consistent only after the aggregated values are received at every node. At one time, agents on different servers might have different aggregate values.

The variable retrieves the current value at run time. You can use the variable within the rules of a rule agent.

In the definition for a global event aggregate, you can reference only one type of event.

Syntax

define '<variable_name>' as <aggregate_expression> [, where <event_filter>] [, defaulting to <number> if there is less than <time> of event history]

Description

Table 1. Mandatory constructs
Construct Description

define '<variable_name>'

Specifies the name of the variable that you can use in rules in a solution. The variable initially has the same name as the .agg file.

as <aggregate_expression>

Specifies the event instances in the working memory, and can specify a time window. The expression can reference only one type of event.

Table 2. Optional constructs
Construct Description

where <event_filter>

Determines a subset of the event instances to include in the calculation. The where construct cannot refer to an entity.

The filter must account for any event horizon properties that are set for your solution.

defaulting to <number> if there is less than <time> of event history

Specifies the default value for the global event aggregate. The number is any number. The time is a number followed by seconds, minutes, hours, days, or weeks.

Time windows

The expression in a global event aggregate indicates the time window in which the events must occur to be included in the aggregate calculation:

  • If you don’t specify a time window, the event aggregate is fixed and the calculation does not compare the time of the events and the current time. For example:
    define 'number_of_temperature_events' as the number of temperature events
    This aggregate counts the number of events from the time of the first event, theoretically forever. As more temperature events occur, the value of the global aggregate continues to rise.
  • If you specify a current time period, the event aggregate uses what is called a skipping window or tumbling window. For example:
    define 'temperatureEventCountCurrMinute' as the number of temperature events during the current minute
    This aggregate calculates its value from all the events that occur during the current minute, after which time the aggregate is reset to zero. You can think of this time window as filling a bucket of events, calculating the aggregate when the time period elapses, and then emptying the bucket of the events so that it can be refilled with new events during the next minute.
  • If you specify a last time period, the event aggregate uses what is called a sliding window. For example:
    define 'temperatureEventCountLast60Secs' as the number of temperature events during the last period of 60 seconds
    This aggregate calculates its value from all the events that occurred during the last 60 seconds, but always relative to the current time. The events are temporarily stored in memory until the time unit passes. Therefore, as each second elapses, the oldest events fall out of the time window and are no longer included in the calculation.

Examples

The following global event aggregate calculates the number of takeoff events.

define 'the number of takeoffs' as the number of takeoff events 

The following global event aggregate calculates the total delay of all the takeoff events that have more than a 5-minute delay:

define 'the total delay' as the total delay of all takeoff events, where the delay of each takeoff event is more than 5 

The following example shows a rule that uses the variable the total delay that was defined in the previous example:

if 
	'the total delay' is more than 1000000 
then 
	print "The accrued time of all delayed flights is very high!";

The following global event aggregate calculates the number of takeoff events and includes a default:

define 'the number of takeoffs' as the number of takeoff events, defaulting to 10 if there is less than 3 hours of event history