Skip to main content

Applying aggregations in Event Strategies

2 Tasks

10 mins

Visible to: All users
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:

  1. Use the EventKey field as the Event key and the System time field as the Event timestamp.
  2. Add a window component that Tumbles after every three events.
  3. Add an aggregate component that calculates the following variables:
    1. Counts the number of events as NumberOfEvents.
    2. Sums the Value field for each event as SumOfValues.
    3. Stores the Minimum of the Value field as MinValue.
    4. 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.

 

You must initiate your own Pega instance to complete this Challenge.

Initialization may take up to 5 minutes so please be patient.

Challenge Walkthrough

Detailed Tasks

1 Aggregating fields as new variables

  1. Log in as the system architect:
    1. In the User name field, enter SystemArchitect.
    2. In the Password field, enter rules.
  2. In the navigation pane of Dev Studio, click App to open the Application Explorer.
  3. In the Application Explorer, search for the Sample-Data-Aggregate Class.
  4. In the Application Explorer, right-click on Sample-Data-Aggregate Class, then select Create > Decision> Event Strategy.
  5. On the Create Event Strategy tab, create a new Event Strategy:
    1. In the Label field, enter Aggregate Events.
    2. In the upper-right corner, click Create and open.
      Create and open
  6. On the Edit Event Strategy: Aggregate Events rule form, double-click on Real-time data component to set up the Real-time data properties.
    1. In the Event key list, select EventKey.
    2. In the Event timestamp section, confirm that the System time radio button is selected.
    3. Click Submit.
      Submit
  7. 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.
  1. On the canvas, double-click the Window component to set up the Window properties:
    1. In the Name field, enter Three Events.
    2. In the Count for field, enter 3.
      Submit 2
    3. Click Submit.
  2. On the canvas, on the Three Events window component, click Add > Aggregate to add a new Aggregate component.
    Aggregate
  3. On the canvas, double-click the Aggregate component to set up the Aggregate properties:
    1. Click Add aggregation to define a new variable.
      1. In the first column, select Count,
      2. In the Aggregate column enter NumberOfEvents.
    2. Click Add aggregation to define a new variable.
      1. In the first column, select Sum,
      2. In the Source column enter or select Value.
      3. In the Aggregate column enter SumOfValues.
    3. Click Add aggregation to define a new variable.
      1. In the first column, select Min,
      2. In the Source column enter or select Value.
      3. In the Aggregate column enter MinValue.
    4. Click Add aggregation to define a new variable.
      1. In the first column, select Approximate Median.
      2. In the Source column enter or select Value.
      3. In the Aggregate column enter MedianValue.
      4. 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.
    5. Click Submit.
      submit 3
  1. In the upper-right corner, click Save.

2 Test the Aggregate Events Event Strategy

  1. On the Event Strategy: Aggregate Events rule form, in the upper-right corner, click Actions > Run to open the run window.
  2. In the Run window, complete the following settings:
    1. In the EventKey field, enter any value, for example, Key-1.
    2. In the Value field, enter 3000.
      Value
    3. In the upper-right corner, click Run to send a single event to the Event Strategy.
    4. In the Value field, enter 2500.
    5. In the upper-right corner, click Run only once to send a second event to the Event Strategy.
    6. In the Value field, enter 1.
    7. In the upper-right corner, click Run only once to send a third event to the Event Strategy.
  3. Analyze the results:
    1. The Sent events (3) section now has three pages.
    2. The Emitted events (1) section has one event emitted. This Event Strategy is configured to tumble after receiving three events in the window component.
    3. The Emitted events (1) section contains the aggregation variables.
      Emitted events


Available in the following mission:

If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice