-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
127 lines (116 loc) · 2.64 KB
/
stats.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
package yflib
import (
"fmt"
"github.com/famendola1/yfquery"
)
// Enum of types when requesting for stats.
const (
StatsTypeUnknown = iota
StatsTypeSeason
StatsTypeAverageSeason
StatsTypeDate
StatsTypeWeek
StatsTypeLastWeek
StatsTypeAverageLastWeek
StatsTypeLastMonth
StatsTypeAverageLastMonth
)
var (
// StatIDToName is a map of stat ids to their name.
StatIDToName = map[int]string{
5: "FG%",
8: "FT%",
10: "3PM",
12: "PTS",
15: "REB",
16: "AST",
17: "STL",
18: "BLK",
19: "TOV",
9004003: "FG",
9007006: "FT",
}
// StatNameToID is a map of stat names to their ID.
StatNameToID = map[string]int{
"FG%": 5,
"FT%": 8,
"3PM": 10,
"PTS": 12,
"REB": 15,
"AST": 16,
"STL": 17,
"BLK": 18,
"TOV": 19,
"FG": 9004003,
"FT": 9007006,
}
// NBA9CATIDs is the set of IDs for standard 9CAT NBA fantasy leagues.
NBA9CATIDs = StatIDSet{
5: true,
8: true,
10: true,
12: true,
15: true,
16: true,
17: true,
18: true,
19: true,
}
// inverseStats is the set of stats where having a lower value is considered
// good (e.g. turnovers).
inverseStats = StatIDSet{
19: true,
}
)
// StatIDSet represents a set of stat IDs.
type StatIDSet map[int]bool
// StatsDiff represents the difference of stats between PlayerA and PlayerB.
type StatsDiff struct {
PlayerA string
PlayerB string
Diffs map[int]float64
}
func addStatsTypeToQuery(q *yfquery.StatsQuery, statsType int) (*yfquery.StatsQuery, error) {
switch statsType {
case StatsTypeUnknown:
return nil, fmt.Errorf("unknown stats type requested")
case StatsTypeSeason:
return q.CurrentSeason(), nil
case StatsTypeAverageSeason:
return q.CurrentSeasonAverage(), nil
case StatsTypeDate:
return q.Today(), nil
case StatsTypeLastWeek:
return q.LastWeek(), nil
case StatsTypeAverageLastWeek:
return q.LastWeekAverage(), nil
case StatsTypeLastMonth:
return q.LastMonth(), nil
case StatsTypeAverageLastMonth:
return q.LastMonthAverage(), nil
default:
return nil, fmt.Errorf("unknown stats type requested")
}
}
func convertStatsTypeToSortType(statsType int) yfquery.PlayerSortType {
switch statsType {
case StatsTypeAverageSeason:
fallthrough
case StatsTypeSeason:
return yfquery.PlayerSortTypeSeason
case StatsTypeDate:
return yfquery.PlayerSortTypeDate
case StatsTypeWeek:
return yfquery.PlayerSortTypeWeek
case StatsTypeAverageLastWeek:
fallthrough
case StatsTypeLastWeek:
return yfquery.PlayerSortTypeLastWeek
case StatsTypeAverageLastMonth:
fallthrough
case StatsTypeLastMonth:
return yfquery.PlayerSortTypeLastMonth
default:
return yfquery.PlayerSortTypeUnknown
}
}