-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (113 loc) · 4.62 KB
/
compute-baseline.yml
File metadata and controls
130 lines (113 loc) · 4.62 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
# ============================================================================
# Compute Baseline Parameters
# ============================================================================
# One-time (or annual) workflow that runs compute_baseline.R to produce
# baseline_params.rds — the fixed μ/σ used to scale Deception+ to 100±10.
#
# Without this file the daily workflow falls back to mu=1.0, sd=0.1 which
# may not reflect actual unpredictability distributions in the data.
#
# Run manually via: Actions → Compute Baseline Parameters → Run workflow
# Recompute annually (e.g. after each full season) to keep the scale current.
# ============================================================================
name: Compute Baseline Parameters
on:
workflow_dispatch:
inputs:
force_recompute:
description: 'Recompute even if baseline_params.rds already exists'
required: false
default: 'false'
type: boolean
jobs:
compute:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if baseline already exists
id: check
run: |
if [ -f "baseline_params.rds" ] && [ "${{ github.event.inputs.force_recompute }}" != "true" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "baseline_params.rds already exists. Use force_recompute=true to regenerate."
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Setup R
if: steps.check.outputs.skip == 'false'
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.3.0'
use-public-rspm: true
- name: Install system dependencies
if: steps.check.outputs.skip == 'false'
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev
- name: Cache R packages
if: steps.check.outputs.skip == 'false'
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ hashFiles('**/DESCRIPTION') }}
restore-keys: |
${{ runner.os }}-r-
- name: Install R packages
if: steps.check.outputs.skip == 'false'
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: |
install.packages(c(
"dplyr", "tidyr", "purrr", "stringr", "lubridate",
"nnet", "readr", "tibble", "forcats",
"httr", "jsonlite", "ggplot2", "scales"
), repos = "https://cloud.r-project.org")
install.packages("remotes")
remotes::install_github("saberpowers/sabRmetrics", quiet = TRUE)
shell: Rscript {0}
- name: Restore Statcast cache
if: steps.check.outputs.skip == 'false'
uses: actions/cache@v4
with:
path: cache/
# Try to reuse data cached by the daily workflow first
key: statcast-baseline-${{ github.run_number }}
restore-keys: |
statcast-baseline-
statcast-cache-
- name: Compute baseline parameters
if: steps.check.outputs.skip == 'false'
run: |
Rscript compute_baseline.R
- name: Commit baseline_params.rds
if: steps.check.outputs.skip == 'false'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add baseline_params.rds || true
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "feat: compute baseline parameters for Deception+ standardization
- Computed mu/sigma from 2023-2025 historical data (30 random splits)
- Enables proper Deception+ = 100 +/- 10 scaling in daily analysis
- Recompute annually with: Actions > Compute Baseline Parameters"
git push
fi
- name: Summary
if: always()
run: |
echo "## Baseline Computation" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check.outputs.skip }}" == "true" ]; then
echo "**Skipped** — baseline_params.rds already exists." >> $GITHUB_STEP_SUMMARY
echo "Use \`force_recompute=true\` to regenerate." >> $GITHUB_STEP_SUMMARY
elif [ -f "baseline_params.rds" ]; then
echo "**Success** — baseline_params.rds computed and committed." >> $GITHUB_STEP_SUMMARY
else
echo "**Failed** — baseline_params.rds was not produced." >> $GITHUB_STEP_SUMMARY
fi