Applying aggregations in Event Strategies
2 Tasks
10 mins
Beginner
Pega Platform '24.2
English
Scenario
In the Sample application, the Sample-Data-Aggregate Class is created for the exercise. The Class uses the following data structure:
Field | Type | Description |
---|---|---|
EventID |
Identifier |
Unique identifier that makes every incoming record unique. |
EventKey |
Text |
A key field that is used to group the incoming events. |
Value |
Integer |
A field that can hold integer values. |
Create an Event Strategy in the Sample-Data-Aggregate Class that calculates the following variables:
- Counts the number of events in the window.
- Sums the Value field for the events in the window.
- Stores the minimum of the Value field.
- Calculates the median of the Value field.
Use the following credentials to log in to the exercise system:
Role | User name | Password |
---|---|---|
System architect | SystemArchitect | rules |
Your assignment consists of the following tasks:
Task 1: Aggregating fields as new variables
Create a new Event Strategy in the Sample-Data-Aggregate Class: Aggregate Events.
Configure the Event Strategy:
- Use the EventKey field as the Event key and the System time field as the Event timestamp.
- Add a window component that Tumbles after every three events.
- Add an aggregate component that calculates the following variables:
- Counts the number of events as NumberOfEvents.
- Sums the Value field for each event as SumOfValues.
- Stores the Minimum of the Value field as MinValue.
- Stores the Median of the Value field as MedianValue. Use the Depends on value distribution option when calculating the median.
Task 2: Test the Aggregate Events Event Strategy
Test the behavior of the Event Strategy with the aggregate component.
Send three events for any Event Key using the values 3000, 2500, 1.
Challenge Walkthrough
Detailed Tasks
1 Aggregating fields as new variables
- Log in as the system architect:
- In the User name field, enter SystemArchitect.
- In the Password field, enter rules.
- In the navigation pane of Dev Studio, click App to open the Application Explorer.
- In the Application Explorer, search for the Sample-Data-Aggregate Class.
- In the Application Explorer, right-click on Sample-Data-Aggregate Class, then select Create > Decision> Event Strategy.
- On the Create Event Strategy tab, create a new Event Strategy:
- In the Label field, enter Aggregate Events.
- In the upper-right corner, click Create and open.
- On the Edit Event Strategy: Aggregate Events rule form, double-click on Real-time data component to set up the Real-time data properties.
- In the Event key list, select EventKey.
- In the Event timestamp section, confirm that the System time radio button is selected.
- Click Submit.
- On the canvas, on the first shape, click Add > Window to add a new Window component.
Tip: Note that the Aggregate component is grayed out. This is because the aggregations can only compute over a window.
- On the canvas, double-click the Window component to set up the Window properties:
- In the Name field, enter Three Events.
- In the Count for field, enter 3.
- Click Submit.
- On the canvas, on the Three Events window component, click Add > Aggregate to add a new Aggregate component.
- On the canvas, double-click the Aggregate component to set up the Aggregate properties:
- Click Add aggregation to define a new variable.
- In the first column, select Count,
- In the Aggregate column enter NumberOfEvents.
- Click Add aggregation to define a new variable.
- In the first column, select Sum,
- In the Source column enter or select Value.
- In the Aggregate column enter SumOfValues.
- Click Add aggregation to define a new variable.
- In the first column, select Min,
- In the Source column enter or select Value.
- In the Aggregate column enter MinValue.
- Click Add aggregation to define a new variable.
- In the first column, select Approximate Median.
- In the Source column enter or select Value.
- In the Aggregate column enter MedianValue.
- Click the Gear icon and confirm that the Depends on value distribution radio button is selected, then click OK.
Tip: The convergence speed is how fast the approximate median arrives at the closest point to the actual median value.
Depends on value distribution - the approximate median converges with the actual middle value at a set speed every time a new event arrives at the window, depending on the value distribution.
Custom speed - the approximate median converges with the actual median faster or slower, depending on the use case. When the speed increases, the calculated approximate median might be less accurate. When the speed decreases, the median might be more accurate, but it takes more time to converge.
- Click Submit.
- Click Add aggregation to define a new variable.
- In the upper-right corner, click Save.
2 Test the Aggregate Events Event Strategy
- On the Event Strategy: Aggregate Events rule form, in the upper-right corner, click Actions > Run to open the run window.
- In the Run window, complete the following settings:
- In the EventKey field, enter any value, for example, Key-1.
- In the Value field, enter 3000.
- In the upper-right corner, click Run to send a single event to the Event Strategy.
- In the Value field, enter 2500.
- In the upper-right corner, click Run only once to send a second event to the Event Strategy.
- In the Value field, enter 1.
- In the upper-right corner, click Run only once to send a third event to the Event Strategy.
- Analyze the results:
- The Sent events (3) section now has three pages.
- The Emitted events (1) section has one event emitted. This Event Strategy is configured to tumble after receiving three events in the window component.
- The Emitted events (1) section contains the aggregation variables.
Available in the following mission:
If you are having problems with your training, please review the Pega Academy Support FAQs.
Want to help us improve this content?