statsapi

package
v0.0.0-...-de618e6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat = "01/02/2006"
)

Variables

View Source
var (
	ScheduleGameAnd = func(fn ...func(*ScheduleGameDoc) bool) func(*ScheduleGameDoc) bool {
		return func(g *ScheduleGameDoc) bool {
			accept := true
			for i := 0; i < len(fn) && accept; i++ {
				accept = fn[i](g)
			}
			return accept
		}
	}

	ScheduleGameWithType = func(scheduleGameTypes ...string) func(*ScheduleGameDoc) bool {
		accept := map[string]bool{}
		for _, curr := range scheduleGameTypes {
			accept[strings.ToUpper(curr)] = true
		}

		defaultTrue := len(accept) == 0
		return func(g *ScheduleGameDoc) bool {
			return defaultTrue || accept[strings.ToUpper(g.GameType)]
		}
	}

	ScheduleGameWithCodedState = func(scheduleGameCodedState ...string) func(*ScheduleGameDoc) bool {
		accept := map[string]bool{}
		for _, curr := range scheduleGameCodedState {
			accept[strings.ToUpper(curr)] = true
		}

		defaultTrue := len(accept) == 0
		return func(g *ScheduleGameDoc) bool {
			return defaultTrue || accept[strings.ToUpper(g.Status.CodedGameState)]
		}
	}
)
View Source
var (
	ErrInvalidScheduleRequest = fmt.Errorf("Invalid schedule request")
)
View Source
var (
	PitchSystem = geom.NewCoord3([6]float64{-20, 0, 0, -10 + 40, 0 + 80, 0 + 20})
)

Functions

func ProcessPlay

func ProcessPlay(doc *FeedDoc) (*mlb.Game, []*mlb.Play, []*mlb.Pitch, []*mlb.PitchSpatial, error)

func ProcessPlayer

func ProcessPlayer(doc *FeedDoc) ([]*mlb.Player, error)

Types

type FeedAtBat

type FeedAtBat struct {
	Result struct {
		Type        string `json:"type"`
		Event       string `json:"event"`
		EventType   string `json:"eventType"`
		Description string `json:"description"`
		Rbi         int    `json:"rbi"`
		AwayScore   int    `json:"awayScore"`
		HomeScore   int    `json:"homeScore"`
	} `json:"result"`
	About struct {
		AtBatIndex       int        `json:"atBatIndex"`
		HalfInning       string     `json:"halfInning"`
		IsTopInning      bool       `json:"isTopInning"`
		Inning           int        `json:"inning"`
		StartTime        *time.Time `json:"startTime"`
		EndTime          *time.Time `json:"endTime"`
		IsComplete       bool       `json:"isComplete"`
		IsScoringPlay    bool       `json:"isScoringPlay"`
		HasReview        bool       `json:"hasReview"`
		HasOut           bool       `json:"hasOut"`
		CaptivatingIndex int        `json:"captivatingIndex"`
	} `json:"about"`
	Count   *FeedCount `json:"count"`
	Matchup struct {
		Batter  *FeedPlayer `json:"batter"`
		BatSide struct {
			Code        string `json:"code"`
			Description string `json:"description"`
		} `json:"batSide"`
		Pitcher   *FeedPlayer `json:"pitcher"`
		PitchHand struct {
			Code        string `json:"code"`
			Description string `json:"description"`
		} `json:"pitchHand"`
		BatterHotColdZones  []interface{} `json:"batterHotColdZones"`
		PitcherHotColdZones []interface{} `json:"pitcherHotColdZones"`
		Splits              struct {
			Batter    string `json:"batter"`
			Pitcher   string `json:"pitcher"`
			MenOnBase string `json:"menOnBase"`
		} `json:"splits"`
	} `json:"matchup,omitempty"`
	PitchIndex  []int            `json:"pitchIndex"`
	ActionIndex []int            `json:"actionIndex"`
	RunnerIndex []int            `json:"runnerIndex"`
	Runners     []*FeedRunner    `json:"runners"`
	PlayEvents  []*FeedPlayEvent `json:"playEvents"`
	AtBatIndex  int              `json:"atBatIndex"`
	PlayEndTime time.Time        `json:"playEndTime"`
}

type FeedCount

type FeedCount struct {
	Balls   *int `json:"balls"`
	Strikes *int `json:"strikes"`
	Outs    *int `json:"outs"`
}

type FeedDoc

type FeedDoc struct {
	Copyright string `json:"copyright"`
	GamePk    int    `json:"gamePk"`
	Link      string `json:"link"`
	MetaData  struct {
		Wait          int      `json:"wait"`
		TimeStamp     string   `json:"timeStamp"`
		GameEvents    []string `json:"gameEvents"`
		LogicalEvents []string `json:"logicalEvents"`
	} `json:"metaData"`
	GameData struct {
		Game struct {
			Pk              int    `json:"pk"`
			Type            string `json:"type"`
			DoubleHeader    string `json:"doubleHeader"`
			ID              string `json:"id"`
			GamedayType     string `json:"gamedayType"`
			Tiebreaker      string `json:"tiebreaker"`
			GameNumber      int    `json:"gameNumber"`
			CalendarEventID string `json:"calendarEventID"`
			Season          string `json:"season"`
			SeasonDisplay   string `json:"seasonDisplay"`
		} `json:"game"`
		Datetime struct {
			DateTime     time.Time `json:"dateTime"`
			OriginalDate string    `json:"originalDate"`
			DayNight     string    `json:"dayNight"`
			Time         string    `json:"time"`
			Ampm         string    `json:"ampm"`
		} `json:"datetime"`
		Status struct {
			AbstractGameState string `json:"abstractGameState"`
			CodedGameState    string `json:"codedGameState"`
			DetailedState     string `json:"detailedState"`
			StatusCode        string `json:"statusCode"`
			AbstractGameCode  string `json:"abstractGameCode"`
		} `json:"status"`
		Teams struct {
			Away *FeedTeam `json:"away"`
			Home *FeedTeam `json:"home"`
		} `json:"teams"`
		Player  map[string]*FeedPlayerProfile `json:"players"`
		Venue   *FeedVenue                    `json:"venue"`
		Weather struct {
			Condition string `json:"condition"`
			Temp      string `json:"temp"`
			Wind      string `json:"wind"`
		} `json:"weather"`
		Review struct {
			HasChallenges bool `json:"hasChallenges"`
			Away          struct {
				Used      int `json:"used"`
				Remaining int `json:"remaining"`
			} `json:"away"`
			Home struct {
				Used      int `json:"used"`
				Remaining int `json:"remaining"`
			} `json:"home"`
		} `json:"review"`
		Flags struct {
			NoHitter            bool `json:"noHitter"`
			PerfectGame         bool `json:"perfectGame"`
			AwayTeamNoHitter    bool `json:"awayTeamNoHitter"`
			AwayTeamPerfectGame bool `json:"awayTeamPerfectGame"`
			HomeTeamNoHitter    bool `json:"homeTeamNoHitter"`
			HomeTeamPerfectGame bool `json:"homeTeamPerfectGame"`
		} `json:"flags"`
		Alerts           []interface{} `json:"alerts"`
		ProbablePitchers struct {
			Away *FeedPlayer `json:"away"`
			Home *FeedPlayer `json:"home"`
		} `json:"probablePitchers"`
		OfficialScorer    *FeedPlayer `json:"officialScorer"`
		PrimaryDatacaster *FeedPlayer `json:"primaryDatacaster"`
	} `json:"gameData"`
	LiveData struct {
		Plays struct {
			AllPlays     []*FeedAtBat `json:"allPlays"`
			ScoringPlays []int        `json:"scoringPlays"`
		} `json:"plays"`
	} `json:"liveData"`
}

func Feed

func Feed(ctx context.Context, gameID int) (json.RawMessage, *FeedDoc, error)

type FeedPlayEvent

type FeedPlayEvent struct {
	Index       int        `json:"index"`
	PfxID       string     `json:"pfxId"`
	PlayID      uuid.UUID  `json:"playId"`
	PitchNumber int        `json:"pitchNumber"`
	StartTime   *time.Time `json:"startTime"`
	EndTime     *time.Time `json:"endTime"`
	IsPitch     bool       `json:"isPitch"`
	Type        string     `json:"type"`

	Details struct {
		Event     string `json:"event"`
		EventType string `json:"eventType"`
		Call      struct {
			Code        string `json:"code"`
			Description string `json:"description"`
		} `json:"call"`
		Description   string `json:"description"`
		Code          string `json:"code"`
		BallColor     string `json:"ballColor"`
		TrailColor    string `json:"trailColor"`
		IsInPlay      bool   `json:"isInPlay"`
		IsStrike      bool   `json:"isStrike"`
		IsBall        bool   `json:"isBall"`
		IsScoringPlay bool   `json:"isScoringPlay"`
		AwayScore     *int   `json:"awayScore"`
		HomeScore     *int   `json:"homeScore"`
		Type          struct {
			Code        string `json:"code"`
			Description string `json:"description"`
		} `json:"type"`
		HasReview bool `json:"hasReview"`
	} `json:"details"`

	Count *FeedCount `json:"count,omitempty"`

	Player struct {
		ID   int    `json:"id"`
		Link string `json:"link"`
	} `json:"player,omitempty"`

	PitchData *struct {
		StartSpeed       float64 `json:"startSpeed"`
		EndSpeed         float64 `json:"endSpeed"`
		StrikeZoneTop    float64 `json:"strikeZoneTop"`
		StrikeZoneBottom float64 `json:"strikeZoneBottom"`
		Coordinates      struct {
			AX   float64 `json:"aX"`
			AY   float64 `json:"aY"`
			AZ   float64 `json:"aZ"`
			PfxX float64 `json:"pfxX"`
			PfxZ float64 `json:"pfxZ"`
			PX   float64 `json:"pX"`
			PZ   float64 `json:"pZ"`
			VX0  float64 `json:"vX0"`
			VY0  float64 `json:"vY0"`
			VZ0  float64 `json:"vZ0"`
			X    float64 `json:"x"`
			Y    float64 `json:"y"`
			X0   float64 `json:"x0"`
			Y0   float64 `json:"y0"`
			Z0   float64 `json:"z0"`
		} `json:"coordinates"`
		Breaks struct {
			BreakAngle    float64 `json:"breakAngle"`
			BreakLength   float64 `json:"breakLength"`
			BreakY        float64 `json:"breakY"`
			SpinRate      float64 `json:"spinRate"`
			SpinDirection float64 `json:"spinDirection"`
		} `json:"breaks"`
		Zone      int     `json:"zone"`
		PlateTime float64 `json:"plateTime"`
		Extension float64 `json:"extension"`
	} `json:"pitchData,omitempty"`

	HitData *struct {
		LaunchSpeed   float64 `json:"launchSpeed"`
		LaunchAngle   float64 `json:"launchAngle"`
		TotalDistance float64 `json:"totalDistance"`
		Trajectory    string  `json:"trajectory"`
		Hardness      string  `json:"hardness"`
		Location      string  `json:"location"`
		Coordinates   struct {
			CoordX float64 `json:"coordX"`
			CoordY float64 `json:"coordY"`
		} `json:"coordinates"`
	} `json:"hitData,omitempty"`
}

type FeedPlayer

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

type FeedPlayerProfile

type FeedPlayerProfile struct {
	ID                 int    `json:"id"`
	FullName           string `json:"fullName"`
	Link               string `json:"link"`
	FirstName          string `json:"firstName"`
	LastName           string `json:"lastName"`
	PrimaryNumber      string `json:"primaryNumber"`
	BirthDate          string `json:"birthDate"`
	CurrentAge         int    `json:"currentAge"`
	BirthCity          string `json:"birthCity"`
	BirthStateProvince string `json:"birthStateProvince"`
	BirthCountry       string `json:"birthCountry"`
	Height             string `json:"height"`
	Weight             int    `json:"weight"`
	Active             bool   `json:"active"`
	PrimaryPosition    struct {
		Code         string `json:"code"`
		Name         string `json:"name"`
		Type         string `json:"type"`
		Abbreviation string `json:"abbreviation"`
	} `json:"primaryPosition"`
	UseName       string `json:"useName"`
	MiddleName    string `json:"middleName"`
	BoxscoreName  string `json:"boxscoreName"`
	NickName      string `json:"nickName"`
	Gender        string `json:"gender"`
	IsPlayer      bool   `json:"isPlayer"`
	IsVerified    bool   `json:"isVerified"`
	DraftYear     int    `json:"draftYear"`
	Pronunciation string `json:"pronunciation"`
	MlbDebutDate  string `json:"mlbDebutDate"`
	BatSide       struct {
		Code        string `json:"code"`
		Description string `json:"description"`
	} `json:"batSide"`
	PitchHand struct {
		Code        string `json:"code"`
		Description string `json:"description"`
	} `json:"pitchHand"`
	NameFirstLast    string  `json:"nameFirstLast"`
	NameSlug         string  `json:"nameSlug"`
	FirstLastName    string  `json:"firstLastName"`
	LastFirstName    string  `json:"lastFirstName"`
	LastInitName     string  `json:"lastInitName"`
	InitLastName     string  `json:"initLastName"`
	FullFMLName      string  `json:"fullFMLName"`
	FullLFMName      string  `json:"fullLFMName"`
	StrikeZoneTop    float64 `json:"strikeZoneTop"`
	StrikeZoneBottom float64 `json:"strikeZoneBottom"`
}

type FeedRunner

type FeedRunner struct {
	Movement struct {
		Start     *string `json:"start"`
		End       *string `json:"end"`
		OutBase   string  `json:"outBase"`
		IsOut     bool    `json:"isOut"`
		OutNumber int     `json:"outNumber"`
	} `json:"movement"`

	Details struct {
		Event              string      `json:"event"`
		EventType          string      `json:"eventType"`
		MovementReason     interface{} `json:"movementReason"`
		Runner             *FeedPlayer `json:"runner"`
		ResponsiblePitcher interface{} `json:"responsiblePitcher"`
		IsScoringEvent     bool        `json:"isScoringEvent"`
		Rbi                bool        `json:"rbi"`
		Earned             bool        `json:"earned"`
		TeamUnearned       bool        `json:"teamUnearned"`
		PlayIndex          int         `json:"playIndex"`
	} `json:"details"`

	Credits []struct {
		Player struct {
			ID   int    `json:"id"`
			Link string `json:"link"`
		} `json:"player"`
		Position struct {
			Code         string `json:"code"`
			Name         string `json:"name"`
			Type         string `json:"type"`
			Abbreviation string `json:"abbreviation"`
		} `json:"position"`
		Credit string `json:"credit"`
	} `json:"credits"`
}

type FeedTeam

type FeedTeam struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Link   string `json:"link"`
	Season int    `json:"season"`
	Venue  struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Link string `json:"link"`
	} `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          struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Link string `json:"link"`
	} `json:"league"`
	Division struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Link string `json:"link"`
	} `json:"division"`
	Sport struct {
		ID   int    `json:"id"`
		Link string `json:"link"`
		Name string `json:"name"`
	} `json:"sport"`
	ShortName string `json:"shortName"`
	Record    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          struct {
			Wins   int    `json:"wins"`
			Losses int    `json:"losses"`
			Pct    string `json:"pct"`
		} `json:"leagueRecord"`
		Records struct {
		} `json:"records"`
		DivisionLeader    bool   `json:"divisionLeader"`
		Wins              int    `json:"wins"`
		Losses            int    `json:"losses"`
		WinningPercentage string `json:"winningPercentage"`
	} `json:"record"`
	SpringLeague struct {
		ID           int    `json:"id"`
		Name         string `json:"name"`
		Link         string `json:"link"`
		Abbreviation string `json:"abbreviation"`
	} `json:"springLeague"`
	AllStarStatus string `json:"allStarStatus"`
	Active        bool   `json:"active"`
}

type FeedVenue

type FeedVenue struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Link     string `json:"link"`
	Location struct {
		City               string `json:"city"`
		State              string `json:"state"`
		StateAbbrev        string `json:"stateAbbrev"`
		DefaultCoordinates struct {
			Latitude  float64 `json:"latitude"`
			Longitude float64 `json:"longitude"`
		} `json:"defaultCoordinates"`
	} `json:"location"`
	TimeZone struct {
		ID     string `json:"id"`
		Offset int    `json:"offset"`
		Tz     string `json:"tz"`
	} `json:"timeZone"`
	FieldInfo struct {
		Capacity    int    `json:"capacity"`
		TurfType    string `json:"turfType"`
		RoofType    string `json:"roofType"`
		LeftLine    int    `json:"leftLine"`
		LeftCenter  int    `json:"leftCenter"`
		Center      int    `json:"center"`
		RightCenter int    `json:"rightCenter"`
		RightLine   int    `json:"rightLine"`
	} `json:"fieldInfo"`
}

type ScheduleDoc

type ScheduleDoc struct {
	Copyright            string `json:"copyright"`
	TotalItems           int    `json:"totalItems"`
	TotalEvents          int    `json:"totalEvents"`
	TotalGames           int    `json:"totalGames"`
	TotalGamesInProgress int    `json:"totalGamesInProgress"`
	Dates                []*struct {
		Date                 string             `json:"date"`
		TotalItems           int                `json:"totalItems"`
		TotalEvents          int                `json:"totalEvents"`
		TotalGames           int                `json:"totalGames"`
		TotalGamesInProgress int                `json:"totalGamesInProgress"`
		Games                []*ScheduleGameDoc `json:"games"`
		Events               []interface{}      `json:"events"`
	} `json:"dates"`
}

func Schedule

func Schedule(ctx context.Context, startDate, endDate *time.Time) ([]byte, *ScheduleDoc, error)

func (*ScheduleDoc) Games

func (doc *ScheduleDoc) Games(accept func(*ScheduleGameDoc) bool) []*ScheduleGameDoc

type ScheduleGameDoc

type ScheduleGameDoc struct {
	GamePk       int       `json:"gamePk"`
	Link         string    `json:"link"`
	GameType     string    `json:"gameType"`
	Season       string    `json:"season"`
	GameDate     time.Time `json:"gameDate"`
	OfficialDate string    `json:"officialDate"`

	Status struct {
		AbstractGameState string `json:"abstractGameState"`
		CodedGameState    string `json:"codedGameState"`
		DetailedState     string `json:"detailedState"`
		StatusCode        string `json:"statusCode"`
		AbstractGameCode  string `json:"abstractGameCode"`
	} `json:"status"`

	Teams struct {
		Away struct {
			LeagueRecord struct {
				Wins   int    `json:"wins"`
				Losses int    `json:"losses"`
				Pct    string `json:"pct"`
			} `json:"leagueRecord"`
			Team struct {
				ID   int    `json:"id"`
				Name string `json:"name"`
				Link string `json:"link"`
			} `json:"team"`
			SplitSquad   bool `json:"splitSquad"`
			SeriesNumber int  `json:"seriesNumber"`
		} `json:"away"`
		Home struct {
			LeagueRecord struct {
				Wins   int    `json:"wins"`
				Losses int    `json:"losses"`
				Pct    string `json:"pct"`
			} `json:"leagueRecord"`
			Team struct {
				ID   int    `json:"id"`
				Name string `json:"name"`
				Link string `json:"link"`
			} `json:"team"`
			SplitSquad   bool `json:"splitSquad"`
			SeriesNumber int  `json:"seriesNumber"`
		} `json:"home"`
	} `json:"teams"`

	Venue struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Link string `json:"link"`
	} `json:"venue"`

	Content struct {
		Link string `json:"link"`
	} `json:"content"`

	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"`
	InningBreakLength      int    `json:"inningBreakLength"`
	GamesInSeries          int    `json:"gamesInSeries"`
	SeriesGameNumber       int    `json:"seriesGameNumber"`
	SeriesDescription      string `json:"seriesDescription"`
	RecordSource           string `json:"recordSource"`
	IfNecessary            string `json:"ifNecessary"`
	IfNecessaryDescription string `json:"ifNecessaryDescription"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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