How keshavraj7/ratingpredictorcf works
1. This is a Chrome Extension Manifest V3 project, not a standalone app. Its runtime is split across a background service worker, a content script that runs on Codeforces standings pages, and small UI/assets for injected display and a popup shell.
2. The main architectural boundary is the browser page vs. extension logic. The extension activates on Codeforces contest standings, reads the page context, calls Codeforces APIs from extension code, computes predictions locally, then writes the results back into the standings table.
3. background/service-worker.js is the orchestration layer. It likely coordinates contest detection, API request sequencing, batching/parallelization, and response caching so the content script can stay focused on DOM work.
4. The API boundary is isolated in api/apiCf.js, which wraps Codeforces endpoints such as contest.standings and user.info. api/cache.js adds a local cache layer to reduce repeated requests, which is important because rating lookup can involve thousands of participants.
5. content/standings.js is the DOM integration layer. It parses standings pages, identifies the rows/handles to enrich, and injects extra columns into either common standings or friends standings without requiring user interaction.
6. The rating prediction engine lives in rating/predictor.js and rating/calculator.js. This subsystem takes standings plus participant ratings and produces estimated performance rating and predicted delta, using a probabilistic model inspired by Codeforces’ rating behavior.
7. The heavy math helpers are in util/conv.js and util/binsearch.js. These support the optimized expectation calculations described in the README, including FFT-style convolution and search routines used to avoid naive quadratic pairwise computation.
8. The end-to-end data flow is: standings page → contest/participant extraction → Codeforces API fetches → cache lookup/update → rating model computation → DOM injection of predicted columns. This is a browser-only pipeline; there is no external backend service.
9. The extension’s performance profile is dominated by API latency, not local computation. The FFT-based predictor is meant to keep local processing fast enough for very large contests, while chunked/parallel user.info requests keep total wait time practical.
10. styles/predictor.css handles visual integration of the injected columns so the added rating data blends into Codeforces’ table UI. popup.html is present as the extension shell/popup entry point, but the core product experience is page injection on standings screens.
11. A notable functional constraint is that the current implementation uses current participant ratings even when predicting historical contests. That means the architecture is optimized for live/ongoing prediction accuracy and validation, rather than full historical reconstruction.
Main entry points: service-worker.js Service worker · predictor.js Predictor · standings.js Standings script · manifest.json Manifest V3
Components 12
Browser extension runtime
Manifest V3 extension pieces that run in the page and extension context.
- Manifest V3 · Declares extension entry points and permissions.
manifest.json - Service worker · Coordinates contest flow, request sequencing, and handoff to content script.
background/service-worker.js - Standings script · Reads Codeforces standings pages, extracts rows, and injects predicted columns.
content/standings.js
Data and model
Codeforces API access, caching, and rating computation.
- CF API client · Wraps Codeforces endpoints such as standings and user info.
api/apiCf.js - API cache · Caches API responses to reduce repeated lookup traffic.
api/cache.js - Predictor · Computes performance estimates and predicted rating deltas.
rating/predictor.js - Calculator · Implements the rating expectation and delta calculations.
rating/calculator.js - Convolution · Fast expectation helper using convolution-style computation.
util/conv.js - Binary search · Search utilities supporting optimized rating calculations.
util/binsearch.js
Injected UI
Presentation assets and extension shell.
- Popup shell · Extension popup entry point.
popup.html - Predictor CSS · Styles injected rating columns to match Codeforces tables.
styles/predictor.css
Other components
- README · Documents the predictor workflow and constraints.
README.md
Connections 15
- Manifest V3 → Service worker: registers · Declares the background service worker.
- Manifest V3 → Standings script: injects · Loads the standings content script on matching pages.
- Manifest V3 → Popup shell: exposes · Provides the extension popup shell.
- Standings script → Service worker: requests data · Asks the service worker for contest and participant information.
- Service worker → CF API client: fetches · Orchestrates Codeforces API calls.
- CF API client → API cache: checks · Reads and updates cached API responses.
- Service worker → Predictor: runs · Triggers local prediction calculations.
- Predictor → Calculator: uses · Delegates core rating math.
- Calculator → Convolution: uses · Relies on convolution helpers for efficient expectation math.
- Calculator → Binary search: uses · Relies on search helpers for optimized thresholds.
- Predictor → Standings script: returns · Produces predicted rating data for DOM injection.
- Standings script → Predictor CSS: applies · Pairs injected table columns with extension styling.
- CF API client → Predictor: supplies · Provides standings and user ratings to the model.
- README → Predictor: describes · Documents the modeling approach and constraints.
- README → Service worker: describes · Explains the browser-only pipeline and orchestration.