This content has been archived and is no longer being maintained.

Table of Contents

Article

Using event strategy in Pega Platform real-time event processing (7.3)

Event strategy is a visual representation of processing logic that is applied to all events that come from a data source in real-time. You can use event strategies to detect and query the events across a data stream and react to emerging patterns.

To use an event strategy in your application, you must create a stream data set that is the source of customer records, an Event Strategy rule that constitutes the processing instructions that are applied to the sourced data, and a data flow to trigger data processing.

Event strategy canvas

Representation of an event strategy processing pattern on the rule canvas

Prerequisites

Perform the following actions before you create and configure an event strategy:

  • Create and configure a data set that is the source of events for the Event Strategy rule. For more information, see About Data Set rules.
    Although you can select data sets of various types, the most common data set type for sourcing events is Stream. This data set type processes a continuous stream of records in real time (for example, with call details from a telecommunications network, customer transactions, and so on) and can take in high volumes of low-latency data. You can use this type of data set to save data to the stream and to browse data from the stream.
  • Ensure that the class in which you create contains the properties whose values you want to use in the event strategy, for example, call details, transaction value, and so on. In this tutorial, the following properties are used:
    • ID – The event identification number
    • CustomerID – The customer identification number
    • Value – The transaction value

Configuring an Event Strategy rule for trend detection

Configure an event strategy on a canvas-based modeler and develop your business logic by using various shapes and connectors. The following event strategy configuration detects trends in the events that are streamed in real time by comparing the moving average over two windows of different size. The goal of the event strategy is to determine whether the average value of customer transactions in the last seven days is greater than the average value for the last 31 days. The event strategy emits events when it detects an upward trend in the customer transaction value in the period of the last seven days.

Creating an Event Strategy rule

Follow these steps to create an Event Strategy rule in your application.

  1. In Designer Studio, click + Create > Decision > Event Strategy.
  2. Provide the rule label and identifier.
  3. Provide the ruleset, Applies To class, and ruleset version of the rule.
  4. Click Create and open.

Configuring the Real-time data shape

Configure the Real-time data shape that is the source of properties that come

  1. On the Event Strategy form, click the Event Strategy tab to access the modeling canvas.
  2. Right-click the Real-time data shape and click Properties.
  3. In the Properties panel, expand the Event Key list and select the property that stores the identification numbers of customers, for example, CustomerID. The Event Key property is used for grouping incoming events.
  4. In the Event timestamp section, select the System time check box. This way, your system provides the value for the time property of incoming events.
  5. Click Submit.

Splitting the strategy into multiple processing paths

For the purpose of this tutorial, you must split the strategy into two independent processing paths: primary and secondary. On each of these paths, you will store and emit events in separate windows, and then compute the average values of customer transactions over the specified period of time.

  • Click the connector that radiates from the Real-time data shape and then click Split and Join. For more information, see Split and Join logic in event strategies.

    Creating split paths

    Splitting an event strategy into two processing paths

Configuring Window shapes for storing events

Create and configure Window shapes that store and emit events at different intervals.

  1. On each path, click the connector that radiates from the Split shape, and then click Window.
  2. Configure the Window shape on the primary path:
    1. Right-click the shape and click Properties.
    2. In the Name field, enter 7 days. This window tracks the customer transactions over seven days.
    3. Select the Sliding check box. Sliding windows process events by gradually moving the window over the data in single increments. As the new events come in, the oldest events are removed. By selecting this window type, you ensure that events are tracked continuously.
    4. In the Look for last field enter 7 and select Days from the drop-down list to complete the expression.
    5. Click Submit.
  3. Configure the Window shape on the secondary path:
    1. Right-click the shape and click Properties.
    2. In the Name field, enter 31 days. This window tracks customer transactions over 31 days.
    3. Select the Sliding check box. Sliding windows process events by gradually moving the window over the data in single increments. As the new events come in, the oldest events are removed. By selecting this window type, you ensure that the events are tracked continuously.
    4. In the Look for last field enter 31 and select Days from the drop-down list to complete the expression.
    5. Click Submit.

Aggregating average transaction values for a specific time period

Create and configure Aggregate shapes that compute the moving average of credit card usage over 7 and 31 days per customer.

  1. On each path, click the connector that radiates from the Window shape, and then click Aggregate.
  2. Configure the Aggregate shape on the primary path:
    1. Right-click the shape and click Properties.
    2. In the Name field, enter Moving Average 7. This shape computes the average transaction value per customer for a period of seven days.
    3. Click Add aggregator.
    4. From the drop-down list, select Average aggregator.
    5. In the Source field, select the Value property. You can select this property only if that property belongs to the event strategy class.
    6. In the Aggregate field, enter Mean7.
  3. Configure the Aggregate shape on the secondary path:
    1. Right-click the shape and click Properties.
    2. In the Name field, enter Moving Average 31. This shape computes the average transaction value per customer for a period of 31 days.
    3. Click Add aggregator.
    4. From the drop-down list select Average aggregator.
    5. In the Source field, select the Value property. You can select this property only if that property belongs to the event strategy class.
    6. In the Aggregate field, enter Mean7.

Combining the averages

Configure the Join shape that was created when the strategy was split into two separate processing paths. In this shape, you join the average values of customer transactions over 7-day and 31-day periods to determine whether the value of customer transactions increased in the last 7 days as compared with the last month.

  1. Right-click the Join shape to open the Properties panel.
  2. In the Join section, from the drop-down list for Moving Average 7 and Moving Average 31, select the ID property of the event strategy class.
  3. In the Output section, click Add Field.
  4. Complete the output expression:
    1. Expand the drop-down list and select Mean31.
    2. Type Mean31 to complete the expression phrase From Moving Average 31 as...

Join Properties

The join expressions for joining data from the primary and secondary paths

Filtering the results

At this point in the event strategy processing path, the events that are emitted from the Join shape contain the values for both 7-day and 31-day period customer transactions. To emit only the events in which the value of customer transactions in the last seven days is trending up as compared with the last 31 days, you must add a filter shape, create a formula for trend computation, and configure the filter condition.

To compute the trending, subtract the average transaction value over 31 days from the average transaction value over 7 days, and then divide the result by the average transaction value over 31 days. Mathematically, this expression can be represented as Trend = (Mean7 - Mean31) / Mean31

You can specify your filter condition to emit only the events whose trend is greater than the specified value, for example, 0.15.

  1. Click the connector that radiates from the Join shape and select Filter.
  2. Double-click the Filter shape to open the Properties panel.
  3. In the Name field, enter Trending Up.
  4. I the Local variables section, click Add variable.
  5. In the Let field, enter mean7_minus_mean31.
  6. In the field to the left of the equals operator ("="), press the Down Arrow key and select Mean7.
  7. From the list of operators, select - (for subtraction).
  8. In the field that is located to the left of the operator list, press the Down Arrow key and select Mean31.
  9. Click Add variable.
  10. In the Let field, enter Trend.
  11. In the field to the right of the equal sign ("="), press the Down Arrow key and select mean7_minus_mean31.
  12. From the list of operators, select the division operator ("/").
  13. In the field that is located to the right of the operator list, press the Down Arrow key and select Mean31.
  14. In the Filter conditions section, click Add condition.
  15. From the list of operators, select (">").
  16. In the field to the left of the list of operators, press the Down Arrow key and select Trend.
  17. In the field to the right of the list of operators enter 0.15.
  18. Click Submit.
  19. Save the event strategy.

Trend Filter

Detecting trends in event strategies

Emitting the events

In the Emit shape, you can specify when your event strategy should emit events.

  1. Double-click the Emit shape to open the Properties panel.
  2. Expand the Emit event drop-down list and select As it happens. When this option is selected, the events and all their properties are emitted as soon as they occur.

Creating a data flow for event strategies

To activate an event strategy, you must create and configure a data flow that references that event strategy and the stream data set. Data flows offer a flexible solution for combining all your data points into a processing pattern that has a source from which the input data is taken and a destination to which the results are saved. Between the stream data set, event strategy, and destination, you can apply various other processing instructions in the form of different patterns to combine different types of data and get the best results for determining the next best action for your customers. For more information, see About Data Flow rules.

Data Flow

Data flow for event processing

Tips for event strategy testing

You can use various external or Pega-provided tools to ensure that the configuration of the Event Strategy rule and all accompanying rules produces the expected results before you deploy the configuration in the production environment.

Sending test events

You can use external tools or data from external tools or any other source to send events to test event strategies. The following list contains a sample list of tools that you can use to create and send events to the event strategy:

  • Python or R scripts – You can use the processing power of object-oriented languages such as Python or R to fully control the data that you send and to verify the results.
  • Chrome Postman plug-in – You can use the plug-in that is provided by Chrome as a browser extension to manually send events.

Monitoring the output

To effectively monitor the results of event strategy processing, you can configure the data flow that contains your event strategy to send the output to a Decision Data Store (DDS) data set to trace, inspect, and debug the data flow results.

Running data flows that contain an event strategy

Use the Data Flows landing page to trigger real-time runs of data flows that contain event strategies. For more information, see Creating a real-time run for data flows.

Published October 17, 2017 — Updated June 2, 2018

Related Content

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.