Added anime popularity

This commit is contained in:
2017-09-30 16:04:13 +02:00
parent 3caad5cb0d
commit 831c6118d9
6 changed files with 99 additions and 7 deletions

View File

@ -7,7 +7,12 @@ import (
"github.com/fatih/color"
)
const currentlyAiringBonus = 4.0
const (
currentlyAiringBonus = 4.0
popularityThreshold = 5
popularityPenalty = 4.0
watchingPopularityWeight = 0.1
)
func main() {
color.Yellow("Caching airing anime")
@ -21,17 +26,30 @@ func main() {
}
sort.Slice(animeList, func(i, j int) bool {
scoreA := animeList[i].Rating.Overall
scoreB := animeList[j].Rating.Overall
a := animeList[i]
b := animeList[j]
scoreA := a.Rating.Overall
scoreB := b.Rating.Overall
if animeList[i].Status == "current" {
if a.Status == "current" {
scoreA += currentlyAiringBonus
}
if animeList[j].Status == "current" {
if b.Status == "current" {
scoreB += currentlyAiringBonus
}
if a.Popularity.Total() < popularityThreshold {
scoreA -= popularityPenalty
}
if b.Popularity.Total() < popularityThreshold {
scoreB -= popularityPenalty
}
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
return scoreA > scoreB
})