-
Notifications
You must be signed in to change notification settings - Fork 9
Add formulae for advancement and for double plays #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
45811ad
005405f
c396715
b5412f0
bec3b63
1698271
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -637,3 +637,109 @@ def get_triple_threshold( | |
| return float("nan") | ||
| opw_pow = pitcher_opw**1.5 | ||
| return 0.042 + 0.2 * batter_gf - 0.056 * opw_pow - 0.05 * fielder_chase + 0.1 * ballpark_sum | ||
|
|
||
| def get_double_play_threshold( | ||
| batter: PlayerData, | ||
| pitcher: PlayerData, | ||
| fielder: PlayerData, | ||
| batting_team: TeamData, | ||
| pitching_team: TeamData, | ||
| stadium: StadiumData, | ||
| meta: StatRelevantData, | ||
| ): | ||
| pitcher_vibes = pitcher.vibes(meta.day) | ||
| fielder_vibes = fielder.vibes(meta.day) | ||
|
|
||
| hype = stadium.hype * (1 if meta.top_of_inning else -1) | ||
|
|
||
| # no vibes, yes multipliers | ||
| batter_trag = batter.multiplied( | ||
| "tragicness", 1 / get_multiplier(batter, batting_team, "batter", "tragicness", meta, stadium) | ||
| ) | ||
| inv_batter_trag = 1 - batter_trag | ||
|
|
||
| pitcher_shakes = pitcher.multiplied( | ||
| "shakespearianism", get_multiplier(pitcher, pitching_team, "pitcher", "shakespearianism", meta, stadium) | ||
| ) | ||
| pitcher_shakes = (pitcher_shakes + 0.2 * hype) * (1 + 0.2 * pitcher_vibes) | ||
|
|
||
| fielder_tenac = fielder.multiplied( | ||
| "tenaciousness", get_multiplier(fielder, pitching_team, "fielder", "tenaciousness", meta, stadium) | ||
| ) | ||
| fielder_tenac = (fielder_tenac + 0.2 * hype) * (1 + 0.2 * fielder_vibes) | ||
|
|
||
| elong = stadium.elongation - 0.5 | ||
|
|
||
| return -0.05 + 0.4 * pitcher_shakes - 0.18 * inv_batter_trag + 0.1 * fielder_tenac - 0.16 * elong | ||
|
|
||
|
|
||
| def get_advance_on_hit_threshold( | ||
| runner: PlayerData, | ||
| fielder: PlayerData, | ||
| pitching_team: TeamData, | ||
| stadium: StadiumData, | ||
| meta: StatRelevantData, | ||
| ): | ||
| # no vibes | ||
| fielder_tenac = fielder.multiplied( | ||
| "tenaciousness", get_multiplier(fielder, pitching_team, "fielder", "tenaciousness", meta, stadium) | ||
| ) | ||
|
|
||
| # No mods or vibes here -- not sure if I need to use .multiplied at all | ||
| runner_cont = runner.multiplied("continuation", 1.0) | ||
|
|
||
| threshold = 0.7 - fielder_tenac + 0.6 * runner_cont | ||
| return max(min(threshold, 0.95), 0.01) | ||
|
|
||
| def get_advance_on_ground_out_threshold( | ||
| runner: PlayerData, | ||
| fielder: PlayerData, | ||
| pitching_team: TeamData, | ||
| stadium: StadiumData, | ||
| meta: StatRelevantData, | ||
| ): | ||
| runner_vibes = runner.vibes(meta.day) | ||
| fielder_vibes = fielder.vibes(meta.day) | ||
|
|
||
| # no mods | ||
| runner_ind = runner.multiplied("indulgence", 1.0) * (1 + 0.2 * runner_vibes) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to groundout_advance.ipynb it should include mods: df["threshold_rounded"] = 0.50 \
+ 0.35 * df["runner_indulgence_with_vibe"] \
- 0.10 * df["fielder_tenaciousness_with_vibe"] \
- 0.10 * (df["ballpark_inconvenience"] - 0.50) \
- 0.10 * (df["ballpark_elongation"] - 0.50) df[attr + "_scaled"] = df[attr] * df["batter_multiplier"]
df[attr + "_with_vibe"] = df[attr + "_scaled"] * (1 + 0.2 * df["batter_vibes"])
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I never got to seasons with hype... but I would guess anywhere we have vibes we should also have hype? |
||
|
|
||
| fielder_tenac = fielder.multiplied( | ||
| "tenaciousness", get_multiplier(fielder, pitching_team, "fielder", "tenaciousness", meta, stadium) | ||
| ) * (1 + 0.2 * fielder_vibes) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hype? |
||
|
|
||
| elong = stadium.elongation - 0.5 | ||
| incon = stadium.inconvenience - 0.5 | ||
|
|
||
| return 0.5 + 0.35 * runner_ind - 0.1 * fielder_tenac - 0.1 * elong - 0.1 * incon | ||
|
|
||
|
|
||
| def get_advance_on_flyout_threshold( | ||
| advancing_from: int, | ||
| runner: PlayerData, | ||
| batting_team: TeamData, | ||
| stadium: StadiumData, | ||
| meta: StatRelevantData, | ||
| ): | ||
| runner_vibes = runner.vibes(meta.day) | ||
|
|
||
| runner_ind = runner.multiplied( | ||
| "indulgence", get_multiplier(runner, batting_team, "batter", "indulgence", meta, stadium) | ||
| ) | ||
| runner_ind = runner_ind * (1 + 0.2 * runner_vibes) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hype? |
||
| runner_ind_sq = runner_ind ** 2 | ||
| runner_ind_p4 = runner_ind ** 4 | ||
|
|
||
| elong = stadium.elongation - 0.5 | ||
| inconv = stadium.inconvenience - 0.5 | ||
| park_factor = 0.10 * elong + 0.10 * inconv | ||
|
|
||
| if advancing_from == 0: | ||
| return -0.085 + 0.36 * runner_ind - 0.38 * runner_ind_sq + 0.24 * runner_ind_p4 - park_factor | ||
| elif advancing_from == 1: | ||
| return 0.045 + 0.065 * runner_ind + 0.30 * runner_ind_sq - park_factor | ||
| elif advancing_from == 2: | ||
| return 0.45 + 0.35 * runner_ind - park_factor | ||
| else: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error gets thrown 94% of the way through running resim.py because the 5th base leads to |
||
| raise RuntimeError(f"Unexpected advancing-from base {advancing_from} (expected 0, 1, or 2).") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| [project] | ||
| name = "resim" | ||
| version = "0.0.1" | ||
| dependencies = [ | ||
| "dataclasses-json>=0.6.7", | ||
| "requests>=2.34.2", | ||
| "tqdm>=4.70.0", | ||
| ] | ||
|
|
||
| [tool.black] | ||
| line-length = 120 | ||
| extend-exclude = '\.ipynb$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does need multipliers? See hit_advance.ipynb:
df["threshold_rounded"] = 0.70 - 1.0*df["fielder_tenaciousness_scaled"] + 0.60*df['runner_continuation_scaled']