User betting behavior analysis
Identify high-risk and high-value users by analyzing and identifying trends in user betting patterns.
Overview
Betting platforms, sports analysts, and market regulators benefit from analyzing and interpreting users’ betting patterns. For sports analysts, this data helps gauge fan sentiment and engagement, allowing them to identify high-profile events and fine-tune their marketing strategies. Regulators, on the other hand, focus on ensuring fair play and compliance with gambling laws. They use these insights to prevent illegal activities, such as match-fixing or money laundering.
During live events, users’ behaviors can shift rapidly in response to gameplay developments. Processing and analyzing these changes in real-time allows platforms to flag high-risk users, who may be more likely to engage in fraudulent activities. By joining historic data on user behavior with live betting data, platforms can easily identify high-risk users for further investigation to mitigate potential risks.
In this tutorial, you will learn how to analyze users’ betting behaviors by integrating historical datasets with live data streams.
Prerequisites
- Ensure that the PostgreSQL interactive terminal,
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL. - Install and run RisingWave. For detailed instructions on how to quickly get started, see the Quick start guide.
- Ensure that a Python environment is set up and install the psycopg2 library.
Step 1: Set up the data source tables
Once RisingWave is installed and deployed, run the three SQL queries below to set up the tables. You will insert data into these tables to simulate live data streams.
-
The table
user_profiles
table contains static information about each user. -
The
betting_history
table contains historical betting records for each user. -
The
positions
table has real-time updates for ongoing betting positions for each user.
Step 2: Run the data generator
To keep this demo simple, a Python script is used to generate and insert data into the tables created above.
Clone the awesome-stream-processing repository.
Navigate to the user_betting_behavior folder.
Run the data_generator.py
file. This Python script utilizes the psycopg2
library to establish a connection with RisingWave so you can generate and insert synthetic data into the tables positions
and market_data
.
If you are not running RisingWave locally or using default credentials, update the connection parameters accordingly:
Step 3: Create materialized views
In this demo, you will create multiple materialized views to understand bettors’ behavior trends.
Materialized views contain the results of a view expression and are stored in the RisingWave database. The results of a materialized view are computed incrementally and updated whenever new events arrive and do not require to be refreshed. When you query from a materialized view, it will return the most up-to-date computation results.
Identify user betting patterns
The user_betting_patterns
materialized view provides an overview of each user’s betting history, including their win/loss count and average profit.
You can query from user_betting_patterns
to see the results.
Summarize users’ exposure
The real_time_user_exposure
materialized view sums up the stake amounts of active positions for each user to track each user’s current total exposure in real-time.
With this materialized view, you can filter for users who may be overexposed.
You can query from real_time_user_exposure
to see the results.
Flag high-risk users
The high_risk_users
materialized view identifies high-risk users by analyzing their risk tolerance, exposure, and profit patterns.
A user is considered high-risk if they meet all of the following criteria:
- The total exposure is five times greater than their average bet size. You can customize this threshold to be lower or higher.
- Their average profit loss is less than zero.
Some users who are not initially categorized as high-risk may exhibit behaviors that indicate they are high-risk users.
You can query from high_risk_users
to see the results.
When finished, press Ctrl+C
to close the connection between RisingWave and psycopg2
.
Summary
In this tutorial, you learn:
- How to perform a multi-way join.
Was this page helpful?