Global entity aggregate syntax

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

Purpose

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

For example, a variable can store an aggregated value of an attribute of an entity, such as the total value, the average, the maximum, or the minimum. For entity aggregations, the value of the variable is calculated according to a schedule.

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

In addition to the scheduled calculations, you can recalculate an entity aggregate by calling an MBean in an agent or by using the jobManager update command.

Syntax

define '<variable_name>' as <aggregate_expression>, [where <entity_filter> ,] [defaulting to <value> if there are less than <number> entities, ]
	evaluated <evaluation_schedule> .

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 entity instances in the working memory.

evaluated <evaluation_schedule>

Specifies how frequently the aggregation is calculated.

The date and time of the schedule is based on the time zone of the server on which the solution is deployed.

To specify specific recurring time points, use the following syntax for <evaluation_schedule>:

Schedule clause syntax

Seconds, if specified, are ignored.

To specify recurring intervals, use the following syntax for <evaluation_schedule>:
at intervals of <number> {second|seconds|minute|minutes|hour|hours|day|days|week|weeks}
Table 2. Optional constructs
Construct Description

where <entity_filter>

Determines a subset of the entity instances to include in the calculation.

defaulting to <value> if there are less than <number> entities

Specifies the default value to assign to the global entity aggregate unless the specified number of entities exists.

The value can be any number. The number can be any integer greater than 0.

Examples

The following example calculates the average capacity of some sizes of aircraft once a day at 2 PM:
define 'average capacity' as the average business capacity of all aircraft, where the number of seats of each aircraft is more than 20,
	evaluated every day at 2:00 PM.
The following example refers to a remote entity by specifying the planes of all aircraft types:
define 'average capacity' as the average business capacity of the planes of all aircraft, where the number of seats of each aircraft is more than 20,
	evaluated every day at 2:00 PM.
Both planes and aircraft are defined as entities in the model. Although remote entities can be used in this way, the time to run such a global entity aggregate can increase considerably.
The following examples are all valid schedule evaluation constructs:
evaluated every May 27 at 10:15 AM 
evaluated every May 27 at every hour at 15 minutes 
evaluated every May 27 at every minute 
evaluated every May 27 
evaluated every May on Friday at 10:15 AM 
evaluated every May on Friday at every hour at 15 minutes 
evaluated every May on Friday at every minute 
evaluated every May on Friday 
evaluated every May on every day at 10:15 AM 
evaluated every May at every hour at 15 minutes 
evaluated every May at every minute 
evaluated every May 
evaluated every month on 27 at 10:15 AM 
evaluated every month on 27 at every hour at 15 minutes 
evaluated every month on 27 at every minute 
evaluated every month on 27 
evaluated every Friday at 10:15 AM 
evaluated every Friday at every hour at 15 minutes 
evaluated every Friday at every minute 
evaluated every Friday 
evaluated every day at 10:15 AM 
evaluated every hour at 15 minutes 
evaluated every minute 
evaluated at intervals of 10 minutes
evaluated at intervals of 12 hours
evaluated at intervals of 1 day
The following definition of a global entity aggregate includes a default value and condition:
define 'average_capacity' as the average business class capacity of all aircraft, defaulting to 50 if there are less than 5 aircraft,
	evaluated daily at 2:00 PM