-
Notifications
You must be signed in to change notification settings - Fork 8
/
distribution.go
73 lines (62 loc) · 1.96 KB
/
distribution.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
package opendota
import (
"net/http"
"github.com/dghubble/sling"
)
func newDistributionService(sling *sling.Sling) *DistributionService {
return &DistributionService{
sling: sling.Path("distributions"),
}
}
// DistributionService provides a method for accesing
// distribution data for Matchmaking Ranking (MMR).
type DistributionService struct {
sling *sling.Sling
}
// Distribution holds distributions of Matchmaking Ranking (MMR)
// data for each region.
type Distribution struct {
Mmr Mmr `json:"mmr"`
CountryMmr CountryMmr `json:"country_mmr"`
}
type CountryMmr struct {
Command string `json:"command"`
RowCount int `json:"rowCount"`
Oid int `json:"oid"`
Rows []CountryMmrRow `json:"rows"`
Fields []Field `json:"fields"`
RowAsArray bool `json:"rowAsArray"`
}
type CountryMmrRow struct {
Loccountrycode string `json:"loccountrycode"`
Count int `json:"count"`
Avg string `json:"avg"`
Common string `json:"common"`
}
type Mmr struct {
Command string `json:"command"`
RowCount int `json:"rowCount"`
Oid int `json:"oid"`
Rows []MmrRow `json:"rows"`
Fields []Field `json:"fields"`
RowAsArray bool `json:"rowAsArray"`
Sum Sum `json:"sum"`
}
type MmrRow struct {
Bin int `json:"bin"`
BinName int `json:"bin_name"`
Count int `json:"count"`
CumulativeSum int `json:"cumulative_sum"`
}
type Sum struct {
Count int `json:"count"`
}
// Distributions returns a collection of Matchmaking Ranking (MMR) distributions
// for each region.
// https://docs.opendota.com/#tag/distributions%2Fpaths%2F~1distributions%2Fget
func (s *DistributionService) Distributions() (Distribution, *http.Response, error) {
distribution := new(Distribution)
apiError := new(APIError)
resp, err := s.sling.New().Receive(distribution, apiError)
return *distribution, resp, relevantError(err, *apiError)
}