igroffman commited on
Commit
2da76c5
·
verified ·
1 Parent(s): 2239b42

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +13 -4
app.R CHANGED
@@ -1277,7 +1277,14 @@ if ("TaggedPitchType" %in% names(df)) {
1277
  SwingIndicator = ifelse(PitchCall %in% c("StrikeSwinging","FoulBallNotFieldable","FoulBall","InPlay"), 1, 0),
1278
  FPindicator = ifelse(Balls == 0 & Strikes == 0, 1, 0),
1279
  FPSindicator = ifelse(PitchCall %in% c("StrikeCalled","StrikeSwinging","FoulBallNotFieldable","FoulBall","InPlay") & FPindicator == 1, 1, 0),
1280
- AheadIndicator = ifelse(((Balls == 0 & Strikes == 1) | (Balls == 1 & Strikes == 1)) & StrikeIndicator == 1, 1, 0),
 
 
 
 
 
 
 
1281
  ABindicator = ifelse(PlayResult %in% c("Error","FieldersChoice","Out","Single","Double","Triple","HomeRun") | KorBB == "Strikeout", 1, 0),
1282
  HitIndicator = ifelse(PlayResult %in% c("Single","Double","Triple","HomeRun"), 1, 0),
1283
  PAindicator = ifelse(PitchCall %in% c("InPlay","HitByPitch","CatchersInterference") | KorBB %in% c("Walk","Strikeout"), 1, 0),
@@ -1326,9 +1333,11 @@ calculate_tableau_header_stats <- function(pitcher_df) {
1326
  fp_k_pct <- ifelse(fp_pitches > 0,
1327
  round(100 * sum(pitcher_df$FPSindicator, na.rm = TRUE) / fp_pitches, 0), 0)
1328
 
1329
- ea_pct <- ifelse(fp_pitches > 0,
1330
- round(100 * (sum(pitcher_df$FPSindicator, na.rm = TRUE) +
1331
- sum(pitcher_df$AheadIndicator & pitcher_df$Balls == 0, na.rm = TRUE)) / fp_pitches, 0), 0)
 
 
1332
 
1333
  comp_pct <- ifelse(total_pitches > 0,
1334
  round(100 * sum(pitcher_df$QualityPitchIndicator, na.rm = TRUE) / total_pitches, 0), 0)
 
1277
  SwingIndicator = ifelse(PitchCall %in% c("StrikeSwinging","FoulBallNotFieldable","FoulBall","InPlay"), 1, 0),
1278
  FPindicator = ifelse(Balls == 0 & Strikes == 0, 1, 0),
1279
  FPSindicator = ifelse(PitchCall %in% c("StrikeCalled","StrikeSwinging","FoulBallNotFieldable","FoulBall","InPlay") & FPindicator == 1, 1, 0),
1280
+ EarlyIndicator = ifelse(
1281
+ ((Balls == 0 & Strikes == 0 & PitchCall == "InPlay") |
1282
+ (Balls == 1 & Strikes == 0 & PitchCall == "InPlay") |
1283
+ (Balls == 0 & Strikes == 1 & PitchCall == "InPlay") |
1284
+ (Balls == 1 & Strikes == 1 & PitchCall == "InPlay")), 1, 0),
1285
+ AheadIndicator = ifelse(
1286
+ ((Balls == 0 & Strikes == 1) & (PitchCall %in% c("StrikeCalled", "StrikeSwinging", "FoulBallNotFieldable",'FoulBall'))) |
1287
+ ((Balls == 1 & Strikes == 1) & (PitchCall %in% c("StrikeCalled", "StrikeSwinging", "FoulBallNotFieldable",'FoulBall'))), 1, 0),
1288
  ABindicator = ifelse(PlayResult %in% c("Error","FieldersChoice","Out","Single","Double","Triple","HomeRun") | KorBB == "Strikeout", 1, 0),
1289
  HitIndicator = ifelse(PlayResult %in% c("Single","Double","Triple","HomeRun"), 1, 0),
1290
  PAindicator = ifelse(PitchCall %in% c("InPlay","HitByPitch","CatchersInterference") | KorBB %in% c("Walk","Strikeout"), 1, 0),
 
1333
  fp_k_pct <- ifelse(fp_pitches > 0,
1334
  round(100 * sum(pitcher_df$FPSindicator, na.rm = TRUE) / fp_pitches, 0), 0)
1335
 
1336
+ ea_pct <- round(
1337
+ (sum(EarlyIndicator, na.rm = TRUE) + sum(AheadIndicator, na.rm = TRUE)) /
1338
+ sum(PAindicator, na.rm = TRUE) * 100,
1339
+ 1
1340
+ )
1341
 
1342
  comp_pct <- ifelse(total_pitches > 0,
1343
  round(100 * sum(pitcher_df$QualityPitchIndicator, na.rm = TRUE) / total_pitches, 0), 0)