1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Package model holds league-agnostic domain types used across the UI.
// ESPN-specific JSON is decoded in the espn package and mapped into these.
package model
import "time"
// State is the coarse lifecycle of a game, normalized from ESPN's
// status.type.state ("pre" | "in" | "post").
type State int
const (
StatePre State = iota // scheduled, not started
StateLive // in progress
StateFinal // completed
)
func (s State) String() string {
switch s {
case StateLive:
return "LIVE"
case StateFinal:
return "FINAL"
default:
return "SCHED"
}
}
// Team is one side of a competition.
type Team struct {
ID string // stable ESPN team id, used to key favorites
Abbr string // e.g. "PHI"
Name string // short display name, e.g. "Phillies"
FullName string // e.g. "Philadelphia Phillies"
Color string // primary hex color w/o leading '#', from ESPN
AltColor string
Score int
Record string // e.g. "40-30"
Winner bool
}
// Game is a single matchup, normalized across all leagues.
type Game struct {
ID string
League LeagueID
Start time.Time
State State
Home Team
Away Team
Detail string // status.type.detail, e.g. "Top 5th", "Final/10", "6:40 PM EDT"
Clock string // displayClock when live
Period int // inning / quarter / half
Venue string
Headline string // optional recap/odds blurb
// Situation is the live play state, currently baseball-only (count, outs,
// bases, pitcher/batter). Nil when absent (not live, or sport without it).
Situation *Situation
}
// Situation is the live in-game state for baseball: the count, outs, occupied
// bases, and who's at the plate / on the mound. Populated from the scoreboard
// endpoint's competition situation while a game is live.
type Situation struct {
Balls, Strikes, Outs int
OnFirst, OnSecond, OnThird bool
Pitcher, Batter string // display names
PitcherLine, BatterLine string // ESPN summary lines ("5.1 IP, 2 ER…", "1-3")
LastPlay string
}
// Started reports whether play has begun (live or final).
func (g Game) Started() bool { return g.State != StatePre }
|