See who actually scored on a slate
dfs.player_stats reports what each player on a slate actually scored under that operator's scoring rules, together with the salary they cost. This recipe ranks a slate by real points. It also shows the trap that catches everyone the first time: a rostered player who never took a snap still returns a row, with every stat null.
- What it is
- Reports what every player on a slate actually scored under that operator's own rules, and ranks them.
- When to use it
- Use it to review a completed slate, to measure how often chalk delivered, or to build the training labels for a projection model.
- What you get back
- One row per player in the pool, with real fantasy points, the salary paid, and a null score for anyone who did not play.
1.Page the player pool for names
player_stats identifies players by player_id only. The pool carries the display names, so fetch it once and index it.
const pool: DFSSlatePlayer[] = []
for await (const row of api.dfs.slate_players.iter({ slate_id: 129036 })) pool.push(row)The complete program
Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.
import { StatApi, type DFSPlayerStat, type DFSSlatePlayer } from '@stat-api/client'
const api = new StatApi() // reads STAT_API_KEY from the environment
// Page the player pool for names
const pool: DFSSlatePlayer[] = []
for await (const row of api.dfs.slate_players.iter({ slate_id: 129036 })) pool.push(row)
// Index the pool by player id
const names = new Map<number, DFSSlatePlayer>()
for (const row of pool) names.set(row.player_id, row)
// Page the slate's scoring rows
const stats: DFSPlayerStat[] = []
for await (const row of api.dfs.player_stats.iter({ slate_id: 129036 })) stats.push(row)
// Drop the players who did not play
const scored = stats.filter((row) => row.fantasy_pts !== null && row.fantasy_pts !== undefined)
// Rank by fantasy points
const best = [...scored].sort((a, b) => (b.fantasy_pts ?? 0) - (a.fantasy_pts ?? 0))
// Take the top fifteen
const top = best.slice(0, 15)
// Print the scoring board
console.log("Top scorers on the slate")
console.log(["display_name", "position", "salary", "fantasy_pts"].join('\t'))
for (const row of top) {
console.log([String(names.get(row.player_id)?.display_name ?? row.player_id), String(row.position ?? ''), String(row.salary ?? ''), String(row.fantasy_pts ?? '')].join('\t'))
}