This repository has been archived by the owner on Aug 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.go
171 lines (147 loc) · 5.44 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
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
package raiponce
type GeneralStats struct {
CountRemarksPublish int `json:"count_remarks_publish"`
CountRemarksUnpublish int `json:"count_remarks_unpublish"`
CountResponsesPublish int `json:"count_responses_publish"`
CountResponsesUnpublish int `json:"count_responses_unpublish"`
CountUsers int `json:"count_users"`
CountVotesRemarksSexist int `json:"count_votes_remarks_sexist"`
CountVotesRemarksLived int `json:"count_votes_remarks_lived"`
CountVotesResponses int `json:"count_votes_responses"`
}
type Stats struct {
Count int `json:"nb"`
CreatedYear int `json:"created_year"`
CreatedMonth int `json:"created_month"`
CreatedDay int `json:"created_day"`
PostedYear int `json:"posted_year"`
PostedMonth int `json:"posted_month"`
PostedDay int `json:"posted_day"`
Emotion int `json:"emotion_id"`
Theme int `json:"theme_id"`
ScaleEmotion int `json:"scale_emotion"`
Remark int `json:"remark_id"`
Author int `json:"author_id"`
User int `json:"user_id"`
Action int `json:"action"`
IsUsedForScore int `json:"is_used_for_score"`
Type int `json:"type"`
Voter int `json:"voter_id"`
Receiver int `json:"receiver_id"`
Response int `json:"response_id"`
}
type CollectionStats []Stats
type ByCreated struct{ CollectionStats }
type ByPosted struct{ CollectionStats }
const (
statsURI = "/stats"
StatsRemarksURI = statsURI + "/remarks"
StatsResponsesURI = statsURI + "/responses"
StatsScoresURI = statsURI + "/scores"
StatsUsersURI = statsURI + "/users"
StatsVotesRemarksURI = statsURI + "/votes/remarks"
StatsVotesResponsesURI = statsURI + "/votes/responses"
FilterFrom = "from"
FilterTo = "to"
FilterCreatedBefore = "created_before"
FilterCreatedAfter = "created_after"
FilterPostedBefore = "posted_before"
FilterPostedAfter = "posted_after"
FilterCreatedYear = "created_year"
FilterCreatedMonth = "created_month"
FilterCreatedDay = "created_day"
FilterPostedYear = "posted_year"
FilterPostedMonth = "posted_month"
FilterPostedDay = "posted_day"
FilterEmotion = "emotion"
FilterTheme = "theme"
FilterScaleEmotion = "scale_emotion"
FilterRemark = "remark"
FilterResponse = "response"
FilterAuthor = "author"
FilterUser = "user"
FilterAction = "action"
FilterIsUsedForScore = "is_used_for_score"
FilterType = "type"
FilterVoter = "voter"
FilterReceiver = "receiver"
OrderCreatedYear = "created_year"
OrderCreatedMonth = "created_month"
OrderCreatedDay = "created_day"
OrderPostedYear = "posted_year"
OrderPostedMonth = "posted_month"
OrderPostedDay = "posted_day"
OrderEmotion = "emotion"
OrderTheme = "theme"
OrderScaleEmotion = "scale_emotion"
OrderCount = "count"
OrderRemark = "remark"
OrderResponse = "response"
OrderAuthor = "author"
OrderUser = "user"
OrderAction = "action"
OrderIsUsedForScore = "is_used_for_score"
OrderType = "type"
OrderVoter = "voter"
OrderReceiver = "receiver"
GroupCreatedYear = "created_year"
GroupCreatedMonth = "created_month"
GroupCreatedDay = "created_day"
GroupPostedYear = "posted_year"
GroupPostedMonth = "posted_month"
GroupPostedDay = "posted_day"
GroupEmotion = "emotion"
GroupTheme = "theme"
GroupScaleEmotion = "scale_emotion"
GroupRemark = "remark"
GroupResponse = "response"
GroupAuthor = "author"
GroupUser = "user"
GroupAction = "action"
GroupIsUsedForScore = "is_used_for_score"
GroupType = "type"
GroupVoter = "voter"
GroupReceiver = "receiver"
)
// === Sort implementation ===
func (stats CollectionStats) Len() int {
return len(stats)
}
func (stats CollectionStats) Swap(i, j int) {
stats[i], stats[j] = stats[j], stats[i]
}
func (stats ByCreated) Less(i, j int) bool {
if stats.CollectionStats[i].CreatedYear != stats.CollectionStats[j].CreatedYear {
return stats.CollectionStats[i].CreatedYear < stats.CollectionStats[j].CreatedYear
}
if stats.CollectionStats[i].CreatedMonth != stats.CollectionStats[j].CreatedMonth {
return stats.CollectionStats[i].CreatedMonth < stats.CollectionStats[j].CreatedMonth
}
if stats.CollectionStats[i].CreatedDay != stats.CollectionStats[j].CreatedDay {
return stats.CollectionStats[i].CreatedDay < stats.CollectionStats[j].CreatedDay
}
return false
}
func (stats ByPosted) Less(i, j int) bool {
if stats.CollectionStats[i].PostedYear != stats.CollectionStats[j].PostedYear {
return stats.CollectionStats[i].PostedYear < stats.CollectionStats[j].PostedYear
}
if stats.CollectionStats[i].PostedMonth != stats.CollectionStats[j].PostedMonth {
return stats.CollectionStats[i].PostedMonth < stats.CollectionStats[j].PostedMonth
}
if stats.CollectionStats[i].PostedDay != stats.CollectionStats[j].PostedDay {
return stats.CollectionStats[i].PostedDay < stats.CollectionStats[j].PostedDay
}
return false
}
// ====
func (client *Client) GetGeneralStats(query *QueryFilter) *GeneralStats {
stats := &GeneralStats{}
client.cget(statsURI, stats, query)
return stats
}
func (client *Client) GetStats(uri string, query *QueryFilter) *CollectionStats {
stats := &CollectionStats{}
client.cget(uri, stats, query)
return stats
}