2018-04-26 18:31:15 +00:00
|
|
|
package recommended
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-04-26 18:31:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getAnimeAffinity(anime *arn.Anime, animeListItem *arn.AnimeListItem, completed *arn.AnimeList, bestGenres []string) float64 {
|
|
|
|
animeAffinity := anime.Score()
|
|
|
|
|
|
|
|
// Planned anime go higher
|
|
|
|
if animeListItem != nil && animeListItem.Status == arn.AnimeListStatusPlanned {
|
|
|
|
animeAffinity += 10.0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anime whose high-ranked prequel you did not see are lower ranked
|
|
|
|
prequels := anime.Prequels()
|
|
|
|
|
|
|
|
for _, prequel := range prequels {
|
|
|
|
item := completed.Find(prequel.ID)
|
|
|
|
|
|
|
|
// Filter out unimportant prequels
|
|
|
|
if prequel.Score() < anime.Score()/2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if item == nil {
|
|
|
|
animeAffinity -= 20.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give favorite genre bonus if we have enough completed anime
|
|
|
|
if len(completed.Items) >= genreBonusCompletedAnimeThreshold {
|
|
|
|
bestGenreCount := 0
|
|
|
|
|
|
|
|
for _, genre := range anime.Genres {
|
|
|
|
if arn.Contains(bestGenres, genre) {
|
|
|
|
bestGenreCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use square root to dampen the bonus of additional best genres
|
|
|
|
animeAffinity += math.Sqrt(float64(bestGenreCount)) * 7.0
|
|
|
|
}
|
|
|
|
|
|
|
|
return animeAffinity
|
|
|
|
}
|