Skip to content

Commit 4067a78

Browse files
committed
Add person data statistic
1 parent fbbc4ff commit 4067a78

15 files changed

+843
-522
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.toml

README.md

+293-279
Large diffs are not rendered by default.

automation/models/lcproblems.go

-43
This file was deleted.

automation/render.go

-190
This file was deleted.

ctl/config.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/BurntSushi/toml"
8+
)
9+
10+
const (
11+
configTOML = "config.toml"
12+
)
13+
14+
type config struct {
15+
Username string
16+
Password string
17+
Cookie string
18+
}
19+
20+
func (c config) String() string {
21+
return fmt.Sprintf("Username: %s, Password: %s", c.Username, c.Password)
22+
}
23+
24+
func getConfig() *config {
25+
cfg := new(config)
26+
if _, err := toml.DecodeFile(configTOML, &cfg); err != nil {
27+
log.Panicf(err.Error())
28+
}
29+
// log.Printf("get config: %s", cfg)
30+
return cfg
31+
}

ctl/models/lcproblems.go

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package models
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// LeetCodeProblemAll define
8+
type LeetCodeProblemAll struct {
9+
UserName string `json:"user_name"`
10+
NumSolved int32 `json:"num_solved"`
11+
NumTotal int32 `json:"num_total"`
12+
AcEasy int32 `json:"ac_easy"`
13+
AcMedium int32 `json:"ac_medium"`
14+
AcHard int32 `json:"ac_hard"`
15+
StatStatusPairs []StatStatusPairs `json:"stat_status_pairs"`
16+
FrequencyHigh int32 `json:"frequency_high"`
17+
FrequencyMid int32 `json:"frequency_mid"`
18+
CategorySlug string `json:"category_slug"`
19+
AcEasyTotal int32
20+
AcMediumTotal int32
21+
AcHardTotal int32
22+
}
23+
24+
// ConvertUserInfoModel define
25+
func ConvertUserInfoModel(lpa LeetCodeProblemAll) UserInfo {
26+
info := UserInfo{}
27+
info.UserName = lpa.UserName
28+
info.NumSolved = lpa.NumSolved
29+
info.NumTotal = lpa.NumTotal
30+
info.AcEasy = lpa.AcEasy
31+
info.AcMedium = lpa.AcMedium
32+
info.AcHard = lpa.AcHard
33+
info.FrequencyHigh = lpa.FrequencyHigh
34+
info.FrequencyMid = lpa.FrequencyMid
35+
info.CategorySlug = lpa.CategorySlug
36+
return info
37+
}
38+
39+
// StatStatusPairs define
40+
type StatStatusPairs struct {
41+
Stat Stat `json:"stat"`
42+
Status string `json:"status"`
43+
Difficulty Difficulty `json:"difficulty"`
44+
PaidOnly bool `json:"paid_only"`
45+
IsFavor bool `json:"is_favor"`
46+
Frequency float64 `json:"frequency"`
47+
Progress float64 `json:"progress"`
48+
}
49+
50+
// ConvertMdModel define
51+
func ConvertMdModel(problems []StatStatusPairs) []Mdrow {
52+
mdrows := []Mdrow{}
53+
for _, problem := range problems {
54+
res := Mdrow{}
55+
res.FrontendQuestionID = problem.Stat.FrontendQuestionID
56+
res.QuestionTitle = problem.Stat.QuestionTitle
57+
res.QuestionTitleSlug = problem.Stat.QuestionTitleSlug
58+
res.Acceptance = fmt.Sprintf("%.1f%%", (problem.Stat.TotalAcs/problem.Stat.TotalSubmitted)*100)
59+
res.Difficulty = DifficultyMap[problem.Difficulty.Level]
60+
res.Frequency = fmt.Sprintf("%f", problem.Frequency)
61+
mdrows = append(mdrows, res)
62+
}
63+
return mdrows
64+
}
65+
66+
// ConvertMdModelFromIds define
67+
func ConvertMdModelFromIds(problemsMap map[int]StatStatusPairs, ids []int) []Mdrow {
68+
mdrows := []Mdrow{}
69+
for _, v := range ids {
70+
res, problem := Mdrow{}, problemsMap[v]
71+
res.FrontendQuestionID = problem.Stat.FrontendQuestionID
72+
res.QuestionTitle = problem.Stat.QuestionTitle
73+
res.QuestionTitleSlug = problem.Stat.QuestionTitleSlug
74+
res.Acceptance = fmt.Sprintf("%.1f%%", (problem.Stat.TotalAcs/problem.Stat.TotalSubmitted)*100)
75+
res.Difficulty = DifficultyMap[problem.Difficulty.Level]
76+
res.Frequency = fmt.Sprintf("%f", problem.Frequency)
77+
mdrows = append(mdrows, res)
78+
}
79+
return mdrows
80+
}
81+
82+
// Stat define
83+
type Stat struct {
84+
QuestionTitle string `json:"question__title"`
85+
QuestionTitleSlug string `json:"question__title_slug"`
86+
TotalAcs float64 `json:"total_acs"`
87+
TotalSubmitted float64 `json:"total_submitted"`
88+
Acceptance string
89+
Difficulty string
90+
FrontendQuestionID int32 `json:"frontend_question_id"`
91+
}
92+
93+
// Difficulty define
94+
type Difficulty struct {
95+
Level int32 `json:"level"`
96+
}
97+
98+
// DifficultyMap define
99+
var DifficultyMap = map[int32]string{
100+
1: "Easy",
101+
2: "Medium",
102+
3: "Hard",
103+
}

0 commit comments

Comments
 (0)