patrickramos commited on
Commit
5b874ed
·
1 Parent(s): a287b0b
Files changed (2) hide show
  1. player_team_leaderboard.py +2 -2
  2. stats.py +4 -0
player_team_leaderboard.py CHANGED
@@ -37,7 +37,7 @@ def create_player_team_leaderboard_app(player_team_type):
37
  prefix_cols = [col for col in prefix_cols if col not in ('Pitcher', 'Throws')]
38
  theme_to_cols = {
39
  'Plate Discipline': ['Swing%', 'Z-Swing%', 'Chase%', 'Contact%', 'Z-Con%', 'O-Con%', 'SwStr%', 'Whiff%', 'CSW%', 'Strike%', 'Ball%', 'F-Str%', 'PAR%', 'PLUS%'],
40
- 'Batted Ball': ['GB%', 'FB%', 'LD%', 'OFFB%', 'IFFB%', 'AIR%'],
41
  'Approach': ['Zone%', 'Arm%', 'Glove%', 'High%', 'Low%', 'MM%', 'Behind%', 'Sec%']
42
  }
43
  all_cols = prefix_cols + sum(list(theme_to_cols.values()), [])
@@ -50,7 +50,7 @@ def create_player_team_leaderboard_app(player_team_type):
50
  prefix_cols = [col for col in prefix_cols if col not in ('Batter', 'Bats')]
51
  theme_to_cols = {
52
  'Plate Discipline': ['Swing%', 'Z-Swing%', 'Chase%', 'Contact%', 'Z-Con%', 'O-Con%', 'SwStr%', 'Whiff%', 'CSW%', 'PLUS%'],
53
- 'Batted Ball': ['GB%', 'FB%', 'LD%', 'OFFB%', 'IFFB%', 'AIR%']
54
  }
55
  all_cols = prefix_cols + sum(list(theme_to_cols.values()), [])
56
  for theme, cols in theme_to_cols.items():
 
37
  prefix_cols = [col for col in prefix_cols if col not in ('Pitcher', 'Throws')]
38
  theme_to_cols = {
39
  'Plate Discipline': ['Swing%', 'Z-Swing%', 'Chase%', 'Contact%', 'Z-Con%', 'O-Con%', 'SwStr%', 'Whiff%', 'CSW%', 'Strike%', 'Ball%', 'F-Str%', 'PAR%', 'PLUS%'],
40
+ 'Batted Ball': ['GB%', 'FB%', 'LD%', 'OFFB%', 'IFFB%', 'AIR%', 'HR%'],
41
  'Approach': ['Zone%', 'Arm%', 'Glove%', 'High%', 'Low%', 'MM%', 'Behind%', 'Sec%']
42
  }
43
  all_cols = prefix_cols + sum(list(theme_to_cols.values()), [])
 
50
  prefix_cols = [col for col in prefix_cols if col not in ('Batter', 'Bats')]
51
  theme_to_cols = {
52
  'Plate Discipline': ['Swing%', 'Z-Swing%', 'Chase%', 'Contact%', 'Z-Con%', 'O-Con%', 'SwStr%', 'Whiff%', 'CSW%', 'PLUS%'],
53
+ 'Batted Ball': ['GB%', 'FB%', 'LD%', 'OFFB%', 'IFFB%', 'AIR%', 'HR%']
54
  }
55
  all_cols = prefix_cols + sum(list(theme_to_cols.values()), [])
56
  for theme, cols in theme_to_cols.items():
stats.py CHANGED
@@ -44,7 +44,10 @@ is_bip_out = pl.col('presult').is_in(verify_and_return_presult([
44
  'Sacrifice bunt', 'Sacrifice fly',
45
  "Fielder's choice", "Sacrifice fielder's choice"
46
  ]))
 
47
 
 
 
48
  register_stat('FB Velo', pl.col('FB Velo').max(), False, Player.PITCHER)
49
  register_stat('K%', pl.when(pl.col('presult').str.contains('strikeout')).then(1).otherwise(0).sum() / pl.col('pa_code').unique().len(), True, Player.PITCHER)
50
  register_stat('BB%', pl.when(pl.col('presult') == 'Walk').then(1).otherwise(0).sum() / pl.col('pa_code').unique().len(), True, Player.BATTER)
@@ -76,6 +79,7 @@ register_stat('LD%', pl.col('L'), True, Player.BATTER, True)
76
  register_stat('IFFB%', pl.col('P'), True, Player.PITCHER, True)
77
  register_stat('OFFB%', pl.col('F'), True, Player.BATTER, True)
78
  register_stat('AIR%', pl.col('F') + pl.col('P') + pl.col('L'), True, Player.BATTER, True)
 
79
 
80
  # register_stat('Usage', pl.col('count')/pl.sum('count').over('pitId'), True, None)
81
  register_stat('Usage', pl.len()/pl.first('Pitches'), True, None)
 
44
  'Sacrifice bunt', 'Sacrifice fly',
45
  "Fielder's choice", "Sacrifice fielder's choice"
46
  ]))
47
+ pa = pl.col('pa_code').unique().len()
48
 
49
+ # to-do: unify PA calculation
50
+ # pl.col('pa_code').unique().len() or pl.col('PA').first()
51
  register_stat('FB Velo', pl.col('FB Velo').max(), False, Player.PITCHER)
52
  register_stat('K%', pl.when(pl.col('presult').str.contains('strikeout')).then(1).otherwise(0).sum() / pl.col('pa_code').unique().len(), True, Player.PITCHER)
53
  register_stat('BB%', pl.when(pl.col('presult') == 'Walk').then(1).otherwise(0).sum() / pl.col('pa_code').unique().len(), True, Player.BATTER)
 
79
  register_stat('IFFB%', pl.col('P'), True, Player.PITCHER, True)
80
  register_stat('OFFB%', pl.col('F'), True, Player.BATTER, True)
81
  register_stat('AIR%', pl.col('F') + pl.col('P') + pl.col('L'), True, Player.BATTER, True)
82
+ register_stat('HR%', (pl.col('presult') == 'Home run').sum() / pa, True, Player.BATTER)
83
 
84
  # register_stat('Usage', pl.col('count')/pl.sum('count').over('pitId'), True, None)
85
  register_stat('Usage', pl.len()/pl.first('Pitches'), True, None)