This commit is contained in:
ponzischeme89
2026-08-22 12:38:26 +12:00
parent f982d391b9
commit b3e3f62c54
26 changed files with 1279 additions and 108 deletions
+44 -3
View File
@@ -159,6 +159,7 @@ type heroCandidate struct {
// when none did, which is a different thing from a score of zero.
Rating float64
Rated bool
Source string
}
// heroRecency decays linearly across the window.
@@ -189,6 +190,16 @@ func heroScore(candidate heroCandidate, now time.Time) float64 {
return score
}
func heroSource(candidate heroCandidate) string {
if candidate.Source != "" {
return candidate.Source
}
if candidate.Kind == heroSeriesPremiere || candidate.Kind == heroSeasonPremiere {
return "continue_world"
}
return "recommended_for_user"
}
// rankHeroCandidates orders the hero and is the whole of the feature that can be reasoned
// about without a network.
//
@@ -340,6 +351,22 @@ func heroLabel(candidate heroCandidate, now time.Time) string {
// be empty, and is empty precisely when there is nothing true to say — a card with no
// evidence behind it says nothing rather than inventing a reason.
func heroReason(candidate heroCandidate, now time.Time, location *time.Location) string {
if location == nil {
location = time.UTC
}
local := now.In(location)
if candidate.Source == "time_sensitive" {
return "Tonight's pick"
}
if candidate.Source == "continue_world" && local.Hour() >= 20 {
return "You normally watch an episode around now"
}
if candidate.Source == "favourite_genre" && local.Weekday() == time.Sunday && local.Hour() < 18 {
return "Something easy for Sunday"
}
if candidate.Source == "trending" {
return "Trending amongst Memby viewers"
}
acclaimed := candidate.Rated && candidate.Rating >= heroAcclaimedRating
fresh := heroRecency(candidate.ReleasedAt, now) > 0
switch {
@@ -857,7 +884,7 @@ func (s *Server) pinnedHeroCandidates(ctx context.Context, ids []string) []heroC
}
byID[fact.ID] = heroCandidate{
ID: fact.ID, Name: fact.Name, Kind: kind, Item: raw,
ReleasedAt: fact.Premiere, Rating: rating, Rated: rated,
ReleasedAt: fact.Premiere, Rating: rating, Rated: rated, Source: "admin_pinned",
}
}
out := make([]heroCandidate, 0, len(ids))
@@ -949,6 +976,20 @@ func heroMovieCandidates(rows []recommend.Row) ([]heroCandidate, map[string]hero
seen[fact.ID] = true
facts[fact.ID] = fact
rating, rated := heroRatingOf(raw)
source := "recommended_for_user"
rowText := strings.ToLower(row.Kind + " " + row.ID)
if strings.Contains(rowText, "favorite") {
source = "favourite_genre"
}
if strings.Contains(rowText, "trending") {
source = "trending"
}
if strings.Contains(rowText, "season") {
source = "seasonal"
}
if strings.Contains(rowText, "latest") {
source = "new_release"
}
candidates = append(candidates, heroCandidate{
ID: fact.ID,
Name: fact.Name,
@@ -956,7 +997,7 @@ func heroMovieCandidates(rows []recommend.Row) ([]heroCandidate, map[string]hero
Item: raw,
ReleasedAt: fact.Premiere,
Rating: rating,
Rated: rated,
Rated: rated, Source: source,
})
}
}
@@ -1139,7 +1180,7 @@ func (s *Server) heroPremiereCandidates(ctx context.Context, now time.Time) []he
Item: raw,
ReleasedAt: premiere.AiredAt,
Rating: rating,
Rated: rated,
Rated: rated, Source: "continue_world",
})
}
return candidates