mlb

package
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RockiesID  = 115
	NLLeagueID = 104
)

Variables

This section is empty.

Functions

func DenverLocation

func DenverLocation() *time.Location

DenverLocation returns the America/Denver timezone.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements GameProvider using the MLB Stats API.

func NewClient

func NewClient(httpClient *http.Client, logger *log.Logger) *Client

func (*Client) GetGameLiveStatus added in v0.6.3

func (c *Client) GetGameLiveStatus(date string) ([]GameLiveStatus, error)

func (*Client) GetGamesSince

func (c *Client) GetGamesSince(date string) ([]GameResult, error)

func (*Client) GetHeadToHead

func (c *Client) GetHeadToHead(opponentID int) (*H2HRecord, error)

func (*Client) GetPitcherStats

func (c *Client) GetPitcherStats(playerID int) (*PitcherStats, error)

func (*Client) GetSeasonResults added in v0.6.1

func (c *Client) GetSeasonResults() ([]GameResult, error)

GetSeasonResults returns every completed regular-season Rockies game for the current season.

func (*Client) GetTeamRecord

func (c *Client) GetTeamRecord() (*TeamRecord, error)

func (*Client) GetTodayGame

func (c *Client) GetTodayGame() (*Game, error)

func (*Client) GetTodayGames

func (c *Client) GetTodayGames() ([]*Game, error)

type Game

type Game struct {
	GamePk             int
	GameDateTime       time.Time
	OfficialDate       string // MLB's canonical game date "2006-01-02"; authoritative over the wall clock
	Status             string // "Preview", "Live", "Final" (abstractGameState)
	DetailedState      string // "Scheduled", "Postponed", "Cancelled", etc.
	Reason             string // reason for postponement/cancellation
	RescheduleGameDate string // official date a postponed game was moved to, if any
	HomeTeam           TeamInfo
	AwayTeam           TeamInfo
	Venue              string
	IsHome             bool   // true if Rockies are the home team
	GameNumber         int    // 1 or 2 for double-headers
	DoubleHeader       string // "Y" (straight), "S" (split), "N" (not)
}

Game represents a single Rockies game.

func (*Game) FormatGameTime

func (g *Game) FormatGameTime() string

func (*Game) GameTimeMST

func (g *Game) GameTimeMST() time.Time

func (*Game) HasProbablePitchers

func (g *Game) HasProbablePitchers() bool

func (*Game) IsPlayable

func (g *Game) IsPlayable() bool

func (*Game) IsUpcoming

func (g *Game) IsUpcoming(now ...time.Time) bool

func (*Game) Opponent

func (g *Game) Opponent() TeamInfo

func (*Game) OpponentID

func (g *Game) OpponentID() int

func (*Game) OpponentPitcher

func (g *Game) OpponentPitcher() *PitcherInfo

func (*Game) RockiesPitcher

func (g *Game) RockiesPitcher() *PitcherInfo

func (*Game) RockiesTeam

func (g *Game) RockiesTeam() TeamInfo

type GameLiveStatus added in v0.6.3

type GameLiveStatus struct {
	GamePk        int
	Status        string // "Preview", "Live", "Final"
	CurrentInning int
	InningState   string // "Top", "Middle", "Bottom", "End"
}

GameLiveStatus represents the live state of a game including inning info.

type GameProvider

type GameProvider interface {
	GetTodayGame() (*Game, error)
	GetTodayGames() ([]*Game, error)
	GetTeamRecord() (*TeamRecord, error)
	GetPitcherStats(playerID int) (*PitcherStats, error)
	GetHeadToHead(opponentID int) (*H2HRecord, error)
	GetGamesSince(date string) ([]GameResult, error)
	GetGameLiveStatus(date string) ([]GameLiveStatus, error)
}

GameProvider is the interface for fetching MLB data. All business logic depends on this interface, making it trivially mockable in tests.

type GameResult

type GameResult struct {
	GamePk       int       `json:"gamePk"`
	Date         string    `json:"date"`         // MLB official date "2006-01-02"
	GameDateTime time.Time `json:"gameDateTime"` // first-pitch time (UTC)
	OpponentID   int       `json:"opponentId"`
	Opponent     string    `json:"opponent"`
	IsHome       bool      `json:"isHome"`
	RockiesScore int       `json:"rockiesScore"`
	OppScore     int       `json:"oppScore"`
	Won          bool      `json:"won"`
	Status       string    `json:"status"`
	GameNumber   int       `json:"gameNumber,omitempty"`
}

type H2HRecord

type H2HRecord struct {
	OpponentID   int
	OpponentName string
	Wins         int
	Losses       int
	GamesPlayed  int
}

H2HRecord represents head-to-head record vs a specific opponent this season.

type PitcherInfo

type PitcherInfo struct {
	ID       int
	FullName string
}

type PitcherStats

type PitcherStats struct {
	PlayerID       int
	FullName       string
	ERA            float64
	WHIP           float64
	Wins           int
	Losses         int
	StrikeOuts     int
	InningsPitched float64
	GamesStarted   int
}

PitcherStats represents season pitching stats for a single pitcher.

type TeamInfo

type TeamInfo struct {
	ID              int
	Name            string
	Wins            int
	Losses          int
	WinPct          string
	ProbablePitcher *PitcherInfo
}

func (TeamInfo) WinLossString

func (t TeamInfo) WinLossString() string

type TeamRecord

type TeamRecord struct {
	Wins              int
	Losses            int
	WinningPercentage float64
	RunsScored        int
	RunsAllowed       int
	RunDifferential   int
	StreakCode        string // e.g. "W3", "L2"
	HomeWins          int
	HomeLosses        int
	AwayWins          int
	AwayLosses        int
	Last10Wins        int
	Last10Losses      int
}

TeamRecord represents current season standings for the Rockies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL