Skip to content

Commit

Permalink
Merge pull request #34 from tomoish/error
Browse files Browse the repository at this point in the history
Error
  • Loading branch information
tomoish authored Feb 2, 2024
2 parents a2d0dd5 + 9b3f5d1 commit 1f239a0
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 121 deletions.
4 changes: 2 additions & 2 deletions src/funcs/create_character_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"math"
)

func CreateCharacterImg(characterPath, gaugePath string, contribution, level int) {
func CreateCharacterImg(characterPath, gaugePath string, total, level int) {
// ゲージ画像生成のためのチャネル
gaugeImageChan := make(chan []byte)
percentage := (float64(contribution) - float64(math.Pow(float64(level), 2))) / float64(math.Pow(float64(level+1), 2))
percentage := (float64(total) - float64(math.Pow(float64(level), 2))) / float64(math.Pow(float64(level+1), 2))

// ゲージ画像を非同期で生成
go func() {
Expand Down
7 changes: 4 additions & 3 deletions src/funcs/create_language_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/patrickmn/go-cache"
)

func CreateLanguageImg(username string) {
func CreateLanguageImg(username string) []LanguageStat {
// 言語ごとの色をここで決める
colordict := map[string]string{
"HTML": "#E34F26",
Expand Down Expand Up @@ -52,7 +52,7 @@ func CreateLanguageImg(username string) {
fmt.Printf("repos: %v\n", repos)
if err != nil {
fmt.Println(err)
return
return nil
}

// 言語ごとの全体のファイルサイズを初期化
Expand Down Expand Up @@ -106,9 +106,10 @@ func CreateLanguageImg(username string) {
err = SaveImage("./images/language.png", ImgBytes)
if err != nil {
fmt.Println(err)

}

// return languages
return languages

}

Expand Down
4 changes: 2 additions & 2 deletions src/funcs/draw_background.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func DrawBackground(username, level, kind string) {
dc.DrawStringAnchored(text1, float64(x1), float64(y1), 0.5, 0.5)

text2 := level
x2, y2 := (18*Width)/100, (25*Height)/100 // テキスト2の座標(テキストの中央に持つ)
x2, y2 := (13*Width)/100, (25*Height)/100 // テキスト2の座標(テキストの中央に持つ)
dc.DrawStringAnchored(text2, float64(x2), float64(y2), 0.5, 0.5)

if err := dc.LoadFontFace("NotoSansJP-ExtraLight.ttf", 50); err != nil {
if err := dc.LoadFontFace("NotoSansJP-ExtraLight.ttf", 30); err != nil {
fmt.Println("フォントのロードに失敗しました:", err)
}
text3 := kind
Expand Down
2 changes: 1 addition & 1 deletion src/funcs/draw_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GenerateLanguageUsageGraph(languages []LanguageStat, width, height int) ([]
dc := gg.NewContext(width, height)

// 背景とタイトルの描画
dc.SetRGB(0.2, 0.24, 0.31) // 背景色(暗い青灰色)
dc.SetRGB(0.2, 0.2, 0.2) // 背景色(暗い青灰色)
drawRoundedRectangle(dc, 0, 0, float64(width), float64(height), cornerRadius)
dc.SetRGB(1, 1, 1)
err := dc.LoadFontFace("Roboto-Medium.ttf", 45) // フォントとサイズの設定が必要
Expand Down
3 changes: 2 additions & 1 deletion src/funcs/get_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type response struct {
}
}

func FetchDataInTimeRange(token string, username string) (int, int, int, int, int, error) {
func FetchData(username string) (int, int, int, int, int, error) {
token, _ := GetTokens(0)
const query_frame = `
{
user(login: "%s") {
Expand Down
4 changes: 2 additions & 2 deletions src/funcs/handle_profession.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func getFinalProfession(profession string, rank string) string {

// func main() {
// fmt.Println(judgeProfession("C+", []string{"Go"}, []float64{100})) // 召喚士
// fmt.Println(judgeProfession("A", []string{"Python", "Java"}, []float64{20, 20})) // 特級 士官と騎士
// fmt.Println(judgeProfession("A", []string{"Python", "C"}, []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("B+", []string{"HTML"}, []float64{20})) // 中級 騎士
// fmt.Println(judgeProfession("A-", []string{"Rust"}, []float64{100})) // 上級 回復術師
// fmt.Println(judgeProfession("A", []string{"Go"}, []float64{100})) // 特級 召喚士
// fmt.Println(judgeProfession("A+", []string{"Assembly"}, []float64{100})) // 賞金稼ぎのラスボス
Expand Down
163 changes: 87 additions & 76 deletions src/funcs/judge_rank.go
Original file line number Diff line number Diff line change
@@ -1,91 +1,102 @@
package funcs

// import (
// "fmt"
import (
// 他の import ステートメント
"math"
"sort"
)

// )
func JudgeRank(languages []LanguageStat, stats UserStats) (string, int) {
// データを取得

// func JudgeRank()[
// // データを取得
// totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := fetchDataInTimeRange(token, username)
// rank := "C-"
total := stats.TotalStars + stats.ContributedTo + stats.TotalIssues + stats.TotalPRs + stats.TotalCommits

// switch {
// case rank < 25:
// rank="C-"
// case rank < 100:
// rank="C"
// case rank < 400:
// rank="C+"
// case rank < 625:
// rank="B-"
// case rank < 1225:
// rank="B"
// case rank < 2500:
// rank="B+"
// case rank < 4900:
// rank="A-"
// case rank < 8100:
// rank="A"
// case rank < 10000:
// rank="A+"
// case 10000 <= rank:
// rank="S"
// default:
// rank="C-"
level := int(math.Sqrt(float64(total)))

// }
rank := ""

// // 言語ごとの割合を持ってくる
// languages, err := funcs.CreateLanguageImg(username, token)
switch {
case total < 25:
rank = "C-"
case total < 100:
rank = "C"
case total < 400:
rank = "C+"
case total < 625:
rank = "B-"
case total < 1225:
rank = "B"
case total < 2500:
rank = "B+"
case total < 4900:
rank = "A-"
case total < 8100:
rank = "A"
case total < 10000:
rank = "A+"
case 10000 <= total:
rank = "S"
default:
rank = "C-"

// // Percent の大きい順にソート
// sort.Slice(languages, func(i, j int) bool {
// return languages[i].Percent > languages[j].Percent
// })
}

// //上位2つの言語を保持
// topLanguage := []funcs.LanguageStat{}
// // 一時的に保持する
// temp := []funcs.LanguageStat{}
// Percent の大きい順にソート
sort.Slice(languages, func(i, j int) bool {
return languages[i].Percent > languages[j].Percent
})

// // ソートされた languages を使用する
// // 一位がHTML,CSS,JavaScript,TypeScriptじゃない場合
// if languages[0].Name != "HTML" && languages[0].Name != "CSS" && languages[0].Name != "JavaScript" && languages[0].Name != "TypeScript"{
// topLanguage = append(topLanguage, languages[0])
//上位2つの言語を保持
topLanguage := []string{}
// パーセントを保持
percentages := []float64{}
// 一時的に保持する
temp := []LanguageStat{}

// } else {
// temp = append(temp, languages[0])
// }
// ソートされた languages を使用する
// 一位がHTML,CSS,JavaScript,TypeScriptじゃない場合
if languages[0].Name != "HTML" && languages[0].Name != "CSS" && languages[0].Name != "JavaScript" && languages[0].Name != "TypeScript" {
topLanguage = append(topLanguage, languages[0].Name)
percentages = append(percentages, languages[0].Percent)

// if topLanguage != [] {
// topLanguage = append(topLanguage, languages[1])
// }
// else{
// if languages[1].Name != "HTML" && languages[1].Name != "CSS" && languages[1].Name != "JavaScript" && languages[1].Name != "TypeScript"{
// topLanguage = append(topLanguage, languages[1])
// topLanguage = append(topLanguage, temp[0])
// }
} else {
temp = append(temp, languages[0])
}

// // 上位2つの言語がHTML,CSS,JavaScript,TypeScriptの場合
// else{
// temp = append(temp, languages[1])
// // HTML,CSS,JavaScript,TypeScriptじゃない中の一位の言語を探す
// for i, language := range languages[2:] {
// if language.Name != "HTML" && language.Name != "CSS" && language.Name != "JavaScript" && language.Name != "TypeScript"{
// if language.Percent >= 15.0{
// topLanguage = append(topLanguage, language)
// topLanguage = append(topLanguage, temp[0])
// }
// else{
// topLanguage = append(topLanguage, temp[0])
// topLanguage = append(topLanguage, temp[1])
// }
if len(topLanguage) != 0 {
topLanguage = append(topLanguage, languages[1].Name)
percentages = append(percentages, languages[1].Percent)
} else {

// }
// }
// }
// }
if languages[1].Name != "HTML" && languages[1].Name != "CSS" && languages[1].Name != "JavaScript" && languages[1].Name != "TypeScript" {
topLanguage = append(topLanguage, languages[1].Name)
percentages = append(percentages, languages[1].Percent)
topLanguage = append(topLanguage, temp[0].Name)
percentages = append(percentages, temp[0].Percent)
topLanguage = append(topLanguage, temp[0].Name)
percentages = append(percentages, temp[0].Percent)
} else {
// 上位2つの言語がHTML,CSS,JavaScript,TypeScriptの場合

// return rank
// ]
temp = append(temp, languages[1])
// HTML,CSS,JavaScript,TypeScriptじゃない中の一位の言語を探す
for _, language := range languages[2:] {
if language.Name != "HTML" && language.Name != "CSS" && language.Name != "JavaScript" && language.Name != "TypeScript" {
if language.Percent >= 15.0 {
topLanguage = append(topLanguage, language.Name)
percentages = append(percentages, language.Percent)
topLanguage = append(topLanguage, temp[0].Name)
percentages = append(percentages, temp[0].Percent)
} else {
topLanguage = append(topLanguage, temp[0].Name)
topLanguage = append(topLanguage, temp[1].Name)
percentages = append(percentages, temp[0].Percent)
percentages = append(percentages, temp[1].Percent)
}
}
}
}
}

return JudgeProfession(rank, topLanguage, percentages), level
}
Binary file added src/funcs/result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/graphs/commit_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func DrawCommitChart(commitsHistory []int, maxCommits int, width int, height int

p := plot.New()

bgColor := color.RGBA{R: 51, G: 61, B: 79, A: 255}
bgColor := color.RGBA{R: 51, G: 51, B: 51, A: 255}
p.BackgroundColor = bgColor

points := make(plotter.XYs, len(x))
Expand Down Expand Up @@ -59,8 +59,8 @@ func DrawCommitChart(commitsHistory []int, maxCommits int, width int, height int

// ラベルの外に余白を持つ
p.Title.Padding = 10 // タイトル周りの余白

Check failure on line 61 in src/graphs/commit_chart.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
p.X.Label.Padding = 10 // X軸ラベル周りの余白
p.Y.Label.Padding = 10 // Y軸ラベル周りの余白
p.X.Label.Padding = 2 // X軸ラベル周りの余白
p.Y.Label.Padding = 2 // Y軸ラベル周りの余白

// DefaultTextHandler is the default text handler used for text processing.

Expand All @@ -77,7 +77,7 @@ func DrawCommitChart(commitsHistory []int, maxCommits int, width int, height int

p.X.Padding, p.Y.Padding = 0, 0

if err := p.Save(8*vg.Inch, 4*vg.Inch, "./images/commits_history.png"); err != nil {
if err := p.Save(5*vg.Inch, 2*vg.Inch, "./images/commits_history.png"); err != nil {
panic(err)
}

Expand Down
Binary file modified src/images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/commits_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/gauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/generate_character.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/language.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 45 additions & 30 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

Check failure on line 4 in src/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"log"
"net/http"

"strconv"

Check failure on line 7 in src/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/tomoish/readme (goimports)
"github.com/tomoish/readme/funcs"
"github.com/tomoish/readme/graphs"
)
Expand Down Expand Up @@ -117,37 +117,52 @@ import (
func createhandler(w http.ResponseWriter, r *http.Request) {
queryValues := r.URL.Query()
username := queryValues.Get("username")
// stats取得と画像生成
stats := funcs.CreateUserStats(username)

//レベル、職業判定

// 背景画像の生成
funcs.DrawBackground(username, "Lv.30", "神")

// キャラクター画像の生成
funcs.CreateCharacterImg("images/character.png", "images/gauge.png", stats.TotalCommits, 30)

// 言語画像の生成
funcs.CreateLanguageImg(username)

// コミットカレンダー画像の生成

_, 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)
if r.Method == http.MethodGet {
// GETリクエストの処理

// stats取得と画像生成
stats := funcs.CreateUserStats(username)
total := stats.TotalStars + stats.ContributedTo + stats.TotalIssues + stats.TotalPRs + stats.TotalCommits
// 言語画像の生成
language := funcs.CreateLanguageImg(username)
//レベル、職業判定
profession, level := funcs.JudgeRank(language, stats)

// 背景画像の生成
funcs.DrawBackground(username, "Lv."+strconv.Itoa(level), profession)

// キャラクター画像の生成
funcs.CreateCharacterImg("characterimages/s.png", "images/gauge.png", total, level)

// コミットカレンダー画像の生成

_, 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)
}

// 全て合体
funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png")

http.ServeFile(w, r, "./result.png")
// } else if r.Method == http.MethodPost {
// // POSTリクエストの処理
// totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := funcs.FetchData(username)
// if err != nil {
// fmt.Println(err)
// return
// }

} else {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}

// 全て合体
funcs.Merge_all("./images/background.png", "./images/stats.png", "./images/generate_character.png", "./images/language.png", "./images/commits_history.png")

http.ServeFile(w, r, "./result.png")
}

func main() {
Expand Down
Binary file modified src/result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f239a0

Please sign in to comment.