patrickramos commited on
Commit
341d615
·
1 Parent(s): 4867feb

Make pitch locations represent top 40% of pitches instead of 68%

Browse files
Files changed (3) hide show
  1. data.py +1 -0
  2. plotting.py +1 -1
  3. stats.py +2 -1
data.py CHANGED
@@ -311,6 +311,7 @@ data_df = (
311
  .with_columns((pl.col('x').is_between(-40, 40) & pl.col('y').is_between(75, 75+100)).alias('heart'))
312
  .with_columns((pl.col('x').is_between(-80, 80) & pl.col('y').is_between(25, 25+200) & ~pl.col('heart')).alias('shadow'))
313
  .with_columns((pl.col('x').is_between(-100, 101) & pl.col('y').is_between(0, 0+251) & ~pl.col('heart') & ~pl.col('shadow')).alias('chase'))
 
314
  )
315
 
316
  if __name__ == '__main__':
 
311
  .with_columns((pl.col('x').is_between(-40, 40) & pl.col('y').is_between(75, 75+100)).alias('heart'))
312
  .with_columns((pl.col('x').is_between(-80, 80) & pl.col('y').is_between(25, 25+200) & ~pl.col('heart')).alias('shadow'))
313
  .with_columns((pl.col('x').is_between(-100, 101) & pl.col('y').is_between(0, 0+251) & ~pl.col('heart') & ~pl.col('shadow')).alias('chase'))
314
+ .filter(pl.col('ballKind_code') != '-')
315
  )
316
 
317
  if __name__ == '__main__':
plotting.py CHANGED
@@ -84,7 +84,7 @@ def plot_loc(ax, locs):
84
  sorted_Z = np.sort(Z_flat)
85
  sorted_Z_idxs = np.argsort(Z_flat)
86
  Z_cumsum = (sorted_Z).cumsum()
87
- t = Z_flat[sorted_Z_idxs[np.argmin(np.abs(Z_cumsum - (1-0.68)))]]
88
 
89
  ax.contourf(X, Y, Z, levels=[t, 1], colors=ball_kind_code_to_color[pitch], alpha=0.5)
90
  ax.contour(X, Y, Z, levels=t.reshape(1), colors=ball_kind_code_to_color[pitch], alpha=0.75)
 
84
  sorted_Z = np.sort(Z_flat)
85
  sorted_Z_idxs = np.argsort(Z_flat)
86
  Z_cumsum = (sorted_Z).cumsum()
87
+ t = Z_flat[sorted_Z_idxs[np.argmin(np.abs(Z_cumsum - (1-0.4)))]]
88
 
89
  ax.contourf(X, Y, Z, levels=[t, 1], colors=ball_kind_code_to_color[pitch], alpha=0.5)
90
  ax.contour(X, Y, Z, levels=t.reshape(1), colors=ball_kind_code_to_color[pitch], alpha=0.75)
stats.py CHANGED
@@ -164,7 +164,7 @@ def compute_pitcher_stats(data, min_ip='qualified'):
164
 
165
 
166
  def get_pitcher_stats(id, lr=None, game_kind=None, start_date=None, end_date=None, min_ip=1, min_pitches=1, pitch_class_type='specific'):
167
- source_data = data_df.filter(pl.col('ballKind_code') != '-')
168
 
169
  # if start_date is not None:
170
  # source_data = source_data.filter(pl.col('date') >= start_date)
@@ -173,6 +173,7 @@ def get_pitcher_stats(id, lr=None, game_kind=None, start_date=None, end_date=Non
173
  #
174
  # if game_kind is not None:
175
  # source_data = source_data.filter(pl.col('coarse_game_kind') == game_kind)
 
176
  source_data = filter_data_by_date_and_game_kind(source_data, start_date=start_date, end_date=end_date, game_kind=game_kind)
177
 
178
  source_data = (
 
164
 
165
 
166
  def get_pitcher_stats(id, lr=None, game_kind=None, start_date=None, end_date=None, min_ip=1, min_pitches=1, pitch_class_type='specific'):
167
+ # source_data = data_df.filter(pl.col('ballKind_code') != '-')
168
 
169
  # if start_date is not None:
170
  # source_data = source_data.filter(pl.col('date') >= start_date)
 
173
  #
174
  # if game_kind is not None:
175
  # source_data = source_data.filter(pl.col('coarse_game_kind') == game_kind)
176
+ source_data = data_df
177
  source_data = filter_data_by_date_and_game_kind(source_data, start_date=start_date, end_date=end_date, game_kind=game_kind)
178
 
179
  source_data = (