Shared aggregates sample details
After you run the sample, you can study the source files to learn how the sample works.
Running the sample
- Right-click train client project and select Run As > Run Configurations.
- Expand Test Scenario and select Train Test.
- 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.
- Review the events in Insight Inspector,
which is a web application that you can use to review and troubleshoot solutions:
- Switch to the Samples Console perspective.
- 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.
- 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.
This same processing results in the emission of several Alert events.
Source files
- 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
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.
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 .
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.
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.
- In the Samples Commands view, open Samples Commands > Samples > Shared Aggregates.
- Double-click redeploy to undeploy and redeploy the solution.