patrickramos commited on
Commit
3eaff33
·
1 Parent(s): 1f837c6

Fix underestimated F-Str% and Ball%

Browse files
Files changed (1) hide show
  1. stats.py +5 -3
stats.py CHANGED
@@ -17,11 +17,13 @@ o_con = ((~pl.col('zone') & pl.col('swing') & ~pl.col('whiff')).sum()/(~pl.col('
17
  whiff = (pl.col('whiff').sum() / pl.col('swing').sum()).alias('Whiff%')
18
  swstr = (pl.col('whiff').sum() / pl.col('pitch').sum()).alias('SwStr%')
19
  csw = (pl.col('csw').sum() / pl.col('pitch').sum()).alias('CSW%')
20
- ball = ((pl.col('presult') == 'Ball').sum() / pl.col('pitch').sum()).alias('Ball%')
21
- strike = ((pl.col('pitch') & (pl.col('presult') != 'Ball')).sum() / pl.col('pitch').sum()).alias('Strike%')
 
 
22
  is_two_str = pl.col('before_s') == 2 # named this way in case I use two_str for 2-Str%
23
  first_count = (pl.col('before_s') == 0) & (pl.col('before_b') == 0)
24
- f_strike = ((pl.col('csw') & first_count).sum() / first_count.sum()).alias('F-Str%')
25
  par = (((is_two_str & pl.col('presult').str.contains('strikeout')).sum()) / is_two_str.sum()).alias('PAR%')
26
  behind = (((pl.col('before_b') > pl.col('before_s')) & (pl.col('before_s') < 2) & (pl.col('before_b') > 1)).sum() / pl.len()).alias('Behind%')
27
  zone = (pl.col('zone').sum() / pl.col('pitch').sum()).alias('Zone%')
 
17
  whiff = (pl.col('whiff').sum() / pl.col('swing').sum()).alias('Whiff%')
18
  swstr = (pl.col('whiff').sum() / pl.col('pitch').sum()).alias('SwStr%')
19
  csw = (pl.col('csw').sum() / pl.col('pitch').sum()).alias('CSW%')
20
+ is_ball = pl.col('presult').is_in(verify_and_return_presult(['Ball', 'Walk']))
21
+ is_non_ball = pl.col('pitch') & ~is_ball # pitches that are not balls i.e. no catcher interference, etc.
22
+ ball = (is_ball.sum() / pl.col('pitch').sum()).alias('Ball%')
23
+ strike = (is_non_ball.sum() / pl.col('pitch').sum()).alias('Strike%')
24
  is_two_str = pl.col('before_s') == 2 # named this way in case I use two_str for 2-Str%
25
  first_count = (pl.col('before_s') == 0) & (pl.col('before_b') == 0)
26
+ f_strike = ((is_non_ball & first_count).sum() / first_count.sum()).alias('F-Str%')
27
  par = (((is_two_str & pl.col('presult').str.contains('strikeout')).sum()) / is_two_str.sum()).alias('PAR%')
28
  behind = (((pl.col('before_b') > pl.col('before_s')) & (pl.col('before_s') < 2) & (pl.col('before_b') > 1)).sum() / pl.len()).alias('Behind%')
29
  zone = (pl.col('zone').sum() / pl.col('pitch').sum()).alias('Zone%')