api

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api provides functions for interacting with the MLB gameday and xmlstats apis

Index

Constants

This section is empty.

Variables

View Source
var Locs = []string{
	"Arizona",
	"Atlanta",
	"Baltimore",
	"Boston",
	"Chicago",
	"Chicago",
	"Cincinnati",
	"Cleveland",
	"Colorado",
	"Detroit",
	"Miami",
	"Houston",
	"Kansas City",
	"Los Angeles",
	"Los Angeles",
	"Milwaukee",
	"Minnesota",
	"New York",
	"New York",
	"Oakland",
	"Philadelphia",
	"Pittsburgh",
	"St. Louis",
	"San Diego",
	"San Francisco",
	"Seattle",
	"Tampa Bay",
	"Texas",
	"Toronto",
	"Washington",
}

Locs is a list of team locations

View Source
var Teams = []string{
	"Diamondbacks",
	"Braves",
	"Red Sox",
	"Cubs",
	"White Sox",
	"Reds",
	"Indians",
	"Rockies",
	"Tigers",
	"Marlins",
	"Astros",
	"Royals",
	"Angels",
	"Dodgers",
	"Brewers",
	"Twins",
	"Mets",
	"Yankees",
	"Athletics",
	"Phillies",
	"Pirates",
	"Cardinals",
	"Padres",
	"Giants",
	"Mariners",
	"Rays",
	"Rangers",
	"Blue Jays",
	"Nationals",
}

Teams is a list of team names

View Source
var TeamsWithLocs = []string{
	"Arizona Diamondbacks",
	"Atlanta Braves",
	"Boston Red Sox",
	"Chicago Cubs",
	"Chicago White Sox",
	"Cincinnati Reds",
	"Cleveland Indians",
	"Colorado Rockies",
	"Detroit Tigers",
	"Miami Marlins",
	"Houston Astros",
	"Kansas City Royals",
	"Los Angeles Angels",
	"Los Angeles Dodgers",
	"Milwaukee Brewers",
	"Minnesota Twins",
	"New York Mets",
	"New York Yankees",
	"Oakland Athletics",
	"Philadelphia Phillies",
	"Pittsburgh Pirates",
	"St. Louis Cardinals",
	"San Diego Padres",
	"San Francisco Giants",
	"Seattle Mariners",
	"Tampa Bay Rays",
	"Texas Rangers",
	"Toronto Blue Jays",
	"Washington Nationals",
}

TeamsWithLocs is a slice of full MLB team names with their location included

Functions

func PrintBoxScoreTable

func PrintBoxScoreTable(sg ScheduleGame, ls *LineScore)

PrintBoxScoreTable prints a box score to Stdout

Types

type AllPositions added in v0.4.1

type AllPositions struct {
	Code         string `json:"code"`
	Name         string `json:"name"`
	Type         string `json:"type"`
	Abbreviation string `json:"abbreviation"`
}

type BoxScore added in v0.4.1

type BoxScore struct {
	Teams         BoxScoreTeams       `json:"teams"`
	Officials     []BoxScoreOfficials `json:"officials"`
	Info          []LabelValue        `json:"info"`
	PitchingNotes []interface{}       `json:"pitchingNotes"`
}

func FetchBoxScore added in v0.4.1

func FetchBoxScore(id string) *BoxScore

FetchBoxScore gets the latest game data from the MLB API and returns a list of games on the day specified by `t`

func (*BoxScore) Print added in v0.4.1

func (bs *BoxScore) Print()

Print prints a boxscore

type BoxScoreBattingStats added in v0.4.1

type BoxScoreBattingStats struct {
	FlyOuts              int    `json:"flyOuts"`
	GroundOuts           int    `json:"groundOuts"`
	Runs                 int    `json:"runs"`
	Doubles              int    `json:"doubles"`
	Triples              int    `json:"triples"`
	HomeRuns             int    `json:"homeRuns"`
	StrikeOuts           int    `json:"strikeOuts"`
	BaseOnBalls          int    `json:"baseOnBalls"`
	IntentionalWalks     int    `json:"intentionalWalks"`
	Hits                 int    `json:"hits"`
	HitByPitch           int    `json:"hitByPitch"`
	Avg                  string `json:"avg"`
	AtBats               int    `json:"atBats"`
	Obp                  string `json:"obp"`
	Slg                  string `json:"slg"`
	Ops                  string `json:"ops"`
	CaughtStealing       int    `json:"caughtStealing"`
	StolenBases          int    `json:"stolenBases"`
	GroundIntoDoublePlay int    `json:"groundIntoDoublePlay"`
	GroundIntoTriplePlay int    `json:"groundIntoTriplePlay"`
	TotalBases           int    `json:"totalBases"`
	Rbi                  int    `json:"rbi"`
	LeftOnBase           int    `json:"leftOnBase"`
	SacBunts             int    `json:"sacBunts"`
	SacFlies             int    `json:"sacFlies"`
	CatchersInterference int    `json:"catchersInterference"`
	Pickoffs             int    `json:"pickoffs"`
}

type BoxScoreDetailedTeam added in v0.4.1

type BoxScoreDetailedTeam struct {
	ID              int            `json:"id"`
	Name            string         `json:"name"`
	Link            string         `json:"link"`
	Season          int            `json:"season"`
	Venue           IDNameLink     `json:"venue"`
	TeamCode        string         `json:"teamCode"`
	FileCode        string         `json:"fileCode"`
	Abbreviation    string         `json:"abbreviation"`
	TeamName        string         `json:"teamName"`
	LocationName    string         `json:"locationName"`
	FirstYearOfPlay string         `json:"firstYearOfPlay"`
	League          IDNameLink     `json:"league"`
	Division        IDNameLink     `json:"division"`
	Sport           IDNameLink     `json:"sport"`
	ShortName       string         `json:"shortName"`
	Record          BoxScoreRecord `json:"record"`
	SpringLeague    SpringLeague   `json:"springLeague"`
	AllStarStatus   string         `json:"allStarStatus"`
	Active          bool           `json:"active"`
}

type BoxScoreOfficials added in v0.4.1

type BoxScoreOfficials struct {
	Official     IDFullNameLink `json:"official"`
	OfficialType string         `json:"officialType"`
}

type BoxScorePitchingStats added in v0.4.1

type BoxScorePitchingStats struct {
	GroundOuts             int    `json:"groundOuts"`
	Runs                   int    `json:"runs"`
	Doubles                int    `json:"doubles"`
	Triples                int    `json:"triples"`
	HomeRuns               int    `json:"homeRuns"`
	StrikeOuts             int    `json:"strikeOuts"`
	BaseOnBalls            int    `json:"baseOnBalls"`
	IntentionalWalks       int    `json:"intentionalWalks"`
	Hits                   int    `json:"hits"`
	AtBats                 int    `json:"atBats"`
	CaughtStealing         int    `json:"caughtStealing"`
	StolenBases            int    `json:"stolenBases"`
	Era                    string `json:"era"`
	InningsPitched         string `json:"inningsPitched"`
	SaveOpportunities      int    `json:"saveOpportunities"`
	EarnedRuns             int    `json:"earnedRuns"`
	Whip                   string `json:"whip"`
	BattersFaced           int    `json:"battersFaced"`
	Outs                   int    `json:"outs"`
	CompleteGames          int    `json:"completeGames"`
	Shutouts               int    `json:"shutouts"`
	HitBatsmen             int    `json:"hitBatsmen"`
	WildPitches            int    `json:"wildPitches"`
	Pickoffs               int    `json:"pickoffs"`
	AirOuts                int    `json:"airOuts"`
	Rbi                    int    `json:"rbi"`
	InheritedRunners       int    `json:"inheritedRunners"`
	InheritedRunnersScored int    `json:"inheritedRunnersScored"`
	CatchersInterference   int    `json:"catchersInterference"`
	SacBunts               int    `json:"sacBunts"`
	SacFlies               int    `json:"sacFlies"`
}

type BoxScorePlayer added in v0.4.1

type BoxScorePlayer struct {
	Person       IDFullNameLink           `json:"person"`
	JerseyNumber string                   `json:"jerseyNumber"`
	Position     Position                 `json:"position"`
	Stats        BoxScorePlayerStats      `json:"stats"`
	Status       BoxScorePlayerStatus     `json:"status"`
	ParentTeamID int                      `json:"parentTeamId"`
	BattingOrder string                   `json:"battingOrder"`
	SeasonStats  SeasonStats              `json:"seasonStats"`
	GameStatus   BoxScorePlayerGameStatus `json:"gameStatus"`
	AllPositions []AllPositions           `json:"allPositions,omitempty"`
}

type BoxScorePlayerBattingStats added in v0.4.1

type BoxScorePlayerBattingStats struct {
	Note                 string `json:"note"`
	GamesPlayed          int    `json:"gamesPlayed"`
	FlyOuts              int    `json:"flyOuts"`
	GroundOuts           int    `json:"groundOuts"`
	Runs                 int    `json:"runs"`
	Doubles              int    `json:"doubles"`
	Triples              int    `json:"triples"`
	HomeRuns             int    `json:"homeRuns"`
	StrikeOuts           int    `json:"strikeOuts"`
	BaseOnBalls          int    `json:"baseOnBalls"`
	IntentionalWalks     int    `json:"intentionalWalks"`
	Hits                 int    `json:"hits"`
	HitByPitch           int    `json:"hitByPitch"`
	Avg                  string `json:"avg"`
	AtBats               int    `json:"atBats"`
	Obp                  string `json:"obp"`
	Slg                  string `json:"slg"`
	Ops                  string `json:"ops"`
	CaughtStealing       int    `json:"caughtStealing"`
	StolenBases          int    `json:"stolenBases"`
	StolenBasePercentage string `json:"stolenBasePercentage"`
	GroundIntoDoublePlay int    `json:"groundIntoDoublePlay"`
	GroundIntoTriplePlay int    `json:"groundIntoTriplePlay"`
	TotalBases           int    `json:"totalBases"`
	Rbi                  int    `json:"rbi"`
	LeftOnBase           int    `json:"leftOnBase"`
	SacBunts             int    `json:"sacBunts"`
	SacFlies             int    `json:"sacFlies"`
	CatchersInterference int    `json:"catchersInterference"`
	Pickoffs             int    `json:"pickoffs"`
}

type BoxScorePlayerFieldingStats added in v0.4.1

type BoxScorePlayerFieldingStats struct {
	Assists              int    `json:"assists"`
	PutOuts              int    `json:"putOuts"`
	Errors               int    `json:"errors"`
	Chances              int    `json:"chances"`
	Fielding             string `json:"fielding,omitempty"`
	CaughtStealing       int    `json:"caughtStealing"`
	PassedBall           int    `json:"passedBall"`
	StolenBases          int    `json:"stolenBases"`
	StolenBasePercentage string `json:"stolenBasePercentage"`
	Pickoffs             int    `json:"pickoffs"`
}

type BoxScorePlayerGameStatus added in v0.4.1

type BoxScorePlayerGameStatus struct {
	IsCurrentBatter  bool `json:"isCurrentBatter"`
	IsCurrentPitcher bool `json:"isCurrentPitcher"`
	IsOnBench        bool `json:"isOnBench"`
	IsSubstitute     bool `json:"isSubstitute"`
}

type BoxScorePlayerPitchingStats added in v0.4.1

type BoxScorePlayerPitchingStats struct {
	Note                   string `json:"note"`
	GamesPlayed            int    `json:"gamesPlayed"`
	GamesStarted           int    `json:"gamesStarted"`
	GroundOuts             int    `json:"groundOuts"`
	Runs                   int    `json:"runs"`
	Doubles                int    `json:"doubles"`
	Triples                int    `json:"triples"`
	HomeRuns               int    `json:"homeRuns"`
	StrikeOuts             int    `json:"strikeOuts"`
	BaseOnBalls            int    `json:"baseOnBalls"`
	IntentionalWalks       int    `json:"intentionalWalks"`
	Hits                   int    `json:"hits"`
	AtBats                 int    `json:"atBats"`
	CaughtStealing         int    `json:"caughtStealing"`
	StolenBases            int    `json:"stolenBases"`
	StolenBasePercentage   string `json:"stolenBasePercentage"`
	Era                    string `json:"era"`
	InningsPitched         string `json:"inningsPitched"`
	Wins                   int    `json:"wins"`
	Losses                 int    `json:"losses"`
	Saves                  int    `json:"saves"`
	SaveOpportunities      int    `json:"saveOpportunities"`
	Holds                  int    `json:"holds"`
	BlownSaves             int    `json:"blownSaves"`
	EarnedRuns             int    `json:"earnedRuns"`
	Whip                   string `json:"whip"`
	Outs                   int    `json:"outs"`
	GamesPitched           int    `json:"gamesPitched"`
	CompleteGames          int    `json:"completeGames"`
	Shutouts               int    `json:"shutouts"`
	HitBatsmen             int    `json:"hitBatsmen"`
	WildPitches            int    `json:"wildPitches"`
	Pickoffs               int    `json:"pickoffs"`
	AirOuts                int    `json:"airOuts"`
	Rbi                    int    `json:"rbi"`
	WinPercentage          string `json:"winPercentage"`
	GamesFinished          int    `json:"gamesFinished"`
	StrikeoutWalkRatio     string `json:"strikeoutWalkRatio"`
	StrikeoutsPer9Inn      string `json:"strikeoutsPer9Inn"`
	WalksPer9Inn           string `json:"walksPer9Inn"`
	HitsPer9Inn            string `json:"hitsPer9Inn"`
	InheritedRunners       int    `json:"inheritedRunners"`
	InheritedRunnersScored int    `json:"inheritedRunnersScored"`
	CatchersInterference   int    `json:"catchersInterference"`
	SacBunts               int    `json:"sacBunts"`
	SacFlies               int    `json:"sacFlies"`
}

type BoxScorePlayerStats added in v0.4.1

type BoxScorePlayerStats struct {
	Batting  BoxScorePlayerBattingStats  `json:"batting"`
	Pitching BoxScorePlayerPitchingStats `json:"pitching"`
	Fielding BoxScorePlayerFieldingStats `json:"fielding"`
}

type BoxScorePlayerStatus added in v0.4.1

type BoxScorePlayerStatus struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

type BoxScoreRecord added in v0.4.1

type BoxScoreRecord struct {
	GamesPlayed           int                    `json:"gamesPlayed"`
	WildCardGamesBack     string                 `json:"wildCardGamesBack"`
	LeagueGamesBack       string                 `json:"leagueGamesBack"`
	SpringLeagueGamesBack string                 `json:"springLeagueGamesBack"`
	SportGamesBack        string                 `json:"sportGamesBack"`
	DivisionGamesBack     string                 `json:"divisionGamesBack"`
	ConferenceGamesBack   string                 `json:"conferenceGamesBack"`
	LeagueRecord          StandingsGenericRecord `json:"leagueRecord"`
	Records               interface{}            `json:"records"`
	DivisionLeader        bool                   `json:"divisionLeader"`
	Wins                  int                    `json:"wins"`
	Losses                int                    `json:"losses"`
	WinningPercentage     string                 `json:"winningPercentage"`
}

type BoxScoreTeam added in v0.4.1

type BoxScoreTeam struct {
	Team         BoxScoreDetailedTeam      `json:"team"`
	TeamStats    TeamStats                 `json:"teamStats"`
	Players      map[string]BoxScorePlayer `json:"players"`
	Batters      []int                     `json:"batters"`
	Pitchers     []int                     `json:"pitchers"`
	Bench        []int                     `json:"bench"`
	Bullpen      []int                     `json:"bullpen"`
	BattingOrder []int                     `json:"battingOrder"`
	Info         []BoxScoreTeamInfo        `json:"info"`
	Note         []LabelValue              `json:"note"`
}

func (*BoxScoreTeam) BattersTableData added in v0.4.1

func (bst *BoxScoreTeam) BattersTableData() [][]string

BattersTableData formats a team's boxscore data for table printing

func (*BoxScoreTeam) PitchersTableData added in v0.4.1

func (bst *BoxScoreTeam) PitchersTableData() [][]string

PitchersTableData formats a team's pitcher boxscore data for table printing

func (*BoxScoreTeam) PrintBattingTable added in v0.4.1

func (bst *BoxScoreTeam) PrintBattingTable()

PrintBattingTable formats a team's battinng boxscore data for table printing

func (*BoxScoreTeam) PrintPitchingTable added in v0.4.1

func (bst *BoxScoreTeam) PrintPitchingTable()

PrintPitchingTable formats a team's battinng boxscore data for table printing

type BoxScoreTeamInfo added in v0.4.1

type BoxScoreTeamInfo struct {
	Title     string       `json:"title"`
	FieldList []LabelValue `json:"fieldList"`
}

type BoxScoreTeams added in v0.4.1

type BoxScoreTeams struct {
	Away BoxScoreTeam `json:"away"`
	Home BoxScoreTeam `json:"home"`
}

type Client added in v0.4.0

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	// contains filtered or unexported fields
}

Client is a wrapper aroudn an HTTP client for the MLB API

func NewClient added in v0.4.0

func NewClient() *Client

NewClient is a constructor for HTTP clients

func (*Client) Do added in v0.4.0

func (c *Client) Do(req *http.Request, target interface{}) (*http.Response, error)

Do performs a request on the MLB API

func (*Client) NewRequest added in v0.4.0

func (c *Client) NewRequest(method, path string, params map[string]string) (*http.Request, error)

NewRequest creates a new request with query string parameters

type IDFullNameLink struct {
	ID       int    `json:"id"`
	FullName string `json:"fullName"`
	Link     string `json:"link"`
}

IDFullNameLink is another generic struct

type IDLink struct {
	ID   int    `json:"id"`
	Link string `json:"link"`
}

IDLink is another generic struct

type IDNameLink struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Link string `json:"link"`
}

IDNameLink is a generic struct that can represent several different types

type LabelValue added in v0.4.1

type LabelValue struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

LabelValue is another generic struct

type LineScore

type LineScore struct {
	CurrentInning        int               `json:"currentInning"`
	CurrentInningOrdinal string            `json:"currentInningOrdinal"`
	InningState          string            `json:"inningState"`
	InningHalf           string            `json:"inningHalf"`
	IsTopInning          bool              `json:"isTopInning"`
	ScheduledInnings     int               `json:"scheduledInnings"`
	Innings              []LineScoreInning `json:"innings"`
	Teams                LineScoreTeams    `json:"teams"`
	Defense              LineScoreDefense  `json:"defense"`
	Offense              LineScoreOffense  `json:"offense"`
	Balls                int               `json:"balls"`
	Strikes              int               `json:"strikes"`
	Outs                 int               `json:"outs"`
}

LineScore represents an MLB API linescore

func FetchLineScore

func FetchLineScore(id string) *LineScore

FetchLineScore gets a line score from the MLB API

type LineScoreDefense added in v0.4.0

type LineScoreDefense struct {
	Pitcher   IDFullNameLink `json:"pitcher"`
	Catcher   IDFullNameLink `json:"catcher"`
	First     IDFullNameLink `json:"first"`
	Second    IDFullNameLink `json:"second"`
	Third     IDFullNameLink `json:"third"`
	Shortstop IDFullNameLink `json:"shortstop"`
	Left      IDFullNameLink `json:"left"`
	Center    IDFullNameLink `json:"center"`
	Right     IDFullNameLink `json:"right"`
	Team      IDNameLink     `json:"team"`
}

LineScoreDefense gives information about players on defense

type LineScoreInning

type LineScoreInning struct {
	Num        int           `json:"num"`
	OrdinalNum string        `json:"ordinalNum"`
	Home       LineScoreTeam `json:"home,omitempty"`
	Away       LineScoreTeam `json:"away,omitempty"`
}

LineScoreInning represents an inning in a Linescore

type LineScoreOffense added in v0.4.0

type LineScoreOffense struct {
	Batter  IDFullNameLink `json:"batter"`
	OnDeck  IDFullNameLink `json:"onDeck"`
	InHole  IDFullNameLink `json:"inHole"`
	Second  IDFullNameLink `json:"second"`
	Pitcher IDFullNameLink `json:"pitcher"`
	Team    IDNameLink     `json:"team"`
}

LineScoreOffense gives information about players on offense

type LineScoreTeam

type LineScoreTeam struct {
	Runs       int `json:"runs"`
	Hits       int `json:"hits"`
	Errors     int `json:"errors"`
	LeftOnBase int `json:"leftOnBase"`
}

LineScoreTeam is a team's representation in a LineScore

type LineScoreTeams

type LineScoreTeams struct {
	Home LineScoreTeam `json:"home"`
	Away LineScoreTeam `json:"away"`
}

LineScoreTeams maps a LineScoreTeam to Home and another to Away

type Position added in v0.4.1

type Position struct {
	Code         string `json:"code"`
	Name         string `json:"name"`
	Type         string `json:"type"`
	Abbreviation string `json:"abbreviation"`
}

type RosterResponse added in v0.4.0

type RosterResponse struct {
	Roster []struct {
		Person       IDFullNameLink `json:"person"`
		JerseyNumber string         `json:"jerseyNumber"`
		Position     struct {
			Code         string `json:"code"`
			Name         string `json:"name"`
			Type         string `json:"type"`
			Abbreviation string `json:"abbreviation"`
		} `json:"position"`
		Status struct {
			Code        string `json:"code"`
			Description string `json:"description"`
		} `json:"status"`
		ParentTeamID int `json:"parentTeamId"`
	} `json:"roster"`
	Link       string `json:"link"`
	TeamID     int    `json:"teamId"`
	RosterType string `json:"rosterType"`
}

RosterResponse is a response from /v1/teams/<teamid>/roster

type Schedule

type Schedule struct {
	TotalItems           int            `json:"totalItems"`
	TotalEvents          int            `json:"totalEvents"`
	TotalGames           int            `json:"totalGames"`
	TotalGamesInProgress int            `json:"totalGamesInProgress"`
	Dates                []ScheduleDate `json:"dates"`
}

Schedule is a day's worth of games from the MLB API

type ScheduleDate

type ScheduleDate struct {
	Date                 string         `json:"date"`
	TotalItems           int            `json:"totalItems"`
	TotalEvents          int            `json:"totalEvents"`
	TotalGames           int            `json:"totalGames"`
	TotalGamesInProgress int            `json:"totalGamesInProgress"`
	Games                []ScheduleGame `json:"games"`
	Events               []interface{}  `json:"events"`
}

ScheduleDate is one day's worth of games

type ScheduleGame

type ScheduleGame struct {
	GamePk   int                `json:"gamePk"`
	Link     string             `json:"link"`
	GameType string             `json:"gameType"`
	Season   string             `json:"season"`
	GameDate time.Time          `json:"gameDate"`
	Status   ScheduleGameStatus `json:"status,omitempty"`
	Teams    ScheduleTeams      `json:"teams"`
	Venue    IDNameLink         `json:"venue"`
	Content  struct {
		Link string `json:"link"`
	} `json:"content"`
	IsTie                  bool      `json:"isTie,omitempty"`
	GameNumber             int       `json:"gameNumber"`
	PublicFacing           bool      `json:"publicFacing"`
	DoubleHeader           string    `json:"doubleHeader"`
	GamedayType            string    `json:"gamedayType"`
	Tiebreaker             string    `json:"tiebreaker"`
	CalendarEventID        string    `json:"calendarEventID"`
	SeasonDisplay          string    `json:"seasonDisplay"`
	DayNight               string    `json:"dayNight"`
	ScheduledInnings       int       `json:"scheduledInnings"`
	GamesInSeries          int       `json:"gamesInSeries"`
	SeriesGameNumber       int       `json:"seriesGameNumber"`
	SeriesDescription      string    `json:"seriesDescription"`
	RecordSource           string    `json:"recordSource"`
	IfNecessary            string    `json:"ifNecessary"`
	IfNecessaryDescription string    `json:"ifNecessaryDescription"`
	RescheduleDate         time.Time `json:"rescheduleDate,omitempty"`
}

ScheduleGame is a game that is part of a schedule

func FetchGames

func FetchGames(t time.Time) []ScheduleGame

FetchGames gets the latest game data from the MLB API and returns a list of games on the day specified by `t`

func (ScheduleGame) FindTeam

func (g ScheduleGame) FindTeam(team string) bool

FindTeam determines if the team `team` is playing in `game`

func (ScheduleGame) HasTeam

func (g ScheduleGame) HasTeam(abbrv string) bool

HasTeam determines if the team `abbrv` is playing in `game`

func (ScheduleGame) IsOver

func (g ScheduleGame) IsOver() bool

IsOver determines whether or not a game is over

func (ScheduleGame) ParseTime added in v0.3.2

func (g ScheduleGame) ParseTime() time.Time

ParseTime returns a game's time localized to the current time zone

type ScheduleGameStatus

type ScheduleGameStatus struct {
	AbstractGameState string `json:"abstractGameState"`
	CodedGameState    string `json:"codedGameState"`
	DetailedState     string `json:"detailedState"`
	StatusCode        string `json:"statusCode"`
	Reason            string `json:"reason,omitempty"`
	AbstractGameCode  string `json:"abstractGameCode"`
}

ScheduleGameStatus is a status of a game that is part of a Schedule

type ScheduleTeam added in v0.4.0

type ScheduleTeam struct {
	LeagueRecord StandingsGenericRecord `json:"leagueRecord"`
	Score        int                    `json:"score"`
	Team         IDNameLink             `json:"team"`
	IsWinner     bool                   `json:"isWinner"`
	SplitSquad   bool                   `json:"splitSquad"`
	SeriesNumber int                    `json:"seriesNumber"`
}

ScheduleTeam is a team that's part of a Schedule

type ScheduleTeams added in v0.4.0

type ScheduleTeams struct {
	Away ScheduleTeam `json:"away"`
	Home ScheduleTeam `json:"home"`
}

ScheduleTeams is a struct that maps a ScheduleTeam to both Away and Home

type SeasonStats added in v0.4.1

type SeasonStats struct {
	Batting  BoxScoreBattingStats        `json:"batting"`
	Pitching BoxScorePitchingStats       `json:"pitching"`
	Fielding BoxScorePlayerFieldingStats `json:"fielding"`
}

type SpringLeague added in v0.4.1

type SpringLeague struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	Link         string `json:"link"`
	Abbreviation string `json:"abbreviation"`
}

type Standings

type Standings struct {
	Records []StandingsRecord `json:"records"`
}

Standings is a wrapper for StandingsRecords

func FetchStandings

func FetchStandings() *Standings

FetchStandings gets the latest game data from the MLB API and returns a list of games on the day specified by `t`

func (*Standings) FlattenToTeamRecordsSlice added in v0.4.0

func (std *Standings) FlattenToTeamRecordsSlice() []StandingsTeamRecord

FlattenToTeamRecordsSlice takes a Standings pointer and returns a flattened slice of TeamRecords

func (*Standings) PrintMasterStandingsTable

func (std *Standings) PrintMasterStandingsTable()

PrintMasterStandingsTable prints a game-wide standings table to Stdout

func (*Standings) PrintStandingsTable

func (std *Standings) PrintStandingsTable(division string)

PrintStandingsTable prints a standings table for a particular league and division to Stdout

type StandingsDetailedRecords added in v0.4.0

type StandingsDetailedRecords struct {
	SplitRecords    []StandingsGenericRecord  `json:"splitRecords"`
	DivisionRecords []StandingsDivisionRecord `json:"divisionRecords"`
	OverallRecords  []StandingsGenericRecord  `json:"overallRecords"`
	LeagueRecords   []StandingsLeagueRecord   `json:"leagueRecords"`
	ExpectedRecords []StandingsGenericRecord  `json:"expectedRecords"`
}

StandingsDetailedRecords give more granular information about a team's record

type StandingsDivisionRecord added in v0.4.0

type StandingsDivisionRecord struct {
	Wins     int        `json:"wins"`
	Losses   int        `json:"losses"`
	Pct      string     `json:"pct"`
	Division IDNameLink `json:"division"`
}

StandingsDivisionRecord is a team's record against a division

type StandingsGenericRecord added in v0.4.0

type StandingsGenericRecord struct {
	Wins   int    `json:"wins"`
	Losses int    `json:"losses"`
	Type   string `json:"type"`
	Pct    string `json:"pct"`
}

StandingsGenericRecord is a generic representation of several more specialized types of records that come from the standings API

type StandingsLeagueRecord added in v0.4.0

type StandingsLeagueRecord struct {
	Wins   int        `json:"wins"`
	Losses int        `json:"losses"`
	Pct    string     `json:"pct"`
	League IDNameLink `json:"league"`
}

StandingsLeagueRecord is a team's record against a league

type StandingsRecord added in v0.4.0

type StandingsRecord struct {
	StandingsType string                `json:"standingsType"`
	League        IDLink                `json:"league"`
	Division      IDNameLink            `json:"division"`
	Sport         IDLink                `json:"sport"`
	LastUpdated   time.Time             `json:"lastUpdated"`
	TeamRecords   []StandingsTeamRecord `json:"teamRecords"`
}

StandingsRecord is an important standings API struct

func RestrictDivision added in v0.4.0

func RestrictDivision(records []StandingsRecord, division string) []StandingsRecord

RestrictDivision restricts standings to a particular division

func RestrictLeague added in v0.4.0

func RestrictLeague(records []StandingsRecord, league string) []StandingsRecord

RestrictLeague restricts standings to a particular league

type StandingsStreak added in v0.4.0

type StandingsStreak struct {
	StreakType   string `json:"streakType"`
	StreakNumber int    `json:"streakNumber"`
	StreakCode   string `json:"streakCode"`
}

StandingsStreak is a winning or losing streak. You usually want StreakCode, which looks like `W7`.

type StandingsTeamRecord

type StandingsTeamRecord struct {
	Team                      IDNameLink               `json:"team"`
	Season                    string                   `json:"season"`
	Streak                    StandingsStreak          `json:"streak"`
	ClinchIndicator           string                   `json:"clinchIndicator,omitempty"`
	DivisionRank              string                   `json:"divisionRank"`
	LeagueRank                string                   `json:"leagueRank"`
	SportRank                 string                   `json:"sportRank"`
	GamesPlayed               int                      `json:"gamesPlayed"`
	GamesBack                 string                   `json:"gamesBack"`
	WildCardGamesBack         string                   `json:"wildCardGamesBack"`
	LeagueGamesBack           string                   `json:"leagueGamesBack"`
	SpringLeagueGamesBack     string                   `json:"springLeagueGamesBack"`
	SportGamesBack            string                   `json:"sportGamesBack"`
	DivisionGamesBack         string                   `json:"divisionGamesBack"`
	ConferenceGamesBack       string                   `json:"conferenceGamesBack"`
	LeagueRecord              StandingsLeagueRecord    `json:"leagueRecord"`
	LastUpdated               time.Time                `json:"lastUpdated"`
	Records                   StandingsDetailedRecords `json:"records"`
	RunsAllowed               int                      `json:"runsAllowed"`
	RunsScored                int                      `json:"runsScored"`
	DivisionChamp             bool                     `json:"divisionChamp"`
	DivisionLeader            bool                     `json:"divisionLeader"`
	HasWildcard               bool                     `json:"hasWildcard"`
	Clinched                  bool                     `json:"clinched"`
	EliminationNumber         string                   `json:"eliminationNumber"`
	WildCardEliminationNumber string                   `json:"wildCardEliminationNumber"`
	MagicNumber               string                   `json:"magicNumber,omitempty"`
	Wins                      int                      `json:"wins"`
	Losses                    int                      `json:"losses"`
	RunDifferential           int                      `json:"runDifferential"`
	WinningPercentage         string                   `json:"winningPercentage"`
	WildCardRank              string                   `json:"wildCardRank,omitempty"`
}

StandingsTeamRecord gives more detail about a team in the standings

type TeamStats added in v0.4.1

type TeamStats struct {
	Batting  BoxScoreBattingStats        `json:"batting"`
	Pitching BoxScorePitchingStats       `json:"pitching"`
	Fielding BoxScorePlayerFieldingStats `json:"fielding"`
}

Jump to

Keyboard shortcuts

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