56 lines
1.2 KiB
Go
Raw Normal View History

2017-07-01 01:16:25 +02:00
package explore
2017-06-20 22:54:45 +02:00
import (
2017-10-28 03:53:12 +02:00
"sort"
2017-06-20 22:54:45 +02:00
"github.com/aerogo/aero"
2017-10-28 03:53:12 +02:00
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
const (
currentlyAiringBonus = 5.0
popularityThreshold = 5
popularityPenalty = 8.0
watchingPopularityWeight = 0.3
plannedPopularityWeight = 0.2
2017-06-20 22:54:45 +02:00
)
2017-07-01 02:14:14 +02:00
// Get ...
2017-06-20 22:54:45 +02:00
func Get(ctx *aero.Context) string {
2017-10-28 03:53:12 +02:00
animeList := arn.GetAiringAnime()
sort.Slice(animeList, func(i, j int) bool {
a := animeList[i]
b := animeList[j]
scoreA := a.Rating.Overall
scoreB := b.Rating.Overall
if a.Status == "current" {
scoreA += currentlyAiringBonus
}
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
2017-07-01 02:14:14 +02:00
2017-10-28 03:53:12 +02:00
scoreA += float64(a.Popularity.Planned) * plannedPopularityWeight
scoreB += float64(b.Popularity.Planned) * plannedPopularityWeight
2017-06-23 19:12:05 -03:00
2017-10-28 03:53:12 +02:00
return scoreA > scoreB
})
2017-06-23 19:12:05 -03:00
2017-10-28 03:53:12 +02:00
return ctx.HTML(components.Explore(animeList))
2017-06-20 22:54:45 +02:00
}