DaveM2430 commited on
Commit
09f00ea
Β·
verified Β·
1 Parent(s): 87c2622

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +25 -13
app.R CHANGED
@@ -55,17 +55,29 @@ build_pitcher_stats <- function(df, min_pitches) {
55
  filter(Pitches >= min_pitches) %>%
56
  mutate(
57
  Name = sapply(Pitcher, format_name),
58
- `Zone%` = round(zone_n / Pitches * 100, 1),
59
- `Strike%` = round(strike_n / Pitches * 100, 1),
60
  `K's` = K,
61
  `BB's` = BB,
62
- `K-BB%` = round((K - BB) / pmax(PA, 1) * 100, 1),
63
- `Whiff%` = round(whiff_n / pmax(swing_n, 1) * 100, 1),
 
 
 
 
 
64
  `Chase%` = round(chase_n / pmax(outzone_n, 1) * 100, 1),
65
- `Hard Hit%` = round(hh_n / pmax(bip_n, 1) * 100, 1)
 
 
 
 
 
 
 
66
  ) %>%
67
  select(Name, Level, Pitches, `Zone%`, `Strike%`, `K's`, `BB's`,
68
- `K-BB%`, `Whiff%`, `Chase%`, `Hard Hit%`) %>%
69
  arrange(desc(Pitches))
70
  }
71
 
@@ -231,13 +243,13 @@ output$pitcher_table <- renderDT({
231
  req(stats_table())
232
  dt <- stats_table()
233
 
234
- # ── Color ranges (edit these when ready) ──────────────────────────────────
235
- # zone_pct_range <- c(42, 53) # bottom, top
236
- # strike_pct_range <- c(58, 67)
237
- # kbb_range <- c(5, 20)
238
- # whiff_range <- c(15, 35)
239
- # chase_range <- c(25, 40)
240
- # hardhit_range <- c(25, 42)
241
  # ──────────────────────────────────────────────────────────────────────────
242
 
243
  datatable(
 
55
  filter(Pitches >= min_pitches) %>%
56
  mutate(
57
  Name = sapply(Pitcher, format_name),
58
+ `Zone%` = round(zone_n / Pitches * 100, 1),
59
+ `Strike%` = round(strike_n / Pitches * 100, 1),
60
  `K's` = K,
61
  `BB's` = BB,
62
+ `K/BB` = case_when(
63
+ K == 0 & BB == 0 ~ NA_real_,
64
+ BB == 0 ~ NA_real_, # undefined β€” infinite
65
+ K == 0 ~ 0,
66
+ TRUE ~ round(K / BB, 2)
67
+ ),
68
+ `Whiff%` = round(whiff_n / pmax(swing_n, 1) * 100, 1),
69
  `Chase%` = round(chase_n / pmax(outzone_n, 1) * 100, 1),
70
+ `Hard Hit%` = round(hh_n / pmax(bip_n, 1) * 100, 1)
71
+ ) %>%
72
+ # filter out blank or incomplete names
73
+ filter(
74
+ !is.na(Name),
75
+ trimws(Name) != "",
76
+ # must have both first and last name (at least one space)
77
+ grepl(" ", trimws(Name))
78
  ) %>%
79
  select(Name, Level, Pitches, `Zone%`, `Strike%`, `K's`, `BB's`,
80
+ `K/BB`, `Whiff%`, `Chase%`, `Hard Hit%`) %>%
81
  arrange(desc(Pitches))
82
  }
83
 
 
243
  req(stats_table())
244
  dt <- stats_table()
245
 
246
+ # ── Color ranges (edit these when ready) ──────────────────────────────────
247
+ # zone_pct_range <- c(42, 53)
248
+ # strike_pct_range <- c(58, 67)
249
+ # kb_range <- c(1.5, 4.0) # K/BB ratio
250
+ # whiff_range <- c(15, 35)
251
+ # chase_range <- c(25, 40)
252
+ # hardhit_range <- c(25, 42)
253
  # ──────────────────────────────────────────────────────────────────────────
254
 
255
  datatable(