2024-07-02 04:16:44 +00:00
|
|
|
package statsapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FeedParams struct {
|
|
|
|
GamePk string
|
|
|
|
}
|
|
|
|
|
|
|
|
type FeedResponse struct {
|
2024-07-03 06:01:02 +00:00
|
|
|
GamePk string
|
2024-07-02 04:16:44 +00:00
|
|
|
MetaData metadata
|
2024-07-03 06:01:02 +00:00
|
|
|
GameData gamedata
|
2024-07-02 04:16:44 +00:00
|
|
|
LiveData livedata
|
|
|
|
}
|
|
|
|
|
|
|
|
type metadata struct {
|
|
|
|
TimeStamp string
|
|
|
|
}
|
|
|
|
|
2024-07-03 06:01:02 +00:00
|
|
|
type gamedata struct {
|
|
|
|
Teams teams
|
|
|
|
}
|
|
|
|
|
|
|
|
type teams struct {
|
|
|
|
Away team
|
|
|
|
Home team
|
|
|
|
}
|
|
|
|
|
|
|
|
type team struct {
|
|
|
|
LocationName string
|
|
|
|
TeamName string
|
|
|
|
}
|
|
|
|
|
2024-07-02 04:16:44 +00:00
|
|
|
type livedata struct {
|
2024-07-03 06:01:02 +00:00
|
|
|
Plays plays
|
|
|
|
Linescore linescore
|
2024-07-02 04:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type plays struct {
|
|
|
|
AllPlays []Play
|
|
|
|
CurrentPlay Play
|
|
|
|
ScoringPlays []json.Number
|
|
|
|
}
|
|
|
|
|
|
|
|
type Play struct {
|
|
|
|
Result result
|
|
|
|
About about
|
|
|
|
AtBatIndex int
|
|
|
|
}
|
|
|
|
|
|
|
|
type result struct {
|
|
|
|
Event string
|
|
|
|
Description string
|
|
|
|
RBI int
|
|
|
|
AwayScore int
|
|
|
|
HomeScore int
|
|
|
|
}
|
|
|
|
|
|
|
|
type about struct {
|
|
|
|
AtBatIndex json.Number
|
|
|
|
IsTopInning bool
|
|
|
|
Inning json.Number
|
|
|
|
IsScoringPlay bool
|
|
|
|
CaptivatingIndex json.Number
|
|
|
|
}
|
|
|
|
|
2024-07-03 06:01:02 +00:00
|
|
|
type linescore struct {
|
|
|
|
Teams teamLines
|
|
|
|
}
|
|
|
|
|
|
|
|
type teamLines struct {
|
|
|
|
Home teamline
|
|
|
|
Away teamline
|
|
|
|
}
|
|
|
|
|
|
|
|
type teamline struct {
|
|
|
|
Runs json.Number
|
|
|
|
Hits json.Number
|
|
|
|
Errors json.Number
|
|
|
|
LeftOnBase json.Number
|
|
|
|
}
|
|
|
|
|
2024-07-02 04:16:44 +00:00
|
|
|
func (p *Play) Patch(patch Patch) {
|
|
|
|
instructions := patch.Diff
|
|
|
|
stem := "/liveData/plays/currentPlay"
|
|
|
|
for _, i := range instructions {
|
|
|
|
if i.Op == "add" && i.Path == stem+"/result/description" {
|
|
|
|
p.Result.Description = i.Value.(string)
|
|
|
|
} else if i.Op == "replace" && i.Path == stem+"/about/isScoringPlay" {
|
|
|
|
p.About.IsScoringPlay = i.Value.(bool)
|
|
|
|
} else if i.Op == "replace" && i.Path == stem+"/result/homeScore" {
|
|
|
|
p.Result.HomeScore = int(i.Value.(float64))
|
|
|
|
} else if i.Op == "replace" && i.Path == stem+"/result/awayScore" {
|
|
|
|
p.Result.AwayScore = int(i.Value.(float64))
|
|
|
|
} else if i.Op == "add" && i.Path == stem+"/result/event" {
|
|
|
|
p.Result.Event = i.Value.(string)
|
|
|
|
} else if i.Op == "replace" && i.Path == stem+"/atBatIndex" {
|
|
|
|
p.AtBatIndex = int(i.Value.(float64))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|