Added age penalty to explore
This commit is contained in:
parent
757ee6f86e
commit
43585b2333
@ -2,6 +2,7 @@ package explore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -15,6 +16,8 @@ const (
|
|||||||
watchingPopularityWeight = 0.3
|
watchingPopularityWeight = 0.3
|
||||||
completedPopularityWeight = 0.3
|
completedPopularityWeight = 0.3
|
||||||
plannedPopularityWeight = 0.2
|
plannedPopularityWeight = 0.2
|
||||||
|
agePenalty = 11.0
|
||||||
|
ageThreshold = 6 * 30 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get ...
|
// Get ...
|
||||||
@ -61,11 +64,11 @@ func filterAnime(year, status, typ string) []*arn.Anime {
|
|||||||
results = append(results, anime)
|
results = append(results, anime)
|
||||||
}
|
}
|
||||||
|
|
||||||
sortAnime(results)
|
sortAnime(results, status)
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortAnime(animeList []*arn.Anime) {
|
func sortAnime(animeList []*arn.Anime, filterStatus string) {
|
||||||
sort.Slice(animeList, func(i, j int) bool {
|
sort.Slice(animeList, func(i, j int) bool {
|
||||||
a := animeList[i]
|
a := animeList[i]
|
||||||
b := animeList[j]
|
b := animeList[j]
|
||||||
@ -89,6 +92,17 @@ func sortAnime(animeList []*arn.Anime) {
|
|||||||
scoreB -= popularityPenalty
|
scoreB -= popularityPenalty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we show current shows, rank old shows a bit lower
|
||||||
|
if filterStatus == "current" {
|
||||||
|
if a.StartDate != "" && time.Since(a.StartDateTime()) > ageThreshold {
|
||||||
|
scoreA -= agePenalty
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.StartDate != "" && time.Since(b.StartDateTime()) > ageThreshold {
|
||||||
|
scoreB -= agePenalty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
|
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
|
||||||
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
|
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user