-
Notifications
You must be signed in to change notification settings - Fork 12
/
leaderboard.go
145 lines (103 loc) · 4.05 KB
/
leaderboard.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
package platformclientv2
import (
"time"
"github.com/leekchan/timeutil"
"encoding/json"
"strconv"
"strings"
)
// Leaderboard
type Leaderboard struct {
// Division - The targeted division for this leaderboard
Division *Division `json:"division,omitempty"`
// Metric - The metric id if the leaderboard is about a specific metric
Metric *Addressableentityref `json:"metric,omitempty"`
// DateStartWorkday - Start workday used as the date range. Dates are represented as an ISO-8601 string. For example: yyyy-MM-dd
DateStartWorkday *time.Time `json:"dateStartWorkday,omitempty"`
// DateEndWorkday - End workday used as the date range. Dates are represented as an ISO-8601 string. For example: yyyy-MM-dd
DateEndWorkday *time.Time `json:"dateEndWorkday,omitempty"`
// Leaders - The list of leaders generated.
Leaders *[]Leaderboarditem `json:"leaders,omitempty"`
// UserRank - The requesting user's rank
UserRank *Leaderboarditem `json:"userRank,omitempty"`
// PerformanceProfile - The targeted performance profile for the average points
PerformanceProfile *Addressableentityref `json:"performanceProfile,omitempty"`
}
func (o *Leaderboard) MarshalJSON() ([]byte, error) {
// Redundant initialization to avoid unused import errors for models with no Time values
_ = timeutil.Timedelta{}
type Alias Leaderboard
DateStartWorkday := new(string)
if o.DateStartWorkday != nil {
*DateStartWorkday = timeutil.Strftime(o.DateStartWorkday, "%Y-%m-%d")
} else {
DateStartWorkday = nil
}
DateEndWorkday := new(string)
if o.DateEndWorkday != nil {
*DateEndWorkday = timeutil.Strftime(o.DateEndWorkday, "%Y-%m-%d")
} else {
DateEndWorkday = nil
}
return json.Marshal(&struct {
Division *Division `json:"division,omitempty"`
Metric *Addressableentityref `json:"metric,omitempty"`
DateStartWorkday *string `json:"dateStartWorkday,omitempty"`
DateEndWorkday *string `json:"dateEndWorkday,omitempty"`
Leaders *[]Leaderboarditem `json:"leaders,omitempty"`
UserRank *Leaderboarditem `json:"userRank,omitempty"`
PerformanceProfile *Addressableentityref `json:"performanceProfile,omitempty"`
*Alias
}{
Division: o.Division,
Metric: o.Metric,
DateStartWorkday: DateStartWorkday,
DateEndWorkday: DateEndWorkday,
Leaders: o.Leaders,
UserRank: o.UserRank,
PerformanceProfile: o.PerformanceProfile,
Alias: (*Alias)(o),
})
}
func (o *Leaderboard) UnmarshalJSON(b []byte) error {
var LeaderboardMap map[string]interface{}
err := json.Unmarshal(b, &LeaderboardMap)
if err != nil {
return err
}
if Division, ok := LeaderboardMap["division"].(map[string]interface{}); ok {
DivisionString, _ := json.Marshal(Division)
json.Unmarshal(DivisionString, &o.Division)
}
if Metric, ok := LeaderboardMap["metric"].(map[string]interface{}); ok {
MetricString, _ := json.Marshal(Metric)
json.Unmarshal(MetricString, &o.Metric)
}
if dateStartWorkdayString, ok := LeaderboardMap["dateStartWorkday"].(string); ok {
DateStartWorkday, _ := time.Parse("2006-01-02", dateStartWorkdayString)
o.DateStartWorkday = &DateStartWorkday
}
if dateEndWorkdayString, ok := LeaderboardMap["dateEndWorkday"].(string); ok {
DateEndWorkday, _ := time.Parse("2006-01-02", dateEndWorkdayString)
o.DateEndWorkday = &DateEndWorkday
}
if Leaders, ok := LeaderboardMap["leaders"].([]interface{}); ok {
LeadersString, _ := json.Marshal(Leaders)
json.Unmarshal(LeadersString, &o.Leaders)
}
if UserRank, ok := LeaderboardMap["userRank"].(map[string]interface{}); ok {
UserRankString, _ := json.Marshal(UserRank)
json.Unmarshal(UserRankString, &o.UserRank)
}
if PerformanceProfile, ok := LeaderboardMap["performanceProfile"].(map[string]interface{}); ok {
PerformanceProfileString, _ := json.Marshal(PerformanceProfile)
json.Unmarshal(PerformanceProfileString, &o.PerformanceProfile)
}
return nil
}
// String returns a JSON representation of the model
func (o *Leaderboard) String() string {
j, _ := json.Marshal(o)
str, _ := strconv.Unquote(strings.Replace(strconv.Quote(string(j)), `\\u`, `\u`, -1))
return str
}