From 8eecb0b1cff995190a4cafbe39ba149dddd69265 Mon Sep 17 00:00:00 2001 From: tomoish Date: Fri, 2 Feb 2024 22:10:20 +0900 Subject: [PATCH 1/3] Fix judgeProfession --- src/funcs/handle_profession.go | 30 +++++++++++++----------------- src/main.go | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/funcs/handle_profession.go b/src/funcs/handle_profession.go index 831e6b2..a5674bb 100644 --- a/src/funcs/handle_profession.go +++ b/src/funcs/handle_profession.go @@ -1,11 +1,7 @@ package funcs -import ( - "fmt" -) - // 職業を判定する関数 -func judgeProfession(rank string, topLanguages []string, percentages []float64) string { +func JudgeProfession(rank string, topLanguages []string, percentages []float64) string { // 職業のルートと言語を定義 magicRoute := map[string]string{ "TypeScript": "攻撃魔法", "R": "ネクロマンサー", "Flutter": "防御魔法", @@ -119,15 +115,15 @@ func getFinalProfession(profession string, rank string) string { return finalProfession } -func main() { - fmt.Println(judgeProfession("C+", []string{"Go"}, []float64{100})) // 召喚士 - fmt.Println(judgeProfession("A", []string{"Python", "Java"}, []float64{20, 20})) // 特級 士官と騎士 - fmt.Println(judgeProfession("C", []string{}, []float64{})) // 少年 - fmt.Println(judgeProfession("B-", []string{"TypeScript"}, []float64{100})) // 攻撃魔法の見習い - fmt.Println(judgeProfession("B", []string{"C"}, []float64{100})) // 初級 無法者 - fmt.Println(judgeProfession("B+", []string{"Java"}, []float64{100})) // 中級 騎士 - fmt.Println(judgeProfession("A-", []string{"Rust"}, []float64{100})) // 上級 回復術師 - fmt.Println(judgeProfession("A", []string{"Go"}, []float64{100})) // 特級 召喚士 - fmt.Println(judgeProfession("A+", []string{"Assembly"}, []float64{100})) // 賞金稼ぎのラスボス - fmt.Println(judgeProfession("S", []string{"Python"}, []float64{100})) // 神 -} +// func main() { +// fmt.Println(judgeProfession("C+", []string{"Go"}, []float64{100})) // 召喚士 +// fmt.Println(judgeProfession("A", []string{"Python", "Java"}, []float64{20, 20})) // 特級 士官と騎士 +// fmt.Println(judgeProfession("C", []string{}, []float64{})) // 少年 +// fmt.Println(judgeProfession("B-", []string{"TypeScript"}, []float64{100})) // 攻撃魔法の見習い +// fmt.Println(judgeProfession("B", []string{"C"}, []float64{100})) // 初級 無法者 +// fmt.Println(judgeProfession("B+", []string{"Java"}, []float64{100})) // 中級 騎士 +// fmt.Println(judgeProfession("A-", []string{"Rust"}, []float64{100})) // 上級 回復術師 +// fmt.Println(judgeProfession("A", []string{"Go"}, []float64{100})) // 特級 召喚士 +// fmt.Println(judgeProfession("A+", []string{"Assembly"}, []float64{100})) // 賞金稼ぎのラスボス +// fmt.Println(judgeProfession("S", []string{"Python"}, []float64{100})) // 神 +// } diff --git a/src/main.go b/src/main.go index d31b0ec..07fcfc6 100644 --- a/src/main.go +++ b/src/main.go @@ -186,5 +186,5 @@ func main() { // fmt.Println("totalIssueContributions: ", totalIssueContributions) // fmt.Println("totalPullRequestContributions: ", totalPullRequestContributions) // fmt.Println("totalRepositoryContributions: ", totalRepositoryContributions) - + fmt.Println(funcs.JudgeProfession("C+", []string{"Go"}, []float64{100})) } From a7555da0e076bed410a8836a8179749b2b808fad Mon Sep 17 00:00:00 2001 From: tomoish Date: Fri, 2 Feb 2024 22:14:41 +0900 Subject: [PATCH 2/3] Change port --- src/graphs/commit_chart.go | 2 +- src/main.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/graphs/commit_chart.go b/src/graphs/commit_chart.go index e5c5506..531a716 100644 --- a/src/graphs/commit_chart.go +++ b/src/graphs/commit_chart.go @@ -58,7 +58,7 @@ func DrawCommitChart(commitsHistory []int, maxCommits int, width int, height int p.Y.Max = float64(maxCommits) + 5 // ラベルの外に余白を持つ - p.Title.Padding = 10 // タイトル周りの余白 + p.Title.Padding = 10 // タイトル周りの余白 p.X.Label.Padding = 2 // X軸ラベル周りの余白 p.Y.Label.Padding = 2 // Y軸ラベル周りの余白 diff --git a/src/main.go b/src/main.go index 646cd7c..bf2f87b 100644 --- a/src/main.go +++ b/src/main.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "strconv" + "github.com/tomoish/readme/funcs" "github.com/tomoish/readme/graphs" ) @@ -114,7 +115,7 @@ import ( // } // 画像生成エンドポイント -func createhandler(w http.ResponseWriter, r *http.Request) { +func createHandler(w http.ResponseWriter, r *http.Request) { queryValues := r.URL.Query() username := queryValues.Get("username") if r.Method == http.MethodGet { @@ -174,9 +175,9 @@ func main() { // http.HandleFunc("/user", getuserHandler) // http.HandleFunc("/merge", mergeAllContents) // http.HandleFunc("/background", getBackgroundHandler) - http.HandleFunc("/create", createhandler) + http.HandleFunc("/create", createHandler) fmt.Println("Hello, World!") - err := http.ListenAndServe(":8000", nil) + err := http.ListenAndServe(":8080", nil) if err != nil { log.Fatalf("HTTP server failed: %v", err) } From 1c524e70b0cff1a03047c9a30be3fbe55c5838e3 Mon Sep 17 00:00:00 2001 From: tomoish Date: Fri, 2 Feb 2024 22:25:23 +0900 Subject: [PATCH 3/3] Remove font in plot --- src/graphs/commit_chart.go | 11 +++++------ src/main.go | 40 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/graphs/commit_chart.go b/src/graphs/commit_chart.go index 531a716..d2c409f 100644 --- a/src/graphs/commit_chart.go +++ b/src/graphs/commit_chart.go @@ -5,7 +5,6 @@ import ( "image/color" "gonum.org/v1/plot" - "gonum.org/v1/plot/font" "gonum.org/v1/plot/plotter" "gonum.org/v1/plot/vg" // "github.com/fogleman/gg" @@ -43,11 +42,11 @@ func DrawCommitChart(commitsHistory []int, maxCommits int, width int, height int } line.Color = color.RGBA{R: 135, G: 206, B: 235, A: 255} p.Add(line) - plot.DefaultFont = font.Font{ - Typeface: "Roboto-Medium.ttf", - Variant: "Roboto-Medium.ttf", - Size: 12.0, - } + // plot.DefaultFont = font.Font{ + // Typeface: "Roboto-Medium.ttf", + // Variant: "Roboto-Medium.ttf", + // Size: 12.0, + // } p.Title.Text = "Contribution History" p.X.Label.Text = "Days" p.Y.Label.Text = "Commits" diff --git a/src/main.go b/src/main.go index bf2f87b..78f0719 100644 --- a/src/main.go +++ b/src/main.go @@ -71,30 +71,30 @@ import ( // } -// func getHistoryHandler(w http.ResponseWriter, r *http.Request) { +func getHistoryHandler(w http.ResponseWriter, r *http.Request) { -// // queryValues := r.URL.Query() -// // username := queryValues.Get("username") + queryValues := r.URL.Query() + username := queryValues.Get("username") -// // if username == "" { -// // http.Error(w, "username is required", http.StatusBadRequest) -// // return -// // } + if username == "" { + http.Error(w, "username is required", http.StatusBadRequest) + return + } -// username := "kou7306" + // username := "kou7306" -// _, dailyCommits, maxCommits, err := funcs.GetCommitHistory(username) -// if err != nil { -// http.Error(w, err.Error(), http.StatusInternalServerError) -// return -// } + _, dailyCommits, maxCommits, err := funcs.GetCommitHistory(username) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } -// err = graphs.DrawCommitChart(dailyCommits, maxCommits, 1000, 700) -// if err != nil { -// fmt.Println(err) -// } -// http.ServeFile(w, r, "./images/commits_history.png") -// } + err = graphs.DrawCommitChart(dailyCommits, maxCommits, 1000, 700) + if err != nil { + fmt.Println(err) + } + http.ServeFile(w, r, "./images/commits_history.png") +} // func getuserHandler(w http.ResponseWriter, r *http.Request) { @@ -171,7 +171,7 @@ func main() { // http.HandleFunc("/streak", getCommitStreakHandler) // http.HandleFunc("/language", getLanguageHandler) // http.HandleFunc("/character", getCharacterHandler) - // http.HandleFunc("/history", getHistoryHandler) + http.HandleFunc("/history", getHistoryHandler) // http.HandleFunc("/user", getuserHandler) // http.HandleFunc("/merge", mergeAllContents) // http.HandleFunc("/background", getBackgroundHandler)