Skip to content

Commit

Permalink
ランクと職業判定をし、画像に反映
Browse files Browse the repository at this point in the history
  • Loading branch information
kou7306 committed Feb 2, 2024
1 parent 9d3733b commit d809140
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 119 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
129 changes: 129 additions & 0 deletions src/funcs/handle_profession.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package funcs

// 職業を判定する関数
func JudgeProfession(rank string, topLanguages []string, percentages []float64) string {
// 職業のルートと言語を定義
magicRoute := map[string]string{
"TypeScript": "攻撃魔法", "R": "ネクロマンサー", "Flutter": "防御魔法",
"Go": "召喚士", "Scala": "精霊魔法", "Rust": "回復術師",
}
outlawRoute := map[string]string{
"Assembly": "賞金稼ぎ", "C": "無法者", "C++": "無法者",
"ObjectiveC": "盗賊", "Matlab": "盗賊",
}
warriorRoute := map[string]string{
"C#": "ファイター", "Swift": "弓使い", "Kotlin": "弓使い",
"Ruby": "槍使い", "PHP": "槍使い", "HTML": "剣士", "CSS": "剣士",
"JavaScript": "剣士", "Java": "騎士", "Python": "士官",
}

// ランクに応じた共通の職業を判定
switch rank {
case "C+":
return "冒険者見習い"
case "C":
return "少年"
case "C-":
return "赤ちゃん"
}

profession := "未定義の職業" // 初期値を設定

// ランクがC+以下の場合は、基本職業をそのまま使用
for _, language := range topLanguages {
if p, ok := magicRoute[language]; ok {
profession = p
break // 最初に見つかった職業を使用
} else if p, ok := outlawRoute[language]; ok {
profession = p
break // 最初に見つかった職業を使用
} else if p, ok := warriorRoute[language]; ok {
profession = p
break // 最初に見つかった職業を使用
}
}

// 混合職のロジックを実装
if rank == "A-" || rank == "A" || rank == "A+" {
if len(topLanguages) >= 2 && len(percentages) >= 2 {
firstProfession := ""
secondProfession := ""
for i, language := range topLanguages[:2] { // 上位2つの言語のみを考慮
if _, ok := magicRoute[language]; ok {
if i == 0 {
firstProfession = "魔法"
} else {
secondProfession = "魔法"
}
} else if _, ok := outlawRoute[language]; ok {
if i == 0 {
firstProfession = "アウトロー"
} else {
secondProfession = "アウトロー"
}
} else if _, ok := warriorRoute[language]; ok {
if i == 0 {
firstProfession = "戦士"
} else {
secondProfession = "戦士"
}
}
}

// 混合職種の判定ロジック
if firstProfession != secondProfession {
if firstProfession == "アウトロー" && secondProfession == "戦士" {
profession = "バーカーサ"
} else if firstProfession == "戦士" && secondProfession == "アウトロー" {
profession = "闇騎士"
} else if firstProfession == "魔法" && secondProfession == "アウトロー" {
profession = "黒魔術師"
} else if firstProfession == "アウトロー" && secondProfession == "魔法" {
profession = "ライダー"
} else if firstProfession == "戦士" && secondProfession == "魔法" {
profession = "魔法戦士"
} else if firstProfession == "魔法" && secondProfession == "戦士" {
profession = "魔法騎士"
}
}
}
}

return getFinalProfession(profession, rank) // 最終的な職業をランクに基づいて修正
}

func getFinalProfession(profession string, rank string) string {
finalProfession := ""
switch rank {
case "B-":
finalProfession = profession + "の見習い"
case "B":
finalProfession = "初級 " + profession
case "B+":
finalProfession = "中級 " + profession
case "A-":
finalProfession = "上級 " + profession
case "A":
finalProfession = "特級 " + profession
case "A+":
finalProfession = profession + "のラスボス"
case "S":
finalProfession = "神"
default:
finalProfession = profession // ランクが指定外の場合は基本職業をそのまま使用
}
return finalProfession
}

// func main() {
// fmt.Println(judgeProfession("C+", []string{"Go"}, []float64{100})) // 召喚士
// 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{"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})) // 賞金稼ぎのラスボス
// fmt.Println(judgeProfession("S", []string{"Python"}, []float64{100})) // 神
// }
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.
Loading

0 comments on commit d809140

Please sign in to comment.