DaveM2430 commited on
Commit
5db6dfb
·
verified ·
1 Parent(s): 5b51434

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +23 -9
app.R CHANGED
@@ -159,6 +159,26 @@ build_pitcher_stats <- function(df, min_pitches) {
159
  select(Pitcher, PitcherTeam) %>%
160
  distinct(Pitcher, .keep_all = TRUE)
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  df %>%
163
  mutate(
164
  IsStrike = PitchCall %in% c("StrikeCalled","StrikeSwinging","FoulBall",
@@ -207,15 +227,9 @@ build_pitcher_stats <- function(df, min_pitches) {
207
  na.rm=TRUE),
208
  .groups = "drop"
209
  ) %>%
210
- left_join(team_lookup, by="Pitcher") %>%
211
- left_join(
212
- tryCatch(compute_stuff_plus(df), error=function(e) tibble(Pitcher=character(), `Stuff+`=numeric())),
213
- by="Pitcher"
214
- ) %>%
215
- left_join(
216
- tryCatch(compute_location_plus(df), error=function(e) tibble(Pitcher=character(), `Location+`=numeric())),
217
- by="Pitcher"
218
- ) %>%
219
  filter(Pitches >= min_pitches) %>%
220
  mutate(
221
  Name = sapply(Pitcher, format_name),
 
159
  select(Pitcher, PitcherTeam) %>%
160
  distinct(Pitcher, .keep_all = TRUE)
161
 
162
+ # compute models upfront outside the pipe
163
+ stuff_scores <- tryCatch(
164
+ compute_stuff_plus(df),
165
+ error = function(e) {
166
+ message("Stuff+ failed: ", e$message)
167
+ tibble(Pitcher=character(), `Stuff+`=numeric())
168
+ }
169
+ )
170
+
171
+ loc_scores <- tryCatch(
172
+ compute_location_plus(df),
173
+ error = function(e) {
174
+ message("Location+ failed: ", e$message)
175
+ tibble(Pitcher=character(), `Location+`=numeric())
176
+ }
177
+ )
178
+
179
+ message("Stuff+ rows: ", nrow(stuff_scores))
180
+ message("Location+ rows: ", nrow(loc_scores))
181
+
182
  df %>%
183
  mutate(
184
  IsStrike = PitchCall %in% c("StrikeCalled","StrikeSwinging","FoulBall",
 
227
  na.rm=TRUE),
228
  .groups = "drop"
229
  ) %>%
230
+ left_join(team_lookup, by="Pitcher") %>%
231
+ left_join(stuff_scores, by="Pitcher") %>%
232
+ left_join(loc_scores, by="Pitcher") %>%
 
 
 
 
 
 
233
  filter(Pitches >= min_pitches) %>%
234
  mutate(
235
  Name = sapply(Pitcher, format_name),