Skip to content

TI4 Stats integration - #5413

Open
dingdong-22 wants to merge 4 commits into
AsyncTI4:masterfrom
dingdong-22:ti4-stats-integration
Open

TI4 Stats integration#5413
dingdong-22 wants to merge 4 commits into
AsyncTI4:masterfrom
dingdong-22:ti4-stats-integration

Conversation

@dingdong-22

@dingdong-22 dingdong-22 commented Jul 18, 2026

Copy link
Copy Markdown

Motivation

Currently TI4 Stats polls /statistics/recently_changed_statistics.json for stats. There are a couple of problems with this.

  1. Round 1 stats are not captured.
  2. The stats are not necessarily end of round.
  3. If multiple rounds are completed within a day the stats for earlier rounds are lost.

I would like to capture accurate end of round stats to process more insights such as round 1 strategy card picks, tech build paths, etc.

Summary

Sends game stats to the TI4 Stats API (https://ti4stats.com/api/v1/asyncti4/game_snapshots_import_jobs) at the end of each round and when a game ends.

The payload uses the same GameStatsDashboardPayload format as the existing UploadRecentStatsCron, wrapped in a {"data": [...]} envelope.

Changes

New files

  1. Ti4StatsWebsiteHelper.java - API helper. sendGameStats() serializes the game and makes a request to the API asynchronously to avoid blocking and isolate any errors from the original request. Errors are logged to Discord with a ping to my user.

Modified files

  1. StartPhaseService.java - Calls sendGameStats() in startStrategyPhase() before the round counter increments.
  2. EndGameService.java - Calls sendGameStats() in gameEndStuff() after the game is marked as ended.
  3. docker-compose.production.yml - Added TI4_STATS_API_KEY environment variable.
  4. deploy-to-production.yml - Added TI4_STATS_API_KEY environment variable.
  5. start-bot.yml - Added TI4_STATS_API_KEY environment variable.
  6. restart-bot.yml - Added TI4_STATS_API_KEY environment variable
  7. JdaService.java - Added my test server's roles.

Configuration

  1. Set TI4_STATS_API_KEY environment variable for authorization.

Testing

  1. Linted
  2. Compiled
  3. Ran tests
  4. Manually tested with a test discord bot successfully pushing data to ti4stats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant