Multichem commited on
Commit
404a89f
·
verified ·
1 Parent(s): 0197b24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -75,13 +75,13 @@ def init_baselines():
75
  return hitter_rhp, hitter_lhp, pitcher_rhh, pitcher_lhh
76
 
77
  @st.cache_resource
78
- def calc_poisson(hitter_val, sp_val):
79
  base_val = hitter_val
80
  opp_val = sp_val
81
  sp_combo_val = sum([base_val, opp_val]) / 2
82
  bp_combo_val = sum([base_val, .085]) / 2
83
- sp_instances = 1
84
- bp_instances = 0
85
  sp_mean = sp_combo_val * sp_instances
86
  bp_mean = bp_combo_val * bp_instances
87
 
@@ -118,10 +118,14 @@ with col1:
118
  hitter_var1 = st.selectbox("What hitter are you looking at?", options = hitter_lhp['Player'].unique())
119
  working_hitters = hitter_lhp.copy()
120
  hitter_check = working_hitters[working_hitters['Player'] == hitter_var1]
 
 
121
 
122
  with col2:
123
- st.write(pitcher_hand)
124
- hitter_val = hitter_check['BB%'].iloc[0]
125
- sp_val = pitcher_check['BB%'].iloc[0]
126
- value = calc_poisson(hitter_val, sp_val)
127
- st.write(value)
 
 
 
75
  return hitter_rhp, hitter_lhp, pitcher_rhh, pitcher_lhh
76
 
77
  @st.cache_resource
78
+ def calc_poisson(hitter_val, sp_val, sp_count, bp_count):
79
  base_val = hitter_val
80
  opp_val = sp_val
81
  sp_combo_val = sum([base_val, opp_val]) / 2
82
  bp_combo_val = sum([base_val, .085]) / 2
83
+ sp_instances = sp_count
84
+ bp_instances = bp_count
85
  sp_mean = sp_combo_val * sp_instances
86
  bp_mean = bp_combo_val * bp_instances
87
 
 
118
  hitter_var1 = st.selectbox("What hitter are you looking at?", options = hitter_lhp['Player'].unique())
119
  working_hitters = hitter_lhp.copy()
120
  hitter_check = working_hitters[working_hitters['Player'] == hitter_var1]
121
+ sp_count = st.number_input("How many PA against the Pitcher?")
122
+ bp_count = st.number_input("How many PA against the Bullpen?")
123
 
124
  with col2:
125
+ if st.button('calculate theoretical means'):
126
+ hitter_val = hitter_check['BB%'].iloc[0]
127
+ sp_val = pitcher_check['BB%'].iloc[0]
128
+ value = calc_poisson(hitter_val, sp_val, sp_count, bp_count)
129
+ st.write(f"Theoretical mean of the SP instances: {value[0]}")
130
+ st.write(f"Theoretical mean of the BP instances: {value[1]}")
131
+ st.write(f"Sample mean from generated data: {value[2]}")