Shared aggregates sample details

After you run the sample, you can study the source files to learn how the sample works.

Running the sample

  1. Right-click train client project and select Run As > Run Configurations.
  2. Expand Test Scenario and select Train Test.
  3. Click Run. The Console view opens and displays several messages. The messages indicate that the test driver is connected, that the entity defined in the LoadEntities.eldr file is created, and the 24 events that are defined in the SendEvents.eseq file are emitted.
  4. Review the events in Insight Inspector, which is a web application that you can use to review and troubleshoot solutions:
    1. Switch to the Samples Console perspective.
    2. In the Sample Server view, click Insights sample server > Launch the Insight Inspector to view test recordings. Insight Inspector opens in a web browser. Accept any security exception that is displayed.
    3. In Insight Inspector, click train. The solution timeline shows that the rule agent processed 24 TrainDelay events. The processing of these events causes one to three alert events to be emitted for some events.
      Insight Inspector displays the events

      This same processing results in the emission of several Alert events.

      Insight Inspector displays the alerts

Source files

The sample source files are in <InstallDir>/samples/sharedaggregates. They are imported into Decision Server Insights during the setup procedure for the sample, and include the following items:
  • train, the solution project
  • rule agent, the rule agent that is used by the solution
  • train - Java Model, which contains the Java™ interfaces of the solution
  • trainBOM, the BOM of the solution
  • train client project, which contains the JUnit test that submits the event and tests the enriched attributes

How this sample works

The entities, attributes, and events are defined in the file trainBOM/bom/train/BusinessModel.bmd. Each shared aggregate is an attribute of an entity type in the business model definitions and is specified with a data type of number or numeric. The shared aggregate definitions are on the Statements tab. For example, the aggregate named total amount reimbursed LY is defined as an attribute of the train entity:
a train is a business entity identified by a train id.
a train has a departure station.
a train has a theoric amount reimbursed (numeric).
a train has a total amount reimbursed LY (numeric).
a train has a total amount reimbursed (numeric).
a train has an average delay (numeric).
a train has a 'number of delay more than 3h' (numeric).
a train has an maximum delay LM (numeric).
a train has an maximum delay LMLY (numeric).

The sample demonstrates the following aggregation operators: maximum, minimum, average, total, and number of. It also shows different ways to define the shared aggregates.

If you always want to query the event-related aggregate over the same time period of a day or a week, for example, you can limit the events to a specified period or time point by using the during construct or a where statement in the shared aggregate definition. For example:
the total amount reimbursed LY of a train is aggregated from train delays ,
        where this train comes from the train of each train delay
    as the total amount reimbursed of all train delays during the calendar year of 1 year before now ,
        where each train delay is before 1 year before now
    available for 5 years .
If you want to query the event-related aggregate over different time periods, use rules to specify the time period and the number of events from which to calculate the result. For example, consider the following aggregate definition:
the number of delay more than 3h of a train is aggregated from train delays ,
        where this train comes from the train of each train delay
    as the number of delays of all train delays ,
        where the delay of each train delay is more than 180
        and it is not true that each train delay is on Saturday
    available for 1 years
    with a resolution of 1 hours .

In this example, the resolution of the aggregate is set to 1 hour, and the available period is 1 year. A resolution combines the data of multiple events over its specified period. You can specify a temporal resolution in the aggregation definition to improve the performance of the engine. The default resolution is 1 second. The available period defines the period during which the aggregate value can be queried.

You can define the period to be queried in the following rule:
when a train delay occurs 
if 
	the number of delay more than 3h  of 'the train' over the current year equals 5
then 
emit a new alert where 
	the message is "The number of delays that exceed 3 hours this year is 20% higher than the yearly maximum acceptable target. " ;

This is an aggregate definition that doesn't contain a reference to now. When the aggregate statement contains no conditions, a rule can specify a time period from which to retrieve a calculation.

Rebuilding the sample

After you use or modify the sample, you can rebuild it to its original state.

  1. In the Samples Commands view, open Samples Commands > Samples > Shared Aggregates.
  2. Double-click redeploy to undeploy and redeploy the solution.