Skip to content

PR #565: Wire batted-ball profile into hits + total_bases enrichment#434

Merged
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-565-batted-ball-profile
May 15, 2026
Merged

PR #565: Wire batted-ball profile into hits + total_bases enrichment#434
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-565-batted-ball-profile

Conversation

@jaayslaughter-cpu
Copy link
Copy Markdown
Owner

@jaayslaughter-cpu jaayslaughter-cpu commented May 15, 2026

PR #565 — Batted-ball profile signal for hits + total_bases

What

Wires get_batter_batted_ball() (already loaded from batted-ball.csv in statcast_static_layer.py) into prop_enrichment_layer.py as a live adjustment signal.

Signal design

hits props:

  • LD rate drives BABIP → (ld_rate − 0.22) / 0.06 × 3pp (league avg ~22%)
  • GB-heavy batters (>48%) get small infield-hit bonus → +1pp per 10pp above 48%

total_bases props:

  • High FB rate = fly-ball power = XBH upside → (fb_rate − 0.22) / 0.08 × 3pp
  • High pull rate = pull-side XBH/HR → (pull_rate − 0.38) / 0.10 × 2pp
  • GB-heavy batters suppress total bases → drag term

Caps: ±4pp per prop; runs through adjustment dampener (geometric decay with other same-direction signals).

Wiring

  1. New block in per-prop loop after Defense OAA section — gated on prop_type in ("hits", "total_bases") and is_batter_prop
  2. _bb_profile_adj added to dampener _all_adjs list
  3. "bb_profile" added to _layer_audit JSONB

No statcast_static_layer changes needed

get_batter_batted_ball() has been in the layer since day 1 — this PR just calls it.


Summary by cubic

Adds a batted-ball profile signal to enrich batter hits and total_bases props, using GB/FB/LD/pull rates to better model BABIP and XBH upside. Adjustments are capped at ±4pp and flow through the existing dampener with audit visibility.

  • New Features
    • New adjustment block after Defense OAA for batter hits and total_bases.
    • Hits: LD rate drives BABIP; GB-heavy (>48%) gets a small infield-hit bonus.
    • Total bases: FB and pull rates boost XBH; GB rate applies a drag.
    • _bb_profile_adj added to the dampener and bb_profile added to layer_audit.
    • Uses get_batter_batted_ball(); no changes to the static layer.

Written for commit 629a099. Summary will update on new commits.

…otal_bases enrichment

- New signal block in prop_enrichment_layer.py after Defense OAA section
- hits: LD rate → BABIP boost; GB heavy → infield-hit bonus
- total_bases: FB rate + pull rate → XBH upside; GB heavy → drag
- _bb_profile_adj flows through adjustment dampener (±4pp max)
- bb_profile added to layer_audit JSONB for observability"
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@jaayslaughter-cpu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 43 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be4b7640-e7a5-4e2a-8bb8-22b7663381e6

📥 Commits

Reviewing files that changed from the base of the PR and between c1b567d and 629a099.

📒 Files selected for processing (1)
  • prop_enrichment_layer.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-565-batted-ball-profile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented May 15, 2026

DeepSource Code Review

We reviewed changes in c1b567d...629a099 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Docker May 15, 2026 2:40a.m. Review ↗
JavaScript May 15, 2026 2:40a.m. Review ↗
Python May 15, 2026 2:40a.m. Review ↗
SQL May 15, 2026 2:40a.m. Review ↗
Secrets May 15, 2026 2:40a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@jaayslaughter-cpu jaayslaughter-cpu merged commit 76f309b into main May 15, 2026
7 of 9 checks passed
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 17 complexity

Metric Results
Complexity 17

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a batted-ball profile signal to the enrichment layer for 'hits' and 'total_bases' props, using Statcast data to adjust probabilities based on ground ball, fly ball, line drive, and pull rates. Review feedback highlights an inefficient local import that should be moved outside the loop and identifies a numerical inconsistency in the fly ball rate average used for total bases calculations, which may introduce bias.

Comment thread prop_enrichment_layer.py
_b_id_bb = prop.get("player_id") or prop.get("mlbam_id")
if _b_id_bb:
try:
from statcast_static_layer import get_batter_batted_ball as _gbb # noqa: PLC0415
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Importing get_batter_batted_ball inside the per-prop loop is inefficient. Although Python caches module imports, the lookup overhead occurs for every prop of type hits or total_bases. It is better to move this import to the top of the enrich_props function, especially since statcast_static_layer is already being imported multiple times in this function.

Comment thread prop_enrichment_layer.py
Comment on lines +1765 to +1767
# MLB avg air_rate ~0.38 (includes LD + FB)
if _fb_r > 0:
_bb_adj += (_fb_r - 0.22) / 0.08 * 0.030 # FB avg ~22%
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a numerical inconsistency between the comments and the adjustment logic for total_bases. Line 1765 states that the average air_rate (LD + FB) is ~0.38. Given that the LD average is cited as 0.22 (line 1755), this implies a FB average of 0.16. However, line 1767 uses 0.22 as the center for the FB adjustment calculation and includes a comment stating FB avg ~22%. This internal contradiction between the air_rate and fb_rate averages will likely result in a systematic bias in the calculated adjustment for league-average hitters.

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.

1 participant