@@ -530,3 +530,63 @@ cat(" CSV: ", OUT_CSV, "\n")
530530cat(" Model: " , OUT_MODEL , " \n " )
531531cat(" Visuals: " , viz_output , " /\n " , sep = " " )
532532cat(" ============================================================\n\n " )
533+
534+ # ============================================================================
535+ # BALTIMORE ORIOLES PITCHER SUMMARY
536+ # ============================================================================
537+
538+ if (LEVEL == " MLB" ) {
539+ orioles_ppi <- NULL
540+
541+ if (all(c(" home_team" , " away_team" , " inning_topbot" ) %in% names(df_test ))) {
542+ # Determine each pitcher's team from test data:
543+ # TOP of inning → home team is pitching; BOT of inning → away team is pitching
544+ pitcher_team_map <- df_test %> %
545+ dplyr :: mutate(
546+ pitcher_team = dplyr :: if_else(
547+ stringr :: str_to_upper(.data $ inning_topbot ) == " TOP" ,
548+ as.character(.data $ home_team ),
549+ as.character(.data $ away_team )
550+ )
551+ ) %> %
552+ dplyr :: filter(! is.na(.data $ pitcher_id ), ! is.na(.data $ pitcher_team )) %> %
553+ dplyr :: distinct(.data $ pitcher_id , .data $ pitcher_team ) %> %
554+ dplyr :: group_by(.data $ pitcher_id ) %> %
555+ dplyr :: slice(1 ) %> %
556+ dplyr :: ungroup()
557+
558+ orioles_pitcher_ids <- pitcher_team_map %> %
559+ dplyr :: filter(.data $ pitcher_team == " BAL" ) %> %
560+ dplyr :: pull(.data $ pitcher_id )
561+
562+ if (length(orioles_pitcher_ids ) > 0 ) {
563+ orioles_ppi <- pitcher_ppi %> %
564+ dplyr :: filter(.data $ pitcher_id %in% orioles_pitcher_ids ,
565+ .data $ n_pitches_test > = 10 ) %> %
566+ dplyr :: arrange(dplyr :: desc(.data $ predict_plus ))
567+ }
568+ }
569+
570+ cat(" ============================================================\n " )
571+ cat(" Baltimore Orioles Pitchers (>= 10 pitches)\n " )
572+ cat(" ============================================================\n " )
573+
574+ if (! is.null(orioles_ppi ) && nrow(orioles_ppi ) > 0 ) {
575+ orioles_display <- orioles_ppi %> %
576+ dplyr :: select(
577+ .data $ pitcher_name , .data $ role , .data $ n_pitches_test ,
578+ .data $ predict_plus , .data $ status
579+ )
580+ print(as.data.frame(orioles_display ), row.names = FALSE )
581+
582+ OUT_ORIOLES_CSV <- file.path(output_base , paste0(" orioles_" , target_day , " .csv" ))
583+ readr :: write_csv(orioles_ppi , OUT_ORIOLES_CSV )
584+ cat(" \n Orioles CSV saved: " , OUT_ORIOLES_CSV , " \n " )
585+ } else if (! all(c(" home_team" , " away_team" ) %in% names(df_test ))) {
586+ cat(" Team data not available in Statcast download.\n " )
587+ } else {
588+ cat(" No Orioles pitchers threw >= 10 pitches.\n " )
589+ }
590+
591+ cat(" ============================================================\n\n " )
592+ }
0 commit comments