Skip to content

Commit 03be075

Browse files
committed
Add Orioles pitcher Predict+ output to daily pipeline
For MLB games, identifies Baltimore Orioles pitchers from yesterday's Statcast data (via home_team/away_team + inning_topbot) and outputs their Predict+ scores for anyone who threw >= 10 pitches. Results are printed to console, saved as orioles_{day}.csv alongside the main CSV, and rendered as a markdown table in the GitHub Actions step summary. https://claude.ai/code/session_01XnaxiNLWNzGJXwyftRiGxr
1 parent 43d0465 commit 03be075

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/daily-analysis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,35 @@ jobs:
249249
echo "### Output Files" >> $GITHUB_STEP_SUMMARY
250250
echo "- CSV: \`${CSV}\`" >> $GITHUB_STEP_SUMMARY
251251
echo "- Visualizations: \`output/${{ steps.check_outputs.outputs.year }}/${{ steps.check_outputs.outputs.month }}/visualizations/\`" >> $GITHUB_STEP_SUMMARY
252+
253+
# Orioles pitcher summary (MLB only)
254+
if [ "${LEVEL}" == "MLB" ]; then
255+
YEAR=${{ steps.check_outputs.outputs.year }}
256+
MONTH=${{ steps.check_outputs.outputs.month }}
257+
DAY=$(date -d "$DATE" '+%d')
258+
ORIOLES_CSV="output/${YEAR}/${MONTH}/orioles_${DAY}.csv"
259+
260+
echo "" >> $GITHUB_STEP_SUMMARY
261+
echo "### Baltimore Orioles Pitcher Predict+ Scores (≥ 10 pitches)" >> $GITHUB_STEP_SUMMARY
262+
echo "" >> $GITHUB_STEP_SUMMARY
263+
264+
if [ -f "$ORIOLES_CSV" ]; then
265+
python3 - "$ORIOLES_CSV" >> $GITHUB_STEP_SUMMARY << 'PYEOF'
266+
import csv, sys
267+
rows = list(csv.DictReader(open(sys.argv[1])))
268+
if rows:
269+
print("| Pitcher | Role | Pitches | Predict+ | Status |")
270+
print("|---------|------|---------|----------|--------|")
271+
for r in rows:
272+
pplus = f"{float(r['predict_plus']):.1f}" if r.get('predict_plus') else "N/A"
273+
print(f"| {r['pitcher_name']} | {r['role']} | {r['n_pitches_test']} | {pplus} | {r['status']} |")
274+
else:
275+
print("No Orioles pitchers threw ≥ 10 pitches.")
276+
PYEOF
277+
else
278+
echo "No Orioles pitchers appeared (or no team data available)." >> $GITHUB_STEP_SUMMARY
279+
fi
280+
fi
252281
else
253282
echo "**Status:** No output generated" >> $GITHUB_STEP_SUMMARY
254283
fi

run_daily.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,63 @@ cat(" CSV: ", OUT_CSV, "\n")
530530
cat(" Model: ", OUT_MODEL, "\n")
531531
cat(" Visuals: ", viz_output, "/\n", sep = "")
532532
cat("============================================================\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("\nOrioles 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

Comments
 (0)