-
Notifications
You must be signed in to change notification settings - Fork 17
/
fixture.go
307 lines (274 loc) · 12 KB
/
fixture.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package uof
import (
"encoding/xml"
"fmt"
"time"
)
type FixtureRsp struct {
Fixture Fixture `xml:"fixture" json:"fixture"`
GeneratedAt time.Time `xml:"generated_at,attr,omitempty" json:"generatedAt,omitempty"`
}
// Fixtures describe static or semi-static information about matches and races.
// Reference: https://docs.betradar.com/display/BD/UOF+-+Fixtures+in+the+API
type Fixture struct {
ID int `xml:"-" json:"id"`
URN URN `xml:"id,attr,omitempty" json:"urn"`
StartTime time.Time `xml:"start_time,attr,omitempty" json:"startTime,omitempty"`
StartTimeConfirmed bool `xml:"start_time_confirmed,attr,omitempty" json:"startTimeConfirmed,omitempty"`
StartTimeTbd bool `xml:"start_time_tbd,attr,omitempty" json:"startTimeTbd,omitempty"`
NextLiveTime time.Time `xml:"next_live_time,attr,omitempty" json:"nextLiveTime,omitempty"`
Liveodds string `xml:"liveodds,attr,omitempty" json:"liveodds,omitempty"`
Status string `xml:"status,attr,omitempty" json:"status,omitempty"`
Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
Scheduled time.Time `xml:"scheduled,attr,omitempty" json:"scheduled,omitempty"`
ScheduledEnd time.Time `xml:"scheduled_end,attr,omitempty" json:"scheduledEnd,omitempty"`
ReplacedBy string `xml:"replaced_by,attr,omitempty" json:"replacedBy,omitempty"`
Sport Sport `xml:"sport" json:"sport"`
Category Category `xml:"category" json:"category"`
Tournament Tournament `xml:"tournament,omitempty" json:"tournament,omitempty"`
Round Round `xml:"tournament_round,omitempty" json:"round,omitempty"`
Season Season `xml:"season,omitempty" json:"season,omitempty"`
Venue Venue `xml:"venue,omitempty" json:"venue,omitempty"`
ProductInfo ProductInfo `xml:"product_info,omitempty" json:"productInfo,omitempty"`
Competitors []Competitor `xml:"competitors>competitor,omitempty" json:"competitors,omitempty"`
TvChannels []TvChannel `xml:"tv_channels>tv_channel,omitempty" json:"tvChannels,omitempty"`
Home Competitor `json:"home"`
Away Competitor `json:"away"`
ExtraInfo []ExtraInfo `xml:"extra_info>info,omitempty" json:"extraInfo,omitempty"`
Races []SportEvent `xml:"races>sport_event,omitempty" json:"races,omitempty"`
// this also exists but we are skiping for the time being
//ReferenceIDs ReferenceIDs `xml:"reference_ids,omitempty" json:"referenceIDs,omitempty"`
//SportEventConditions SportEventConditions `xml:"sport_event_conditions,omitempty" json:"sportEventConditions,omitempty"`
//DelayedInfo DelayedInfo `xml:"delayed_info,omitempty" json:"delayedInfo,omitempty"`
//CoverageInfo CoverageInfo `xml:"coverage_info,omitempty" json:"coverageInfo,omitempty"`
//ScheduledStartTimeChanges []ScheduledStartTimeChange `xml:"scheduled_start_time_changes>scheduled_start_time_change,omitempty" json:"scheduledStartTimeChanges,omitempty"`
//Parent *ParentStage `xml:"parent,omitempty" json:"parent,omitempty"`
}
type Tournament struct {
ID int `json:"id"`
Name string `xml:"name,attr" json:"name"`
}
type Sport struct {
ID int `json:"id"`
Name string `xml:"name,attr" json:"name"`
}
type Category struct {
ID int `json:"id"`
Name string `xml:"name,attr" json:"name"`
CountryCode string `xml:"country_code,attr,omitempty" json:"countryCode,omitempty"`
}
type Competitor struct {
ID int `json:"id"`
Qualifier string `xml:"qualifier,attr,omitempty" json:"qualifier,omitempty"`
Name string `xml:"name,attr" json:"name"`
Abbreviation string `xml:"abbreviation,attr" json:"abbreviation"`
Country string `xml:"country,attr,omitempty" json:"country,omitempty"`
CountryCode string `xml:"country_code,attr,omitempty" json:"countryCode,omitempty"`
Virtual bool `xml:"virtual,attr,omitempty" json:"virtual,omitempty"`
Players []CompetitorPlayer `xml:"players>player,omitempty" json:"players,omitempty"`
//ReferenceIDs CompetitorReferenceIDs `xml:"reference_ids,omitempty" json:"referenceIDs,omitempty"`
}
type CompetitorPlayer struct {
ID int `json:"id"`
Name string `xml:"name,attr" json:"name"`
Abbreviation string `xml:"abbreviation,attr" json:"abbreviation"`
Nationality string `xml:"nationality,attr,omitempty" json:"nationality,omitempty"`
}
type Venue struct {
ID int `json:"id"`
Name string `xml:"name,attr" json:"name"`
Capacity int `xml:"capacity,attr,omitempty" json:"capacity,omitempty"`
CityName string `xml:"city_name,attr,omitempty" json:"cityName,omitempty"`
CountryName string `xml:"country_name,attr,omitempty" json:"countryName,omitempty"`
CountryCode string `xml:"country_code,attr,omitempty" json:"countryCode,omitempty"`
MapCoordinates string `xml:"map_coordinates,attr,omitempty" json:"mapCoordinates,omitempty"`
}
type TvChannel struct {
Name string `xml:"name,attr" json:"name"`
// seams to be always zero
// StartTime time.Time `xml:"start_time,attr,omitempty" json:"startTime,omitempty"`
}
type StreamingChannel struct {
ID int `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
}
type ProductInfoLink struct {
Name string `xml:"name,attr" json:"name"`
Ref string `xml:"ref,attr" json:"ref"`
}
type Round struct {
ID int `xml:"betradar_id,attr,omitempty" json:"id,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
Number int `xml:"number,attr,omitempty" json:"number,omitempty"`
Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
GroupLongName string `xml:"group_long_name,attr,omitempty" json:"groupLongName,omitempty"`
Group string `xml:"group,attr,omitempty" json:"group,omitempty"`
GroupID string `xml:"group_id,attr,omitempty" json:"groupID,omitempty"`
CupRoundMatches int `xml:"cup_round_matches,attr,omitempty" json:"cupRoundMatches,omitempty"`
CupRoundMatchNumber int `xml:"cup_round_match_number,attr,omitempty" json:"cupRoundMatchNumber,omitempty"`
OtherMatchID string `xml:"other_match_id,attr,omitempty" json:"otherMatchID,omitempty"`
}
type Season struct {
ID int `json:"id"`
StartDate string `xml:"start_date,attr" json:"startDate"`
EndDate string `xml:"end_date,attr" json:"endDate"`
StartTime string `xml:"start_time,attr,omitempty" json:"startTime,omitempty"`
EndTime string `xml:"end_time,attr,omitempty" json:"endTime,omitempty"`
Year string `xml:"year,attr,omitempty" json:"year,omitempty"`
Name string `xml:"name,attr" json:"name"`
//TournamentID string `xml:"tournament_id,attr,omitempty" json:"tournamentID,omitempty"`
}
// type ParentStage struct {
// URN URN `xml:"id,attr,omitempty" json:"urn,omitempty"`
// Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
// Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
// Scheduled time.Time `xml:"scheduled,attr,omitempty" json:"scheduled,omitempty"`
// StartTimeTbd bool `xml:"start_time_tbd,attr,omitempty" json:"startTimeTbd,omitempty"`
// ScheduledEnd time.Time `xml:"scheduled_end,attr,omitempty" json:"scheduledEnd,omitempty"`
// ReplacedBy string `xml:"replaced_by,attr,omitempty" json:"replacedBy,omitempty"`
// }
// type ScheduledStartTimeChange struct {
// OldTime time.Time `xml:"old_time,attr" json:"oldTime"`
// NewTime time.Time `xml:"new_time,attr" json:"newTime"`
// ChangedAt time.Time `xml:"changed_at,attr" json:"changedAt"`
// }
type ProductInfo struct {
Streaming []StreamingChannel `xml:"streaming>channel,omitempty" json:"streaming,omitempty"`
IsInLiveScore string `xml:"is_in_live_score,omitempty" json:"isInLiveScore,omitempty"`
IsInHostedStatistics string `xml:"is_in_hosted_statistics,omitempty" json:"isInHostedStatistics,omitempty"`
IsInLiveCenterSoccer string `xml:"is_in_live_center_soccer,omitempty" json:"isInLiveCenterSoccer,omitempty"`
IsAutoTraded string `xml:"is_auto_traded,omitempty" json:"isAutoTraded,omitempty"`
Links []ProductInfoLink `xml:"links>link,omitempty" json:"links,omitempty"`
}
// ExtraInfo covers additional fixture information about the match,
// such as coverage information, extended markets offer, additional rules etc.
type ExtraInfo struct {
Key string `xml:"key,attr,omitempty" json:"key,omitempty"`
Value string `xml:"value,attr,omitempty" json:"value,omitempty"`
}
// SportEvent covers information about scheduled races in a stage
// For VHC and VDR information is in vdr/vhc:stage:<int> fixture with type="parent"
type SportEvent struct {
ID string `xml:"id,attr,omitempty" json:"id,omitempty"`
Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
Scheduled time.Time `xml:"scheduled,attr,omitempty" json:"scheduled,omitempty"`
ScheduledEnd time.Time `xml:"scheduled_end,attr,omitempty" json:"scheduled_end,omitempty"`
}
func (f *Fixture) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Fixture
var overlay struct {
*T
Tournament *struct {
URN URN `xml:"id,attr"`
Name string `xml:"name,attr"`
Sport Sport `xml:"sport"`
Category Category `xml:"category"`
} `xml:"tournament,omitempty"`
}
overlay.T = (*T)(f)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
if overlay.Tournament == nil {
return fmt.Errorf("missing tournament for fixture URN %s", f.URN)
}
f.ID = overlay.URN.EventID()
f.Sport = overlay.Tournament.Sport
f.Category = overlay.Tournament.Category
f.Tournament.ID = overlay.Tournament.URN.ID()
f.Tournament.Name = overlay.Tournament.Name
for _, c := range f.Competitors {
if c.Qualifier == "home" {
f.Home = c
}
if c.Qualifier == "away" {
f.Away = c
}
}
return nil
}
func (t *Sport) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Sport
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
func (t *Category) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Category
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
func (t *Season) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Season
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
func (t *Venue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Venue
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
func (t *Competitor) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T Competitor
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
func (t *CompetitorPlayer) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type T CompetitorPlayer
var overlay struct {
*T
URN URN `xml:"id,attr"`
}
overlay.T = (*T)(t)
if err := d.DecodeElement(&overlay, &start); err != nil {
return err
}
t.ID = overlay.URN.ID()
return nil
}
// PP pretty prints fixure row
func (f *Fixture) PP() string {
name := fmt.Sprintf("%s - %s", f.Home.Name, f.Away.Name)
return fmt.Sprintf("%-90s %12s %15s", name, f.Scheduled.Format("02.01. 15:04"), f.Status)
}