-
Notifications
You must be signed in to change notification settings - Fork 2
/
review_statistic.go
131 lines (111 loc) · 3.87 KB
/
review_statistic.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
package wanikaniapi
import (
"strconv"
"time"
)
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Exported functions
//
//
//
//////////////////////////////////////////////////////////////////////////////
// ReviewStatisticGet retrieves a specific review statistic by its ID.
func (c *Client) ReviewStatisticGet(params *ReviewStatisticGetParams) (*ReviewStatistic, error) {
obj := &ReviewStatistic{}
err := c.request("GET", "/v2/review_statistics/"+strconv.Itoa(int(*params.ID)), params, nil, obj)
return obj, err
}
// ReviewStatisticList returns a collection of all review statistics, ordered
// by ascending CreatedAt, 500 at a time.
func (c *Client) ReviewStatisticList(params *ReviewStatisticListParams) (*ReviewStatisticPage, error) {
obj := &ReviewStatisticPage{}
err := c.request("GET", "/v2/review_statistics", params, nil, obj)
return obj, err
}
//////////////////////////////////////////////////////////////////////////////
//
//
//
// Exported constants/types
//
//
//
//////////////////////////////////////////////////////////////////////////////
// ReviewStatistic summarizes the activity recorded in reviews. They contain
// sum the number of correct and incorrect answers for both meaning and
// reading. They track current and maximum streaks of correct answers. They
// store the overall percentage of correct answers versus total answers.
//
// A review statistic is created when the user has done their first review on
// the related subject.
type ReviewStatistic struct {
Object
Data *ReviewStatisticData `json:"data"`
}
// ReviewStatisticData contains core data of ReviewStatistic.
type ReviewStatisticData struct {
CreatedAt time.Time `json:"created_at"`
Hidden bool `json:"hidden"`
MeaningCorrect int `json:"meaning_correct"`
MeaningCurrentStreak int `json:"meaning_current_streak"`
MeaningIncorrect int `json:"meaning_incorrect"`
MeaningMaxStreak int `json:"meaning_max_streak"`
PercentageCorrect int `json:"percentage_correct"`
ReadingCorrect int `json:"reading_correct"`
ReadingCurrentStreak int `json:"reading_current_streak"`
ReadingIncorrect int `json:"reading_incorrect"`
ReadingMaxStreak int `json:"reading_max_streak"`
SubjectID WKID `json:"subject_id"`
SubjectType WKObjectType `json:"subject_type"`
}
// ReviewStatisticGetParams are parameters for ReviewStatisticGet.
type ReviewStatisticGetParams struct {
Params
ID *WKID
}
// ReviewStatisticListParams are parameters for ReviewStatisticList.
type ReviewStatisticListParams struct {
ListParams
Params
Hidden *bool
IDs []WKID
PercentagesGreaterThan *int
PercentagesLesserThan *int
SubjectIDs []WKID
SubjectTypes []WKObjectType
UpdatedAfter *WKTime
}
// EncodeToQuery encodes parametes to a query string.
func (p *ReviewStatisticListParams) EncodeToQuery() string {
values := p.encodeToURLValues()
if p.Hidden != nil {
values.Add("hidden", strconv.FormatBool(*p.Hidden))
}
if p.IDs != nil {
values.Add("ids", joinIDs(p.IDs, ","))
}
if p.PercentagesGreaterThan != nil {
values.Add("percentages_greater_than", strconv.Itoa(*p.PercentagesGreaterThan))
}
if p.PercentagesLesserThan != nil {
values.Add("percentages_lesser_than", strconv.Itoa(*p.PercentagesLesserThan))
}
if p.SubjectIDs != nil {
values.Add("subject_ids", joinIDs(p.SubjectIDs, ","))
}
if p.SubjectTypes != nil {
values.Add("subject_types", joinObjectTypes(p.SubjectTypes, ","))
}
if p.UpdatedAfter != nil {
values.Add("updated_after", p.UpdatedAfter.Encode())
}
return values.Encode()
}
// ReviewStatisticPage represents a single page of ReviewStatistics.
type ReviewStatisticPage struct {
PageObject
Data []*ReviewStatistic `json:"data"`
}