recommend

package
v2.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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.

View Source
const (

	// DefaultMaxResults and DefaultMaxSections apply when a request names
	// neither.
	DefaultMaxResults  = 12
	DefaultMaxSections = 6
)
View Source
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.

View Source
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

type Pick struct {
	SystemID  string
	Reasons   []Reason
	TitleDBID int64
	Score     float64
	Rating    int
}

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.

func BuildPlan

func BuildPlan(ctx context.Context, deps *Deps, profileID string, now time.Time, opts Options) (*Plan, error)

BuildPlan gathers the profile's signals and turns them into sections. With no signals there is nothing to recommend from, and the plan is empty.

type PlanCache

type PlanCache struct {
	// contains filtered or unexported fields
}

PlanCache holds recently built plans, most recently used first.

func NewPlanCache

func NewPlanCache() *PlanCache

NewPlanCache returns an empty cache.

func (*PlanCache) Get

func (c *PlanCache) Get(key *PlanKey, now time.Time) (*Plan, bool)

Get returns the plan built for key, if one is held and still fresh.

func (*PlanCache) Put

func (c *PlanCache) Put(key *PlanKey, plan *Plan, now time.Time)

Put stores the plan built for key, dropping the least recently used plan when the cache is full.

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 Reason

type Reason struct {
	Code string
	Tags []database.TagInfo
}

Reason is one thing a pick shares with the title it was picked for.

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.

type UserStore

type UserStore interface {
	GetMediaPlayTotals(
		ctx context.Context, profileID string, since time.Time, minSessionSecs, limit int,
	) ([]database.MediaPlayTotal, error)
	ListDecks() ([]database.Deck, error)
}

UserStore is the part of the user database recommendations read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL