Rolling averages over an NBA game log
A rolling average smooths a per-game stat over a trailing window. Fetch a player's game log with the ops, sort it oldest-first, then compute a 5-game trailing average of points — the windowed math the DSL leaves to the escape hatch.
1. Resolve the current season
curl -sS --compressed \ -H 'Authorization: Bearer YOUR_API_KEY' \ 'https://api.stat-api.com/api/v1/nba/seasons?limit=200'2. Grab one game
curl -sS --compressed \ -H 'Authorization: Bearer YOUR_API_KEY' \ 'https://api.stat-api.com/api/v1/nba/games?season_id=2025&limit=1'3. Borrow a player from that game's box score
One stat line gives a valid player_id to build the log from.
curl -sS --compressed \ -H 'Authorization: Bearer YOUR_API_KEY' \ 'https://api.stat-api.com/api/v1/nba/game_player_stats?game_id=1&limit=1'4. Page that player's full game log
curl -sS --compressed \ -H 'Authorization: Bearer YOUR_API_KEY' \ 'https://api.stat-api.com/api/v1/nba/game_player_stats?player_id=1'5. Oldest game first
Sort chronologically so the rolling window walks forward in time.
const chron = [...gamelog].sort((a, b) => a.game_date - b.game_date)6. Compute a 5-game trailing average of points
For each game, average points over the current game and the four before it.
const window = 5 for (let i = 0; i < chron.length; i++) { const start = Math.max(0, i - window + 1) const span = chron.slice(start, i + 1) const avg = span.reduce((sum, r) => sum + r.pts, 0) / span.length console.log(`game ${i + 1}: pts=${chron[i].pts}, ${window}-game avg=${avg.toFixed(1)}`) }