-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
188 lines (167 loc) · 4.52 KB
/
state.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
package main
import (
"encoding/json"
"sync"
)
type state struct {
teamsId []int
rawGames []Game
rawRankings []GroupRankings
teams map[int]Team
gamesPerTeam map[int][]Game
rankingPerTeam map[int]GroupRankings
leaguePerTeam map[int]League
groupPerTeam map[int]Group
lock *sync.RWMutex
}
func newState(teamsId []int) *state {
internalState := state{
teamsId: teamsId,
lock: &sync.RWMutex{},
}
return &internalState
}
func (s *state) isManagedTeam(teamId int) bool {
if len(s.teamsId) == 0 {
return true
}
for _, id := range s.teamsId {
if id == teamId {
return true
}
}
return false
}
type Game struct {
GameId int `json:"gameId"`
PlayDate string `json:"playDate"`
Gender string `json:"gender"`
Status int `json:"status"`
Teams struct {
Home Team `json:"home"`
Away Team `json:"away"`
} `json:"teams"`
League League `json:"league"`
Phase Phase `json:"phase"`
Group Group `json:"group"`
Hall Hall `json:"hall"`
Referees Referees `json:"referees"`
SetResults SetResults `json:"setResults"`
ResultSummary ResultSummaries `json:"resultSummary"`
}
type Team struct {
TeamId int `json:"teamId"`
Caption string `json:"caption"`
ClubId string `json:"clubId"`
ClubCaption string `json:"clubCaption"`
}
type League struct {
LeagueId int `json:"leagueId"`
LeagueCategoryId int `json:"leagueCategoryId"`
Caption string `json:"caption"`
Translations struct {
D string `json:"d"`
ShortD string `json:"shortD"`
F string `json:"f"`
ShortF string `json:"shortF"`
} `json:"translations"`
}
type Phase struct {
PhaseId int `json:"phaseId"`
Caption string `json:"caption"`
Translations struct {
D string `json:"d"`
ShortD string `json:"shortD"`
F string `json:"f"`
ShortF string `json:"shortF"`
} `json:"translations"`
}
type Group struct {
GroupId int `json:"groupId"`
Caption string `json:"caption"`
Translations struct {
D string `json:"d"`
ShortD string `json:"shortD"`
F string `json:"f"`
ShortF string `json:"shortF"`
} `json:"translations"`
}
type Hall struct {
HallId int `json:"hallId"`
Caption string `json:"caption"`
Street string `json:"street"`
Number string `json:"number"`
Zip string `json:"zip"`
City string `json:"city"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
PlusCode string `json:"plusCode"`
}
type SetResults struct {
Data map[string]SetResult
}
type SetResult struct {
Home string `json:"home"`
Away string `json:"away"`
}
func (r *SetResults) UnmarshalJSON(data []byte) error {
var setResultsMap map[string]SetResult
if err := json.Unmarshal(data, &setResultsMap); err == nil {
r.Data = setResultsMap
}
return nil
}
type Referees struct {
Data map[string]Referee
}
func (r *Referees) UnmarshalJSON(data []byte) error {
var refereesMap map[string]Referee
if err := json.Unmarshal(data, &refereesMap); err == nil {
r.Data = refereesMap
}
return nil
}
type ResultSummaries struct {
Data ResultSummary
}
func (r *ResultSummaries) UnmarshalJSON(data []byte) error {
var resultSummary ResultSummary
if err := json.Unmarshal(data, &resultSummary); err == nil {
r.Data = resultSummary
}
return nil
}
type Referee struct {
RefereeId int `json:"refereeId"`
LastName string `json:"lastName"`
FirstName string `json:"firstName"`
}
type ResultSummary struct {
WonSetsHomeTeam int `json:"wonSetsHomeTeam"`
WonSetsAwayTeam int `json:"wonSetsAwayTeam"`
Winner string `json:"winner"`
}
type GroupRankings struct {
LeagueId int `json:"leagueId"`
PhaseId int `json:"phaseId"`
GroupId int `json:"groupId"`
Ranking []TeamRanking `json:"ranking"`
}
type TeamRanking struct {
Rank int `json:"rank"`
TeamId int `json:"teamId,omitempty"`
TeamCaption string `json:"teamCaption"`
Games int `json:"games"`
Points int `json:"points"`
Wins int `json:"wins"`
WinsClear int `json:"winsClear"`
WinsNarrow int `json:"winsNarrow"`
Defeats int `json:"defeats"`
DefeatsClear int `json:"defeatsClear"`
DefeatsNarrow int `json:"defeatsNarrow"`
SetsWon int `json:"setsWon"`
SetsLost int `json:"setsLost"`
BallsWon int `json:"ballsWon"`
BallsLost int `json:"ballsLost"`
IsTeam bool `json:"isTeam"`
}