Skip to content

MLB API Sabermetrics Ingestion #171

@grovecj

Description

@grovecj

Overview

Integrate with the MLB Stats API sabermetrics endpoint to fetch official WAR, wOBA, wRC+, FIP, and other advanced metrics.

Parent Issue

Part of #94 (WAR and Advanced Stats)

MLB Stats API Endpoint

GET /people/{playerId}/stats?stats=sabermetrics&season={season}&group={hitting|pitching}

Response Fields (Already mapped in SabermetricsResponse.java)

Batting:

  • war, woba, wRaa, wRc, wRcPlus
  • batting, fielding, baseRunning, positional, replacement (WAR components)
  • wSb, ubr, spd

Pitching:

  • war, fip, xfip, fipMinus
  • ra9War, eraMinus
  • pli, gmli (leverage)

Files to Modify

ingestion/client/MlbApiClient.java

Add methods:

public SabermetricsResponse getBattingSabermetrics(Integer playerId, Integer season);
public SabermetricsResponse getPitchingSabermetrics(Integer playerId, Integer season);

ingestion/mapper/StatsMapper.java

Add methods:

public void applySabermetrics(PlayerBattingStats stats, SabermetricData saber);
public void applySabermetrics(PlayerPitchingStats stats, SabermetricData saber);

Files to Create

ingestion/service/SabermetricsIngestionService.java

@Service
public class SabermetricsIngestionService {
    public void syncPlayerSabermetrics(Player player, Integer season);
    public int syncAllPlayerSabermetrics(Integer season);
}

Workflow

  1. After basic stats are synced (StatsIngestionService)
  2. Fetch sabermetrics for each player with stats
  3. Apply official WAR and components to entity
  4. Calculate gWAR using GwarCalculationService
  5. Save updated stats

Test Cases

  • Sabermetrics response parsed correctly
  • WAR, wOBA, wRC+ applied to batting stats
  • FIP, xFIP applied to pitching stats
  • Handles API errors gracefully
  • Integration test with mock fixtures

Acceptance Criteria

  • Official WAR ingested from MLB API
  • wOBA and wRC+ populated
  • FIP family metrics populated for pitchers
  • gWAR calculated after sabermetrics applied
  • Existing StatsMapperTest extended with new methods

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions