Real-Time RTP Calculator
Relevant source files
The following files were used as context for generating this wiki page:
The Real-Time RTP Calculator is a core component of the SweepBot ecosystem, primarily residing within the browser extension's library. Its purpose is to provide users with immediate visibility into their Return to Player (RTP) percentages and game volatility as they play across various sweepstakes casino platforms. By intercepting transaction data in real-time, the calculator helps fulfill the project's mission of providing cross-platform transparency and data-driven intelligence that casinos typically do not disclose to players.
The calculator processes live data streams from the browser extension's interceptor to compute statistical metrics, including confidence intervals and temporal patterns. This information is then synchronized with the centralized API to update the user's dashboard and portfolio visibility.
Sources: README.md, AGENTS.md, SWEEPBOT_DASHBOARD.html
Architecture and Data Flow
The RTP Calculator operates as a bridge between the raw data intercepted from casino web traffic and the analytical insights displayed to the user. The data flow begins with the browser extension's interceptor, which captures {bet, win, balance} data from XHR/Fetch requests on supported casino sites.
Calculation Pipeline
The following diagram illustrates the lifecycle of a transaction as it is processed by the RTP Calculator and integrated into the broader system:
The diagram shows the end-to-end flow from raw network interception to the final dashboard update.
Sources: CLAUDE.md, SWEEPBOT_DASHBOARD.html
Core Features and Logic
The RTP Calculator is noted for its "statistical rigor," moving beyond simple win/loss ratios to provide sophisticated mathematical analysis of gambling outcomes.
Key Analytical Metrics
| Metric | Description | Implementation Detail |
|---|---|---|
| Real-Time RTP | Calculation of return percentage based on live sessions. | Auto-computed on session end. |
| Confidence Intervals | Statistical range indicating the reliability of the RTP data. | Differentiates SweepBot from basic trackers. |
| Volatility Analysis | Measuring the "swing" or variance in game outcomes. | Computed per game/platform. |
| Temporal Patterns | RTP trends analyzed by hour of day or day of week. | Used for the "Temporal Pattern Analysis" feature. |
Sources: SWEEPBOT_DASHBOARD.html, AGENTS.md
Integration with Session Management
The RTP calculation is deeply integrated into the session lifecycle. When a session ends via a PATCH /sessions/:id request, the API triggers an automatic RTP computation based on all transactions linked to that session. This ensures that the data persisted in the PostgreSQL database remains the source of truth for historical reporting.
Sources: SWEEPBOT_DASHBOARD.html
Component Relationships
The RTP Calculator interacts with several other modules within the apps/extension and packages/ directories to ensure data integrity and responsible play.
Implementation Context
While the specific mathematical functions are contained within apps/extension/src/lib/rtp-calculator.ts, the system-wide application of these calculations involves:
- Batch Processing: The system is optimized to handle up to 500 transactions in a single HTTP call to the
/transactions/batchendpoint, maintaining $O(1)$ complexity for session updates while recalculating totals. - Accuracy vs. Moat: The calculator uses both community-sourced data and theoretical RTP data to provide a "Trust Index" for platforms. This comparison allows users to see if a platform's actual performance aligns with its stated numbers.
- Responsible Play: Calculations are subject to non-negotiable guardrails, such as
max_duration(default 2 hours) and loop caps for automated flows.
Sources: AGENTS.md, SWEEPBOT_DASHBOARD.html, CLAUDE.md
Summary
The Real-Time RTP Calculator is a sophisticated analytical engine that transforms raw transaction data into actionable intelligence. By providing metrics like confidence intervals and volatility, it serves as a primary driver of the "data moat" SweepBot aims to build. It ensures that players have an objective, mathematically sound view of their activity across multiple sweepstakes platforms, integrated seamlessly into the browser extension and web dashboard.
Sources: README.md, SWEEPBOT_DASHBOARD.html