igroffman commited on
Commit
f102e5f
·
verified ·
1 Parent(s): ffd013c

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +17 -2
app.R CHANGED
@@ -2239,14 +2239,28 @@ create_advanced_pitch_characteristics <- function(data, player_name) {
2239
  )
2240
 
2241
  preflight_predictor_check(stuffplus_model, pitcher_data)
2242
- raw_predictions <- safe_predict_stuff(stuffplus_model, pitcher_data)
2243
- pitcher_data$raw_stuff <- raw_predictions
 
 
 
 
 
 
2244
 
2245
  pitcher_data <- standardize_stuffplus_to_league(pitcher_data, combined)
2246
 
2247
  } else {
2248
 
2249
  message("WARNING: No reference data available. Using local standardization.")
 
 
 
 
 
 
 
 
2250
 
2251
  finite_raw <- pitcher_data$raw_stuff[is.finite(pitcher_data$raw_stuff)]
2252
  if (length(finite_raw) == 0) {
@@ -2298,6 +2312,7 @@ create_advanced_pitch_characteristics <- function(data, player_name) {
2298
  ) %>%
2299
  dplyr::arrange(dplyr::desc(`Usage%`))
2300
 
 
2301
  dup_mask <- duplicated(names(pitch_stats))
2302
  if (any(dup_mask)) {
2303
  message("Removing ", sum(dup_mask), " duplicate columns from pitch_stats")
 
2239
  )
2240
 
2241
  preflight_predictor_check(stuffplus_model, pitcher_data)
2242
+
2243
+ # Direct prediction - no safe_predict_stuff wrapper
2244
+ pitcher_data$raw_stuff <- tryCatch({
2245
+ predict(stuffplus_model, pitcher_data, type = "numeric")$.pred
2246
+ }, error = function(e) {
2247
+ message("Stuff+ prediction error: ", e$message)
2248
+ rep(NA_real_, nrow(pitcher_data))
2249
+ })
2250
 
2251
  pitcher_data <- standardize_stuffplus_to_league(pitcher_data, combined)
2252
 
2253
  } else {
2254
 
2255
  message("WARNING: No reference data available. Using local standardization.")
2256
+
2257
+ # Direct prediction for local standardization path
2258
+ pitcher_data$raw_stuff <- tryCatch({
2259
+ predict(stuffplus_model, pitcher_data, type = "numeric")$.pred
2260
+ }, error = function(e) {
2261
+ message("Stuff+ prediction error: ", e$message)
2262
+ rep(NA_real_, nrow(pitcher_data))
2263
+ })
2264
 
2265
  finite_raw <- pitcher_data$raw_stuff[is.finite(pitcher_data$raw_stuff)]
2266
  if (length(finite_raw) == 0) {
 
2312
  ) %>%
2313
  dplyr::arrange(dplyr::desc(`Usage%`))
2314
 
2315
+ # Rest of function remains the same...
2316
  dup_mask <- duplicated(names(pitch_stats))
2317
  if (any(dup_mask)) {
2318
  message("Removing ", sum(dup_mask), " duplicate columns from pitch_stats")