igroffman commited on
Commit
8fdf227
·
verified ·
1 Parent(s): 5be2ddf

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +9 -9
app.R CHANGED
@@ -20,9 +20,9 @@ if (!requireNamespace("magick", quietly = TRUE)) {
20
  }
21
 
22
  team_meta <- tryCatch({
23
- read.csv("TMB.csv", stringsAsFactors = FALSE)
24
  }, error = function(e) {
25
- message("TMB.csv not found - logos will not display")
26
  NULL
27
  })
28
 
@@ -619,7 +619,7 @@ plot_data <- df %>%
619
  ggplot2::scale_y_continuous(NULL, limits = c(y_min_needed, 60/12)) +
620
  ggplot2::coord_fixed(ratio = 1.3, clip = "off") +
621
  ggplot2::scale_fill_manual(values = c(
622
- "Fastball" = "#FA8072", "Four-Seam" = "#FA8072", "Sinker" = "#fdae61",
623
  "Slider" = "#A020F0", "Sweeper" = "magenta", "Curveball" = "#2c7bb6",
624
  "ChangeUp" = "#90EE90", "Splitter" = "#90EE32", "Cutter" = "red"
625
  ), name = "Pitch Type") +
@@ -1116,7 +1116,7 @@ catcher_create_framing_plots <- function(catcher_data, catcher_name) {
1116
  strikes_added <- df %>% filter(frame == "Strike Added")
1117
  strikes_lost <- df %>% filter(frame == "Strike Lost")
1118
  pitch_colors <- c(
1119
- "Fastball"="#FA8072","Four-Seam"="#FA8072","Sinker"="#fdae61","Slider"="#A020F0",
1120
  "Sweeper"="magenta","Curveball"="#2c7bb6","ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red"
1121
  )
1122
 
@@ -2354,7 +2354,7 @@ sec_averages <- list(
2354
  )
2355
 
2356
  sec_extension_benchmark <- function(pt) {
2357
- if (pt %in% c("Fastball","Four-Seam","Four Seam","Fourseam","Sinker","Two-Seam","2-Seam")) return(5.83)
2358
  if (pt %in% c("Slider","Sweeper")) return(5.54)
2359
  if (pt %in% c("Curveball","Knuckle Curve")) return(5.47)
2360
  if (pt %in% c("ChangeUp","Splitter")) return(5.98)
@@ -2656,7 +2656,7 @@ create_advanced_pitch_characteristics <- function(data, player_name) {
2656
  for (i in seq_len(num_rows)) {
2657
  pt <- pitch_stats$Pitch[i]
2658
 
2659
- sec_ref <- if (pt %in% c("Fastball","Four-Seam","Sinker","Two-Seam","2-Seam")) {
2660
  sec_averages$fb_sinker
2661
  } else if (pt %in% c("Cutter")) {
2662
  sec_averages$cutter
@@ -2670,7 +2670,7 @@ create_advanced_pitch_characteristics <- function(data, player_name) {
2670
 
2671
  if (!is.null(sec_ref)) {
2672
  velo_bench <- NA_real_
2673
- if (tolower(pt) %in% c("fastball","four-seam","four seam","fourseam","sinker","two-seam","2-seam")) {
2674
  velo_bench <- if (identical(pitcher_hand, "Left")) sec_averages$overall$fb_velo_l else sec_averages$overall$fb_velo_r
2675
  } else {
2676
  vb_l <- sec_ref$velo_l %||% NA_real_
@@ -2954,7 +2954,7 @@ create_advanced_pitcher_pdf <- function(game_df, pitcher_name, output_file) {
2954
  if (length(dev.list()) > 0) try(dev.off(), silent = TRUE)
2955
 
2956
  pitch_colors <- c(
2957
- "Fastball" = "#FA8072", "Four-Seam" = "#FA8072", "Sinker" = "#fdae61",
2958
  "Slider" = "#A020F0", "Sweeper" = "magenta", "Curveball" = "#2c7bb6",
2959
  "ChangeUp" = "#90EE90", "Splitter" = "#90EE32", "Cutter" = "red"
2960
  )
@@ -3552,7 +3552,7 @@ output$download_ui <- renderUI({
3552
  },
3553
  content = function(file) {
3554
  df <- data_pitcher(); req(df, input$pitcher_name)
3555
- pitch_colors <- c("Fastball"="#FA8072","Four-Seam"="#FA8072","Sinker"="#fdae61",
3556
  "Slider"="#A020F0","Sweeper"="magenta","Curveball"="#2c7bb6",
3557
  "ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red")
3558
  withProgress(message='Generating Pitcher PDF', value=0, {
 
20
  }
21
 
22
  team_meta <- tryCatch({
23
+ read.csv("TMB (1).csv", stringsAsFactors = FALSE)
24
  }, error = function(e) {
25
+ message("TMB (1).csv not found - logos will not display")
26
  NULL
27
  })
28
 
 
619
  ggplot2::scale_y_continuous(NULL, limits = c(y_min_needed, 60/12)) +
620
  ggplot2::coord_fixed(ratio = 1.3, clip = "off") +
621
  ggplot2::scale_fill_manual(values = c(
622
+ "Fastball" = "#FA8072", "FourSeamFastBall" = "#FA8072","Four-Seam" = "#FA8072", "Sinker" = "#fdae61",
623
  "Slider" = "#A020F0", "Sweeper" = "magenta", "Curveball" = "#2c7bb6",
624
  "ChangeUp" = "#90EE90", "Splitter" = "#90EE32", "Cutter" = "red"
625
  ), name = "Pitch Type") +
 
1116
  strikes_added <- df %>% filter(frame == "Strike Added")
1117
  strikes_lost <- df %>% filter(frame == "Strike Lost")
1118
  pitch_colors <- c(
1119
+ "Fastball"="#FA8072", "FourSeamFastBall" = "#FA8072","Four-Seam"="#FA8072","Sinker"="#fdae61","Slider"="#A020F0",
1120
  "Sweeper"="magenta","Curveball"="#2c7bb6","ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red"
1121
  )
1122
 
 
2354
  )
2355
 
2356
  sec_extension_benchmark <- function(pt) {
2357
+ if (pt %in% c("Fastball","Four-Seam","Four Seam","Fourseam","FourSeamFastBall","Sinker","Two-Seam","2-Seam")) return(5.83)
2358
  if (pt %in% c("Slider","Sweeper")) return(5.54)
2359
  if (pt %in% c("Curveball","Knuckle Curve")) return(5.47)
2360
  if (pt %in% c("ChangeUp","Splitter")) return(5.98)
 
2656
  for (i in seq_len(num_rows)) {
2657
  pt <- pitch_stats$Pitch[i]
2658
 
2659
+ sec_ref <- if (pt %in% c("Fastball","Four-Seam", "FourSeamFastBall","Sinker","Two-Seam","2-Seam")) {
2660
  sec_averages$fb_sinker
2661
  } else if (pt %in% c("Cutter")) {
2662
  sec_averages$cutter
 
2670
 
2671
  if (!is.null(sec_ref)) {
2672
  velo_bench <- NA_real_
2673
+ if (tolower(pt) %in% c("fastball","four-seam","FourSeamFastBall","four seam","fourseam","sinker","two-seam","2-seam")) {
2674
  velo_bench <- if (identical(pitcher_hand, "Left")) sec_averages$overall$fb_velo_l else sec_averages$overall$fb_velo_r
2675
  } else {
2676
  vb_l <- sec_ref$velo_l %||% NA_real_
 
2954
  if (length(dev.list()) > 0) try(dev.off(), silent = TRUE)
2955
 
2956
  pitch_colors <- c(
2957
+ "Fastball" = "#FA8072", "FourSeamFastBall" = "#FA8072", "Four-Seam" = "#FA8072", "Sinker" = "#fdae61",
2958
  "Slider" = "#A020F0", "Sweeper" = "magenta", "Curveball" = "#2c7bb6",
2959
  "ChangeUp" = "#90EE90", "Splitter" = "#90EE32", "Cutter" = "red"
2960
  )
 
3552
  },
3553
  content = function(file) {
3554
  df <- data_pitcher(); req(df, input$pitcher_name)
3555
+ pitch_colors <- c("Fastball"="#FA8072","FourSeamFastBall"="#FA8072", "Four-Seam"="#FA8072","Sinker"="#fdae61",
3556
  "Slider"="#A020F0","Sweeper"="magenta","Curveball"="#2c7bb6",
3557
  "ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red")
3558
  withProgress(message='Generating Pitcher PDF', value=0, {