Documentation
¶
Overview ¶
Package recommend finds media like other media from what the library's scraped tags say about each title, and builds a personal list from the titles a profile has shown interest in. Everything is computed on demand from the local index: nothing is precomputed and nothing leaves the device.
Index ¶
Constants ¶
const ( ReasonSeries = "series" ReasonGenre = "genre" ReasonPerspective = "perspective" ReasonArt = "art" ReasonBased = "based" ReasonDeveloper = "developer" ReasonPlayers = "players" ReasonYear = "year" ReasonDecade = "decade" ReasonPublisher = "publisher" )
Reason codes name the kind of thing two titles share. Clients turn them into their own wording.
const ( SectionSeed = "seed" SectionPlayLater = "playLater" SectionSeries = "series" // SectionQueue is the one section of a queue plan: every pick, best // first, whatever it was picked for. SectionQueue = "queue" )
Section kinds say what a section of recommendations is built around.
const ( // DefaultMaxResults and DefaultMaxSections apply when a request names // neither. DefaultMaxResults = 12 DefaultMaxSections = 6 )
const ( SignalPlayed = "played" SignalFavorite = "favorite" SignalLiked = "liked" SignalDeck = "deck" // SignalPlayLater marks a queue item the profile marked to play later. SignalPlayLater = "playLater" )
Signal names say which sign of interest made a title a seed.
const ( // MinSessionSecs is the shortest session that counts as play. Anything // shorter is a launch that was closed again. MinSessionSecs = 60 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
MediaDB MediaStore
UserDB UserStore
// ResolvePlays maps each play total, by its index, to the title its
// path belongs to. Totals whose media is no longer indexed are absent.
ResolvePlays func(ctx context.Context, plays []database.MediaPlayTotal) (map[int]int64, error)
}
Deps is what gathering signals and building a plan read from.
type GameSignal ¶
type GameSignal struct {
LastPlayed time.Time
// TitleDBID is the title that stands for the game: the version with the
// most play, or failing that a flagged one.
TitleDBID int64
Group int64
PlaySecs int64
Favorite bool
Liked bool
Disliked bool
Hidden bool
PlayLater bool
OwnedDeck bool
}
GameSignal is the interest shown in one game: every version of it added up.
func (*GameSignal) Affinity ¶
func (g *GameSignal) Affinity(now time.Time) (affinity float64, signal string)
Affinity is how strongly the profile is drawn to the game, from 0 to 1, and the sign of interest that says so. The strongest sign decides: a favorite barely played is still a favorite. A disliked game has none, and neither does one with a hidden version: hiding it says not to bring it up.
type MediaStore ¶
type MediaStore interface {
GetTitleFacetTags(ctx context.Context, titleDBIDs []int64, tagTypes []string) ([]database.TitleFacetTag, error)
CountTitlesByTag(ctx context.Context, tagDBIDs []int64, limit int) (map[int64]int, error)
FindTitlesSharingTags(
ctx context.Context, weighted []database.WeightedTag, excludeTitleDBIDs []int64,
systemIDs []string, limit int,
) ([]database.TagSharingTitle, error)
GetUserTagMedia(ctx context.Context) ([]database.UserTagMedia, error)
MediaTitleCountEstimate(ctx context.Context) (int64, error)
GetTitleVersionGroups(ctx context.Context, titleDBIDs []int64) (map[int64]int64, error)
GetVersionGroupMembers(ctx context.Context, titleDBIDs []int64) (map[int64][]int64, error)
}
MediaStore is the part of the media index recommendations read.
type Options ¶
type Options struct {
// Systems limits picks to these systems. Nil allows every system.
Systems map[string]struct{}
MaxResults int
MaxSections int
// Queue lays the plan out as one ranked list instead of sections.
Queue bool
}
Options shapes a plan.
type Pick ¶
Pick is a title found to be like another, with why.
func Similar ¶
func Similar( ctx context.Context, mediaDB MediaStore, titleDBID int64, opts SimilarOptions, ) ([]Pick, error)
Similar returns the titles most like the given one, best first. A title is never like another version of itself or the same game on another system, and each game is picked once however many versions and ports of it the library holds. A title the scrapers know nothing about has nothing to compare, so it has no picks.
type Plan ¶
type Plan struct {
Sections []PlanSection
}
Plan is a profile's recommendations before the media rows are read: which titles, in which sections, and why.
type PlanCache ¶
type PlanCache struct {
// contains filtered or unexported fields
}
PlanCache holds recently built plans, most recently used first.
type PlanItem ¶
type PlanItem struct {
// Signal says why a queue item was picked: the signal of the seed it is
// like, or SignalPlayLater for a game the profile marked.
Signal string
Reasons []Reason
// SeedTitleDBID is the seed a queue item is most like.
SeedTitleDBID int64
TitleDBID int64
}
PlanItem is one recommended title and why it was picked. Reasons is empty for an item that is in a section for what it is, not for what it shares.
type PlanKey ¶
type PlanKey struct {
ProfileID string
PreferencesRev string
HistoryVersion string
Day string
Systems string
IndexGeneration int64
MaxResults int
MaxSections int
Queue bool
}
PlanKey names everything a plan was built from. Two requests share a plan only when every part matches, so a different profile, a changed flag, a new play session or a reindex each build their own.
type PlanSection ¶
type PlanSection struct {
// Tag is the series a series section is about.
Tag *database.TagInfo
Kind string
// Signal is the sign of interest that made a seed section's seed.
Signal string
Items []PlanItem
// SeedTitleDBID is the title a seed section is built around.
SeedTitleDBID int64
}
PlanSection is one group of recommendations.
func (*PlanSection) MinItems ¶
func (s *PlanSection) MinItems() int
MinItems is the fewest items the section is worth showing with.
type Signals ¶
type Signals struct {
ByGroup map[int64]*GameSignal
}
Signals is the interest a profile has shown, keyed by version group.
func GatherSignals ¶
func GatherSignals(ctx context.Context, deps *Deps, profileID string, now time.Time) (*Signals, error)
GatherSignals collects every sign of interest for one profile: its play history, the flags on the library, and the decks made on this device. An empty profileID is the shared profile, whose play is what was played with no profile active. Flags and decks are read from the library's own copy of them, so they follow whatever that copy holds.
type SimilarOptions ¶
type SimilarOptions struct {
// Systems limits picks to these systems. Nil allows every system.
Systems map[string]struct{}
Limit int
}
SimilarOptions narrows a Similar lookup.