igroffman commited on
Commit
125ac4e
·
verified ·
1 Parent(s): 67cf417

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +11 -11
app.R CHANGED
@@ -832,28 +832,28 @@ game_date <- if ("Date" %in% names(df)) {
832
 
833
  top_ev <- df %>%
834
  filter(!is.na(ExitSpeed), !is.na(Batter)) %>%
835
- group_by(Batter, BatterTeam) %>%
836
- summarise(MaxEV = max(ExitSpeed, na.rm = TRUE), .groups = "drop") %>%
837
- arrange(desc(MaxEV)) %>%
838
  head(5) %>%
 
839
  mutate(Batter = sapply(Batter, format_name),
840
  Logo = sapply(BatterTeam, get_logo))
841
 
842
  top_dist <- df %>%
843
  filter(!is.na(Distance), !is.na(Batter), Distance > 0) %>%
844
- group_by(Batter, BatterTeam) %>%
845
- summarise(MaxDist = max(Distance, na.rm = TRUE), .groups = "drop") %>%
846
- arrange(desc(MaxDist)) %>%
847
  head(5) %>%
 
848
  mutate(Batter = sapply(Batter, format_name),
849
  Logo = sapply(BatterTeam, get_logo))
850
 
851
  top_velo <- df %>%
852
  filter(!is.na(RelSpeed), !is.na(Pitcher)) %>%
853
- group_by(Pitcher, PitcherTeam) %>%
854
- summarise(MaxVelo = max(RelSpeed, na.rm = TRUE), .groups = "drop") %>%
855
- arrange(desc(MaxVelo)) %>%
856
  head(5) %>%
 
857
  mutate(Pitcher = sapply(Pitcher, format_name),
858
  Logo = sapply(PitcherTeam, get_logo))
859
 
@@ -1028,7 +1028,7 @@ create_postgame_pdf <- function(game_df, player_name, output_file, bio_data = NU
1028
  # Updated draw function with bat tracking support
1029
  draw_pitch_table <- function(df, y_top, row_height = 0.0135, cex = 0.58, include_bat_tracking = FALSE) {
1030
  if (include_bat_tracking) {
1031
- # Headers with bat tracking: #, Inn, Pitcher, Count, Pitch, Velo, IVB, HB, VAA, Event, EV, LA, Dist, BatSpd, AA, HAA
1032
  headers <- c("#", "Inn", "Pitcher", "Count", "Pitch", "Velo", "IVB", "HB", "VAA", "Event", "EV", "LA", "Dist", "BatSpd", "VBA", "HBA")
1033
  widths <- c(0.025, 0.03, 0.12, 0.04, 0.065, 0.04, 0.04, 0.04, 0.04, 0.065, 0.035, 0.035, 0.04, 0.045, 0.04, 0.04)
1034
  } else {
@@ -1069,7 +1069,7 @@ create_postgame_pdf <- function(game_df, player_name, output_file, bio_data = NU
1069
  ifelse(is.na(df$Dist[r]), "-", df$Dist[r]),
1070
  ifelse(is.na(df$BatSpd[r]), "-", df$BatSpd[r]),
1071
  ifelse(is.na(df$VBA[r]), "-", df$VBA[r]),
1072
- ifelse(is.na(df$V+HBA[r]), "-", df$HBA[r])
1073
  )
1074
  } else {
1075
  row_vals <- c(
 
832
 
833
  top_ev <- df %>%
834
  filter(!is.na(ExitSpeed), !is.na(Batter)) %>%
835
+ select(Batter, BatterTeam, ExitSpeed) %>%
836
+ arrange(desc(ExitSpeed)) %>%
 
837
  head(5) %>%
838
+ rename(MaxEV = ExitSpeed) %>%
839
  mutate(Batter = sapply(Batter, format_name),
840
  Logo = sapply(BatterTeam, get_logo))
841
 
842
  top_dist <- df %>%
843
  filter(!is.na(Distance), !is.na(Batter), Distance > 0) %>%
844
+ select(Batter, BatterTeam, Distance) %>%
845
+ arrange(desc(Distance)) %>%
 
846
  head(5) %>%
847
+ rename(MaxDist = Distance) %>%
848
  mutate(Batter = sapply(Batter, format_name),
849
  Logo = sapply(BatterTeam, get_logo))
850
 
851
  top_velo <- df %>%
852
  filter(!is.na(RelSpeed), !is.na(Pitcher)) %>%
853
+ select(Pitcher, PitcherTeam, RelSpeed) %>%
854
+ arrange(desc(RelSpeed)) %>%
 
855
  head(5) %>%
856
+ rename(MaxVelo = RelSpeed) %>%
857
  mutate(Pitcher = sapply(Pitcher, format_name),
858
  Logo = sapply(PitcherTeam, get_logo))
859
 
 
1028
  # Updated draw function with bat tracking support
1029
  draw_pitch_table <- function(df, y_top, row_height = 0.0135, cex = 0.58, include_bat_tracking = FALSE) {
1030
  if (include_bat_tracking) {
1031
+ # Headers with bat tracking: #, Inn, Pitcher, Count, Pitch, Velo, IVB, HB, VAA, Event, EV, LA, Dist, BatSpd, VBA, HBA
1032
  headers <- c("#", "Inn", "Pitcher", "Count", "Pitch", "Velo", "IVB", "HB", "VAA", "Event", "EV", "LA", "Dist", "BatSpd", "VBA", "HBA")
1033
  widths <- c(0.025, 0.03, 0.12, 0.04, 0.065, 0.04, 0.04, 0.04, 0.04, 0.065, 0.035, 0.035, 0.04, 0.045, 0.04, 0.04)
1034
  } else {
 
1069
  ifelse(is.na(df$Dist[r]), "-", df$Dist[r]),
1070
  ifelse(is.na(df$BatSpd[r]), "-", df$BatSpd[r]),
1071
  ifelse(is.na(df$VBA[r]), "-", df$VBA[r]),
1072
+ ifelse(is.na(df$HBA[r]), "-", df$HBA[r])
1073
  )
1074
  } else {
1075
  row_vals <- c(