Skip to content

Add team hits allowed per game - #45

Merged
Mattsface merged 1 commit into
mainfrom
issue-43-hits-allowed
Aug 24, 2026
Merged

Add team hits allowed per game#45
Mattsface merged 1 commit into
mainfrom
issue-43-hits-allowed

Conversation

@Mattsface

Copy link
Copy Markdown
Member

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_allowed was 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:

team A's hits_allowed  ==  team B's hits     (same game_pk)

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:

MLB Hits Allowed/Game  ==  MLB Hits/Game

2025:  40,138 hits / 4,860 team-game records  =  8.2588

That is why this page can show an MLB reference line where /pitching usually 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_allowed 97%, league_hits_allowed 100%)
  • poetry run ruff check . / ruff format --check . clean
  • The league identity asserted directly, not assumed
  • Fixture test asserts the pitching figure is not accidentally reading the batting one (game 776704: 9 allowed, 6 recorded)
  • Verified against the real database: 1,331 hits allowed over 1,462.2 IP, 8.22/game, H/9 8.19, −0.04 against an MLB average of 8.26
  • /hits-allowed returns 200 with pitching stored, 409 with re-import guidance without it

🤖 Generated with Claude Code

https://claude.ai/code/session_0178J2Rs8QQfS1wTqG98FSK9

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
@Mattsface
Mattsface merged commit 5ba4753 into main Aug 24, 2026
1 check passed
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.

Add team hits allowed per game page

1 participant