Skip to content

Salary data: Spotrac 2017-2021, team ID normalisation, full 1985-2025 coverage#1

Merged
luceydav merged 5 commits into
mainfrom
dev
Mar 28, 2026
Merged

Salary data: Spotrac 2017-2021, team ID normalisation, full 1985-2025 coverage#1
luceydav merged 5 commits into
mainfrom
dev

Conversation

@luceydav

Copy link
Copy Markdown
Owner

Spotrac scraper, MLB minimum filter, team ID normalisation (Spotrac + USA Today to Lahman codes), and SalariesAll covering 1985-2025. Four new tests added; 72 total passing.

David Lucey and others added 5 commits March 28, 2026 12:04
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Passes through to connections::connection_open() when the connections
package is installed, making the DuckDB connection visible in RStudio's
Connections pane. Gracefully falls back to DBI::dbConnect() otherwise.
connections added to Suggests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Rewrite data-raw/salaries.R to use Spotrac AJAX POST endpoint
  (POST /mlb/rankings/player/_/year/{year}/sort/cash_total with ajax=table)
  Old CSS selectors (.player-name, .rank-position) were obsolete post-2023 redesign
- Parse new div-based table structure: div.link a (name), small (team/pos),
  span.medium (salary); yields 1440-1590 players per year with no pagination
- add spotrac_file param to setup_baseball_db(); auto-detects
  salaries_spotrac_*_with_playerID.csv in same dir as dbdir
- Load SalariesSpotrac table; add third UNION ALL branch in SalariesAll view
- SalariesAll now covers: Lahman 1985-2016, Spotrac 2017-2021, USA Today 2022+
  with no missing years

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Spotrac includes 40-man roster minor leaguers (~500-800/year) at
sub-minimum salaries (0K-00K). These are excluded from SalariesAll
via a per-year CASE filter to match Lahman's scope (MLB contracts only).

MLB minimums used: 2017=$535K, 2018=$545K, 2019=$555K,
2020=$208K (prorated 60-game season), 2021=$570.5K.

Result: Spotrac player counts (768-1028/yr) are now consistent
with Lahman (802-853) and USA Today (765-938).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add CASE mappings in setup_db.R for Spotrac (CHC→CHN, CHW→CHA, KC→KCA,
  LAD→LAN, NYM→NYN, NYY→NYA, SD→SDN, SF→SFN, STL→SLN, TB→TBA, WSH→WAS)
- Add full team-name→code CASE for USA Today (all 30 franchise name variants)
- All SalariesAll teamIDs now join cleanly to the Lahman Teams table

Tests added (test-setup.R):
- Spotrac team code normalisation (11 remapped codes verified)
- Spotrac MLB-minimum salary filter
- USA Today team name normalisation (10 name variants verified)
- SalariesAll teamIDs have zero unmatched rows against Teams

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@luceydav luceydav merged commit 96fd162 into main Mar 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant