-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_daily.R
More file actions
596 lines (503 loc) · 22.2 KB
/
run_daily.R
File metadata and controls
596 lines (503 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# ============================================================================
# run_daily.R — Daily Deception+ Analysis Using Per-Pitcher Models
# ----------------------------------------------------------------------------
# Runs daily Deception+ analysis for the previous day's MLB games using
# per-pitcher models (each pitcher evaluated against their own patterns).
#
# Approach:
# 1. Load historical data to get each pitcher's last N pitches
# 2. Load today's test data
# 3. For each pitcher: train model on their history, evaluate today's pitches
# 4. Standardize using fixed baseline (from compute_baseline.R)
# 5. Generate social media graphics
#
# Output:
# - CSV: output/{season}/{month}/{day}.csv
# - Social media graphics: output/{season}/{month}/visualizations/
# ============================================================================
source("pitch_ppi.R")
# ============================================================================
# CONFIGURATION
# ============================================================================
# Get the date to analyze (default: yesterday)
args <- commandArgs(trailingOnly = TRUE)
if (length(args) > 0 && !grepl("^--", args[1])) {
TARGET_DATE <- as.Date(args[1])
} else {
TARGET_DATE <- Sys.Date() - 1
}
# Parse optional arguments
get_arg <- function(flag, default = NULL) {
hit <- which(args == flag)
if (length(hit) == 1 && hit < length(args)) args[hit + 1] else default
}
# Level selection (MLB or AAA)
LEVEL <- get_arg("--level", "MLB")
# Number of historical pitches per pitcher for training
N_HISTORY_PITCHES <- as.integer(get_arg("--n_history", "500"))
# Minimum historical pitches required to evaluate a pitcher
MIN_HISTORY_PITCHES <- as.integer(get_arg("--min_history", "100"))
# Minimum test pitches for social media graphics (role-specific thresholds)
MIN_PITCHES_STARTER_SOCIAL <- 50
MIN_PITCHES_RELIEVER_SOCIAL <- 10
# Baseline parameters file (generated by compute_baseline.R)
BASELINE_FILE <- get_arg("--baseline", "baseline_params.rds")
# Features for per-pitcher models (simpler set for individual models)
FEATURE_NAMES <- c(
"balls", "strikes", "two_strikes", "ahead_in_count",
"outs", "is_risp", "stand", "last_pitch_type"
)
# ============================================================================
# DATE CALCULATIONS
# ============================================================================
target_year <- as.integer(format(TARGET_DATE, "%Y"))
target_month <- as.integer(format(TARGET_DATE, "%m"))
target_day <- format(TARGET_DATE, "%d")
target_month_name <- tolower(format(TARGET_DATE, "%B"))
# ============================================================================
# OUTPUT PATHS
# ============================================================================
output_base <- file.path("output", target_year, target_month_name)
viz_output <- file.path(output_base, "visualizations")
if (!dir.exists(output_base)) {
dir.create(output_base, recursive = TRUE)
message("Created output directory: ", output_base)
}
if (!dir.exists(viz_output)) {
dir.create(viz_output, recursive = TRUE)
}
OUT_CSV <- file.path(output_base, paste0(target_day, ".csv"))
OUT_MODEL <- file.path("models", sprintf("daily_%s_%s.rds", LEVEL, TARGET_DATE))
# ============================================================================
# EXECUTION
# ============================================================================
cat("\n")
cat("============================================================\n")
cat(" Deception+ Daily Analysis (Per-Pitcher Models)\n")
cat("============================================================\n")
cat("Target Date: ", as.character(TARGET_DATE), "\n")
cat("Level: ", LEVEL, "\n")
cat("History Pitches: ", N_HISTORY_PITCHES, " per pitcher\n")
cat("Min History: ", MIN_HISTORY_PITCHES, "\n")
cat("Baseline File: ", BASELINE_FILE, "\n")
cat("Output CSV: ", OUT_CSV, "\n")
cat("============================================================\n\n")
ensure_directories()
# ============================================================================
# LOAD BASELINE PARAMETERS
# ============================================================================
if (!file.exists(BASELINE_FILE)) {
warning("Baseline file not found: ", BASELINE_FILE)
warning("Using fallback values. Run compute_baseline.R for stable baseline.")
baseline_params <- list(mu = 1.0, sd = 0.1) # Fallback
} else {
message("Loading baseline parameters from: ", BASELINE_FILE)
baseline_params <- load_baseline_params(BASELINE_FILE)
message(" Baseline μ = ", round(baseline_params$mu, 4),
", σ = ", round(baseline_params$sd, 4))
message(" Computed from: ", baseline_params$data_period)
}
# ============================================================================
# LOAD TEST DATA (Today's Games)
# ============================================================================
message("\nLoading test data for ", TARGET_DATE, "...")
TRAIN_LEVEL <- LEVEL
TEST_LEVEL <- LEVEL
test_cachefile <- sprintf("cache/savant_raw_%s_%s_R_%s.Rds",
TARGET_DATE, TARGET_DATE, LEVEL)
if (file.exists(test_cachefile)) {
message("Using cached test data: ", test_cachefile)
raw_test <- readRDS(test_cachefile)
} else {
message("Downloading test data...")
raw_test <- load_statcast_range(as.character(TARGET_DATE),
as.character(TARGET_DATE),
game_type = "R", level = LEVEL, verbose = TRUE)
if (!is.null(raw_test) && nrow(raw_test) > 0) {
saveRDS(raw_test, test_cachefile)
message("Cached to: ", test_cachefile)
}
}
if (is.null(raw_test) || nrow(raw_test) == 0) {
message("No games found for ", TARGET_DATE, ". This may be an off-day.")
quit(save = "no", status = 0)
}
message("Test data: ", nrow(raw_test), " pitches")
df_test <- engineer_features(raw_test, include_batter_metrics = FALSE)
df_test <- df_test %>% dplyr::filter(!is.na(pitcher_id))
message("Test features: ", nrow(df_test), " pitches from ",
length(unique(df_test$pitcher_id)), " pitchers")
# Get unique pitchers from today's games
today_pitcher_ids <- unique(df_test$pitcher_id)
message("Pitchers to evaluate: ", length(today_pitcher_ids))
# ============================================================================
# LOAD HISTORICAL DATA
# ============================================================================
message("\nLoading historical data for pitcher histories...")
# We need to load enough historical data to get last N_HISTORY_PITCHES per pitcher
# Load data from the past ~2 years to ensure coverage
history_start <- as.Date(TARGET_DATE) - 730 # ~2 years back
history_end <- as.Date(TARGET_DATE) - 1 # Through yesterday
# Try to load cached historical data, or download
# For efficiency, we cache by year
historical_data <- NULL
current_year <- lubridate::year(history_end)
for (year in seq(lubridate::year(history_start), current_year)) {
year_start <- max(as.Date(sprintf("%d-03-01", year)), history_start)
year_end <- min(as.Date(sprintf("%d-11-30", year)), history_end)
if (year_end < year_start) next
if (year == current_year) {
# Current (incomplete) season: use a stable filename and update incrementally.
# The date-range filename changes every day, so instead we cache by year and
# download only the delta since the last cached date.
year_cachefile <- sprintf("cache/savant_partial_%d_R_%s.Rds", year, LEVEL)
if (file.exists(year_cachefile)) {
message(" Loading cached partial ", year, " data...")
year_data <- readRDS(year_cachefile)
# Determine how stale the cache is and fetch only new pitches
cached_max_date <- tryCatch(
as.Date(max(as.character(year_data$game_date), na.rm = TRUE)),
error = function(e) as.Date(NA)
)
if (!is.na(cached_max_date) && cached_max_date < year_end) {
delta_start <- cached_max_date + 1
message(" Fetching new data: ", delta_start, " to ", year_end, "...")
new_data <- load_statcast_range(
as.character(delta_start), as.character(year_end),
game_type = "R", level = LEVEL, verbose = FALSE
)
if (!is.null(new_data) && nrow(new_data) > 0) {
year_data <- dplyr::bind_rows(year_data, new_data)
saveRDS(year_data, year_cachefile)
message(" Cache updated: added ", nrow(new_data), " pitches through ", year_end)
} else {
message(" No new pitches found since ", cached_max_date)
}
} else {
message(" Cache is current through ", year_end)
}
} else {
message(" Downloading partial ", year, " data (", year_start, " to ", year_end, ")...")
year_data <- load_statcast_range(
as.character(year_start), as.character(year_end),
game_type = "R", level = LEVEL, verbose = FALSE
)
if (!is.null(year_data) && nrow(year_data) > 0) {
saveRDS(year_data, year_cachefile)
message(" Cached to: ", year_cachefile)
}
}
} else {
# Complete past season: filename is stable (end date never changes once season ends)
year_cachefile <- sprintf("cache/savant_raw_%s_%s_R_%s.Rds",
year_start, year_end, LEVEL)
if (file.exists(year_cachefile)) {
message(" Loading cached ", year, " data...")
year_data <- readRDS(year_cachefile)
} else {
message(" Downloading ", year, " data...")
year_data <- load_statcast_range(as.character(year_start),
as.character(year_end),
game_type = "R", level = LEVEL, verbose = FALSE)
if (!is.null(year_data) && nrow(year_data) > 0) {
saveRDS(year_data, year_cachefile)
}
}
}
if (!is.null(year_data) && nrow(year_data) > 0) {
if (is.null(historical_data)) {
historical_data <- year_data
} else {
historical_data <- dplyr::bind_rows(historical_data, year_data)
}
}
}
if (is.null(historical_data) || nrow(historical_data) == 0) {
stop("No historical data available")
}
message("Total historical data: ", nrow(historical_data), " pitches")
# Pre-filter historical data to only pitchers who appeared today before
# running expensive feature engineering on the full dataset
message("\nPre-filtering historical data to today's pitchers...")
pitcher_id_col <- coalesce_pitcher_id(historical_data)
historical_data <- historical_data[!is.na(pitcher_id_col) & pitcher_id_col %in% today_pitcher_ids, ]
message(" Filtered to ", nrow(historical_data), " pitches for today's pitchers")
# Engineer features on filtered historical data
df_history_all <- engineer_features(historical_data, include_batter_metrics = FALSE)
df_history_all <- df_history_all %>% dplyr::filter(!is.na(pitcher_id))
# Get last N_HISTORY_PITCHES for each pitcher who appeared today
message("\nExtracting last ", N_HISTORY_PITCHES, " pitches per pitcher...")
df_history <- get_pitcher_history(df_history_all, today_pitcher_ids, N_HISTORY_PITCHES)
message(" History data: ", nrow(df_history), " pitches from ",
length(unique(df_history$pitcher_id)), " pitchers")
# ============================================================================
# EVALUATE PER-PITCHER UNPREDICTABILITY
# ============================================================================
message("\nEvaluating per-pitcher unpredictability...")
# Use the same baseline keys that were used to compute baseline_params (mu/sigma)
BASELINE_KEYS <- baseline_params$baseline_keys %||% c("balls", "strikes", "stand", "two_strikes")
eval_result <- evaluate_per_pitcher(
df_history = df_history,
df_test = df_test,
min_train_pitches = MIN_HISTORY_PITCHES,
min_test_pitches = 1, # Include all pitchers with any test pitches
feature_names = FEATURE_NAMES,
baseline_keys = BASELINE_KEYS,
verbose = TRUE
)
# Extract results and excluded pitchers
per_pitcher_results <- eval_result$results
excluded_pitchers <- eval_result$excluded
if (nrow(per_pitcher_results) == 0) {
message("No pitchers with sufficient data to evaluate.")
quit(save = "no", status = 0)
}
# ============================================================================
# STANDARDIZE TO PREDICT+
# ============================================================================
message("\nStandardizing to Deception+ scale...")
# Calculate Deception+ using fixed baseline parameters
per_pitcher_results <- per_pitcher_results %>%
dplyr::mutate(
ppi = 1 - (mean_surp_model / pmax(mean_surp_base, 1e-9)),
ppi = pmin(pmax(ppi, -1), 1),
deception_plus = 100 + 10 * ((unpredictability_ratio - baseline_params$mu) /
pmax(baseline_params$sd, 1e-9))
)
# Identify starter/reliever roles from test data
message("Identifying starter/reliever roles...")
pitcher_roles <- get_daily_pitcher_roles(df_test)
n_starters <- sum(pitcher_roles$role == "starter")
n_relievers <- sum(pitcher_roles$role == "reliever")
message(" ", n_starters, " starters, ", n_relievers, " relievers")
# Resolve pitcher names (for both evaluated and excluded pitchers)
message("Resolving pitcher names...")
all_pitcher_ids <- dplyr::bind_rows(
per_pitcher_results %>% dplyr::select(pitcher_id),
excluded_pitchers %>% dplyr::select(pitcher_id)
) %>% dplyr::distinct()
name_map <- resolve_pitcher_names_with_fallback(all_pitcher_ids,
cache_file = "cache/mlbam_name_cache.csv",
verbose = TRUE)
# Create evaluated pitchers output
evaluated_ppi <- per_pitcher_results %>%
dplyr::left_join(name_map, by = "pitcher_id") %>%
dplyr::left_join(pitcher_roles, by = "pitcher_id") %>%
dplyr::mutate(
pitcher_name = dplyr::if_else(is.na(pitcher_name),
paste0("Pitcher_", pitcher_id),
pitcher_name),
total_pitches = n_history,
n_pitches_test = n_test,
status = "evaluated",
role = dplyr::coalesce(role, "unknown")
) %>%
dplyr::select(
pitcher_id, pitcher_name, role, total_pitches, n_pitches_test,
mean_surp_model, mean_surp_base, ppi,
unpredictability_ratio, deception_plus, status
) %>%
dplyr::arrange(dplyr::desc(deception_plus))
# Create excluded pitchers output (debuts, insufficient history)
excluded_ppi <- excluded_pitchers %>%
dplyr::left_join(name_map, by = "pitcher_id") %>%
dplyr::left_join(pitcher_roles, by = "pitcher_id") %>%
dplyr::mutate(
pitcher_name = dplyr::if_else(is.na(pitcher_name),
paste0("Pitcher_", pitcher_id),
pitcher_name),
total_pitches = n_history,
n_pitches_test = n_test,
mean_surp_model = NA_real_,
mean_surp_base = NA_real_,
ppi = NA_real_,
unpredictability_ratio = NA_real_,
deception_plus = NA_real_,
role = dplyr::coalesce(role, "unknown")
) %>%
dplyr::select(
pitcher_id, pitcher_name, role, total_pitches, n_pitches_test,
mean_surp_model, mean_surp_base, ppi,
unpredictability_ratio, deception_plus, status
)
# Combine evaluated and excluded pitchers
pitcher_ppi <- dplyr::bind_rows(evaluated_ppi, excluded_ppi) %>%
dplyr::arrange(dplyr::desc(deception_plus), status)
# ============================================================================
# SAVE RESULTS
# ============================================================================
message("\nSaving results...")
readr::write_csv(pitcher_ppi, OUT_CSV)
message("CSV saved: ", OUT_CSV)
# Create result object for visualization functions
res <- list(
pitcher_ppi = pitcher_ppi,
baseline_params = baseline_params,
split_method = "per_pitcher",
test_period = as.character(TARGET_DATE),
n_history_pitches = N_HISTORY_PITCHES
)
# Count evaluated vs excluded
n_evaluated <- sum(pitcher_ppi$status == "evaluated")
n_debuts <- sum(pitcher_ppi$status == "debut_no_history")
n_insufficient <- sum(pitcher_ppi$status == "insufficient_history")
# Save model metadata
saveRDS(list(
baseline_params = baseline_params,
split_method = "per_pitcher",
test_date = as.character(TARGET_DATE),
level = LEVEL,
n_history_pitches = N_HISTORY_PITCHES,
min_history_pitches = MIN_HISTORY_PITCHES,
feature_names = FEATURE_NAMES,
n_pitchers_evaluated = n_evaluated,
n_pitchers_debut = n_debuts,
n_pitchers_insufficient = n_insufficient
), OUT_MODEL)
message("Model metadata saved: ", OUT_MODEL)
# ============================================================================
# SOCIAL MEDIA GRAPHICS
# ============================================================================
message("\nGenerating social media graphics...")
create_social_media_graphics(
res = res,
game_date = as.character(TARGET_DATE),
min_pitches_starter = MIN_PITCHES_STARTER_SOCIAL,
min_pitches_reliever = MIN_PITCHES_RELIEVER_SOCIAL,
output_dir = viz_output,
top_n = 5
)
# ============================================================================
# SUMMARY
# ============================================================================
cat("\n")
cat("============================================================\n")
cat(" Daily Analysis Complete!\n")
cat("============================================================\n")
cat("Date: ", as.character(TARGET_DATE), "\n")
cat("Level: ", LEVEL, "\n")
cat("Pitchers Evaluated:", n_evaluated, "\n")
if (n_debuts > 0) {
cat("Debuts (no data): ", n_debuts, "\n")
}
if (n_insufficient > 0) {
cat("Insufficient Hist: ", n_insufficient, " (<", MIN_HISTORY_PITCHES, " pitches)\n", sep = "")
}
cat("Total Test Pitches:", sum(pitcher_ppi$n_pitches_test, na.rm = TRUE), "\n")
cat("Baseline: μ=", round(baseline_params$mu, 4),
" σ=", round(baseline_params$sd, 4), "\n")
cat("\n")
# Show top 5 and bottom 5 using role-specific thresholds (only evaluated pitchers)
# Starters: >= MIN_PITCHES_STARTER_SOCIAL, Relievers: >= MIN_PITCHES_RELIEVER_SOCIAL
qualified_starters <- pitcher_ppi %>%
dplyr::filter(status == "evaluated", role == "starter",
n_pitches_test >= MIN_PITCHES_STARTER_SOCIAL)
qualified_relievers <- pitcher_ppi %>%
dplyr::filter(status == "evaluated", role == "reliever",
n_pitches_test >= MIN_PITCHES_RELIEVER_SOCIAL)
# Helper function to print rankings
print_rankings <- function(data, title_top, title_bottom, n = 5) {
if (nrow(data) == 0) {
cat("No pitchers qualified.\n")
return()
}
cat(title_top, ":\n", sep = "")
top_n <- data %>%
dplyr::arrange(dplyr::desc(deception_plus)) %>%
head(n) %>%
dplyr::mutate(rank = dplyr::row_number()) %>%
dplyr::select(rank, pitcher_name, n_pitches_test, deception_plus)
print(as.data.frame(top_n), row.names = FALSE)
cat("\n", title_bottom, ":\n", sep = "")
bottom_n <- data %>%
dplyr::arrange(deception_plus) %>%
head(n) %>%
dplyr::mutate(rank = dplyr::row_number()) %>%
dplyr::select(rank, pitcher_name, n_pitches_test, deception_plus)
print(as.data.frame(bottom_n), row.names = FALSE)
}
# Starters
cat("--- STARTERS (>= ", MIN_PITCHES_STARTER_SOCIAL, " pitches) ---\n", sep = "")
if (nrow(qualified_starters) > 0) {
print_rankings(
qualified_starters,
paste0("Top 5 Least Predictable Starters"),
paste0("Top 5 Most Predictable Starters")
)
} else {
cat("No starters with >= ", MIN_PITCHES_STARTER_SOCIAL, " pitches today.\n", sep = "")
}
cat("\n")
# Relievers
cat("--- RELIEVERS (>= ", MIN_PITCHES_RELIEVER_SOCIAL, " pitches) ---\n", sep = "")
if (nrow(qualified_relievers) > 0) {
print_rankings(
qualified_relievers,
paste0("Top 5 Least Predictable Relievers"),
paste0("Top 5 Most Predictable Relievers")
)
} else {
cat("No relievers with >= ", MIN_PITCHES_RELIEVER_SOCIAL, " pitches today.\n", sep = "")
}
cat("\n")
cat("============================================================\n")
cat("Output files:\n")
cat(" CSV: ", OUT_CSV, "\n")
cat(" Model: ", OUT_MODEL, "\n")
cat(" Visuals: ", viz_output, "/\n", sep = "")
cat("============================================================\n\n")
# ============================================================================
# BALTIMORE ORIOLES PITCHER SUMMARY
# ============================================================================
if (LEVEL == "MLB") {
orioles_ppi <- NULL
if (all(c("home_team", "away_team", "inning_topbot") %in% names(df_test))) {
# Determine each pitcher's team from test data:
# TOP of inning → home team is pitching; BOT of inning → away team is pitching
pitcher_team_map <- df_test %>%
dplyr::mutate(
pitcher_team = dplyr::if_else(
stringr::str_to_upper(.data$inning_topbot) == "TOP",
as.character(.data$home_team),
as.character(.data$away_team)
)
) %>%
dplyr::filter(!is.na(.data$pitcher_id), !is.na(.data$pitcher_team)) %>%
dplyr::distinct(.data$pitcher_id, .data$pitcher_team) %>%
dplyr::group_by(.data$pitcher_id) %>%
dplyr::slice(1) %>%
dplyr::ungroup()
orioles_pitcher_ids <- pitcher_team_map %>%
dplyr::filter(.data$pitcher_team == "BAL") %>%
dplyr::pull(.data$pitcher_id)
if (length(orioles_pitcher_ids) > 0) {
# Include ALL Orioles pitchers regardless of pitch count
orioles_ppi <- pitcher_ppi %>%
dplyr::filter(.data$pitcher_id %in% orioles_pitcher_ids) %>%
dplyr::arrange(dplyr::desc(.data$deception_plus))
}
}
cat("============================================================\n")
cat(" Baltimore Orioles Pitchers (all pitchers)\n")
cat("============================================================\n")
if (!is.null(orioles_ppi) && nrow(orioles_ppi) > 0) {
# Print markdown-style table to console
orioles_display <- orioles_ppi %>%
dplyr::select(
.data$pitcher_name, .data$role, .data$n_pitches_test,
.data$deception_plus, .data$status
)
print(as.data.frame(orioles_display), row.names = FALSE)
# Generate PNG graphic with orange/black gradient
create_orioles_graphic(
orioles_data = orioles_ppi,
game_date = as.character(TARGET_DATE),
output_dir = viz_output
)
} else if (!all(c("home_team", "away_team") %in% names(df_test))) {
cat("Team data not available in Statcast download.\n")
} else {
cat("No Orioles pitchers found in today's games.\n")
}
cat("============================================================\n\n")
}