In October, every recent-form number on Statpro, my sports stats site, quietly changed meaning. Once a league is in the postseason, a hitter's "last 10" mixes regular-season and playoff games, and nothing on the chart said which was which.
Now it does. The site shows a player's numbers over his last 5, 10 or 20 games (L5, L10 and L20). Each playoff game in one of those windows carries its round (Wild Card, Division Series and so on) in the tooltip. Season rates stay strictly regular-season, and so does the context rail, the panel of matchup details such as injuries and probable pitchers.
The labels exposed a subtraction bug
The labels were the easy half. To show "the rest of the season", the code subtracted the L20 window from the season total. Take 40 hits in 80 games, minus an L20 of 12 in 20. That gives 28 in 60.
But this October the window was mixed. Inside it, only 8 of those hits came in 15 regular-season games, so the honest remainder is 32 in 65. Subtracting a mixed window from a regular-season total throws away real games on both sides of the fraction.
The fix subtracts only the regular-season games inside the window for MLB and NBA. NFL keeps the plain subtraction, because its window is already all regular season:
const inWindow = last20.filter(g => g.seasonType === "regular");
// subtract matching subpopulations, never raw counts
const rest = {
hits: season.hits - countHits(inWindow),
games: season.games - inWindow.length,
};
Three questions for any derived number
When one number is derived by subtracting a window from a total, any change in what the window contains leaks into the result. Playoff season just makes it visible. I wrote the checklist down:
- Does this window mix season types?
- Does the subtraction match subpopulations?
- Does the label admit the mixture?