Server changes/Sonarr
This commit is contained in:
@@ -193,8 +193,39 @@ func (p Profile) Score(candidate Item) float64 {
|
||||
return genreScore + studioScore + ratingScore
|
||||
}
|
||||
|
||||
// CollectionAffinity decides which curated shelf appears first for this user.
|
||||
func (p Profile) CollectionAffinity(genres, studios []string) float64 {
|
||||
var score float64
|
||||
for _, genre := range genres {
|
||||
score += weightFold(p.GenreWeights, genre)
|
||||
}
|
||||
for _, studio := range studios {
|
||||
score += weightFold(p.StudioWeights, studio)
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
func weightFold(weights map[string]float64, wanted string) float64 {
|
||||
for key, value := range weights {
|
||||
if strings.EqualFold(strings.TrimSpace(key), strings.TrimSpace(wanted)) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Rank scores, filters and truncates candidates, dropping duplicates by id.
|
||||
func Rank(profile Profile, candidates []Item, limit int) []Item {
|
||||
return rank(profile, candidates, limit, false)
|
||||
}
|
||||
|
||||
// RankCollection keeps unseen candidates with no affinity/rating score at the end,
|
||||
// ensuring a curated shelf remains useful for a new profile or unrated library.
|
||||
func RankCollection(profile Profile, candidates []Item, limit int) []Item {
|
||||
return rank(profile, candidates, limit, true)
|
||||
}
|
||||
|
||||
func rank(profile Profile, candidates []Item, limit int, includeZero bool) []Item {
|
||||
type scored struct {
|
||||
item Item
|
||||
score float64
|
||||
@@ -207,7 +238,7 @@ func Rank(profile Profile, candidates []Item, limit int) []Item {
|
||||
continue
|
||||
}
|
||||
seen[candidate.ID] = true
|
||||
if score := profile.Score(candidate); score > 0 {
|
||||
if score := profile.Score(candidate); score > 0 || includeZero && score == 0 {
|
||||
ranked = append(ranked, scored{candidate, score})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user