Add team hits allowed per game - #45
Merged
Merged
Conversation
Adds /hits-allowed, the mirror of the Hits page: hits surrendered by a team's pitching rather than recorded by its hitters. No migration and no new MLB request -- hits_allowed was already stored on the pitching line from #41. Two properties shape the page. The pitching figure agrees with the opposing batting row. MLB reports the two in independently fetched stat groups, and across all 162 games of the 2025 Mariners hits_allowed equals the opponent's own hits for the same game_pk, with zero mismatches. The test suite asserts that agreement against the captured fixture rather than assuming it. The MLB average comes from the batting table. Summed league-wide, hits and hits allowed are the same total over the same count of team-game records, so MLB Hits Allowed/Game == MLB Hits/Game (2025: 40,138 / 4,860 = 8.2588). The comparison therefore needs complete league-wide batting coverage, which most stored seasons have, rather than every club's pitching lines -- which is why this page shows an MLB line where the ERA comparison on /pitching usually cannot. The identity holds for the league as a whole and for no subset of it, and the module says so. Hits allowed per game is a count, so its season figure is a plain mean. H/9 is the one rate and divides summed totals; a test pins the gap between them on a season with uneven innings (6.00 per game against 9.00 per nine). Lower is better here, the reverse of the page this one mirrors. The card caption and a rendered sentence both say so rather than relying on the sign alone. Verified against the real database: 1,331 hits allowed over 1,462.2 IP, 8.22 per game, H/9 8.19, -0.04 against an MLB average of 8.26. Closes #43. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0178J2Rs8QQfS1wTqG98FSK9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/hits-allowed— the mirror of the Hits page: hits surrendered by a team's pitching rather than recorded by its hitters.No migration, no new MLB request.
hits_allowedwas already stored on the pitching line from #41.Closes #43.
The pitching figure agrees with the opposing batting row
MLB reports hits in two separate stat groups fetched in two separate requests. For any game those describe opposite sides of the same event:
Verified across all 162 games of the 2025 Mariners with zero mismatches. Two independently fetched payloads agreeing exactly is a strong signal both are parsed correctly, so the test suite asserts it against the captured fixture rather than assuming it.
The MLB average comes from the batting table
Summed league-wide, every hit is allowed by someone — so the two totals are identical over the same count of team-game records:
That is why this page can show an MLB reference line where
/pitchingusually cannot: it needs complete league-wide batting coverage, which most stored seasons already have, rather than every club's pitching lines. Only the selected team needs pitching rows.The identity holds for the league as a whole and for no subset of it — one club's hits allowed has nothing to do with its own hits. The module docstring and the page both say so, since it is easy to over-generalize.
Counts and rates
The chart is Hits Allowed/Game, a count, so its season figure is a plain mean. H/9 in the cards is a rate and divides summed totals, the way the other pitching rates do.
They diverge whenever a team pitches other than regulation length. A test pins the gap on a season with uneven innings: 6.00 per game against 9.00 per nine.
Direction
Lower is better, the reverse of the page this one mirrors. Nothing in the chart encodes that, so the summary card caption reads "Hits Allowed, Negative Is Better" and a rendered sentence states the direction in words rather than relying on the sign.
Test plan
poetry run pytest— 1402 tests passing, 94% coverage (32 new;team_hits_allowed97%,league_hits_allowed100%)poetry run ruff check ./ruff format --check .clean/hits-allowedreturns 200 with pitching stored, 409 with re-import guidance without it🤖 Generated with Claude Code
https://claude.ai/code/session_0178J2Rs8QQfS1wTqG98FSK9