-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathGetSubmissionStats.go
49 lines (40 loc) · 1.22 KB
/
GetSubmissionStats.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
package src
import (
"context"
"math"
"github.com/machinebox/graphql"
)
func GetSubmissionStats(username string) (SubmissionData, error) {
client := graphql.NewClient("https://leetcode.com/graphql")
req := graphql.NewRequest(`
query userProblemsSolved($username: String!) {
allQuestionsCount {
count
}
matchedUser(username: $username) {
problemsSolvedBeatsStats {
percentage
}
submitStatsGlobal {
acSubmissionNum {
count
}
}
}
}
`)
req.Var("username", username)
ctx := context.Background()
var respData SubmissionData
if err := client.Run(ctx, req, &respData); err != nil {
return respData, err
}
for i := 0; i < len(respData.MatchedUser.ProblemsSolvedBeatsStats); i++ {
respData.MatchedUser.ProblemsSolvedBeatsStats[i].Percentage = math.Round(respData.MatchedUser.ProblemsSolvedBeatsStats[i].Percentage*10) / 10
}
for i := 0; i < len(respData.MatchedUser.SubmitStatsGlobal.AcSubmissionNum); i++ {
percentage := float64(respData.MatchedUser.SubmitStatsGlobal.AcSubmissionNum[i].Count) / float64(respData.AllQuestionsCount[i].Count)
respData.MatchedUser.SubmitStatsGlobal.AcSubmissionNum[i].Percentage = math.Round(percentage*1000000) / 10000
}
return respData, nil
}