Help us shape the future of Go! Take the 2026 Go Developer Survey

popularity

package
v0.130.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package popularity ranks works by their event-time eligible-population participation over immutable access intervals, weighted by bounded quality (docs/popularity-policy.md):

rank = rate + we·engage + wf·finish + wa·approve + wr·revisit

where every term is the duration-weighted mean over a work's intervals of its smoothed participation rate times the interval's smoothed quality term.

Index

Constants

View Source
const DefaultPeriod = "30d"

DefaultPeriod is the window a listing gets when it names none.

Variables

View Source
var Periods = []string{"7d", "30d", "90d", "365d", "all"}

Periods are the only public popularity windows: literal whole-UTC-day windows with equal weight inside, "all" unbounded.

View Source
var PolicyV2 = Policy{
	Weights: Weights{Engagement: 0.35, Completion: 0.25, Approval: 0.40, Revisit: 0.10},
	Priors: Priors{
		Engagement: 0.40, EngagementWeight: 10,
		Completion: 0.30, CompletionWeight: 10,
		Approval: 0.75, ApprovalWeight: 5,
		RevisitWeight: 10,
	},
}

PolicyV2 normalizes each historical access interval by its active eligible population. Its twenty pseudo-eligible nonreaders are a modest reliability heuristic, not a statistical confidence interval.

Functions

func Rank added in v0.128.6

func Rank(ctx context.Context, source Source, availability AvailabilityProvider, kind string, window signal.Window, scope signal.ActivityScope, limit int) ([]string, error)

Rank returns up to limit works of kind with qualified readers in window, best first. Without trusted audience history it returns none: missing lineage never becomes unnormalized reach.

func WindowForPeriod

func WindowForPeriod(period string, now time.Time) (signal.Window, error)

WindowForPeriod maps a public period onto the window ending on now's UTC day. Anything else is an error, never a silent default.

Types

type AvailabilityProvider added in v0.98.0

type AvailabilityProvider interface {
	Availability(ctx context.Context, kind string, window signal.Window, scope signal.ActivityScope, contents []string) (signal.Availability, error)
}

AvailabilityProvider supplies immutable publication and access history for a common covered portion of a requested activity window, for the given contents of the kind.

type Policy

type Policy struct {
	Weights Weights
	Priors  Priors
}

Policy is the ranking's weights and priors.

func (Policy) RankExpr

func (p Policy) RankExpr() string

RankExpr renders the policy as a ClickHouse expression over the normalized metric columns for signal.PopularOptions.RankExpr. Parameters are rendered as literals; nothing user-controlled reaches it.

type Priors

type Priors struct {
	Engagement       float64
	EngagementWeight float64
	Completion       float64
	CompletionWeight float64
	Approval         float64
	ApprovalWeight   float64
	RevisitWeight    float64
}

Priors smooth each term with pseudo-observations: a prior mean in [0, 1] and its weight (>= 1) in pseudo-readers or pseudo-votes.

type Source

type Source interface {
	Popular(ctx context.Context, contentKind string, opts signal.PopularOptions) ([]signal.PopularHit, error)
	// ReadContent lists the works of kind read in window.
	ReadContent(ctx context.Context, kind string, window signal.Window) ([]string, error)
	// PopulationCoverage is when trusted audience observations start for scope.
	PopulationCoverage(ctx context.Context, kind string, scope signal.ActivityScope, window signal.Window) (time.Time, bool, error)
}

Source is one tenant's signal plane; the engine's hub satisfies it.

type Weights

type Weights struct {
	Engagement float64
	Completion float64
	Approval   float64
	Revisit    float64
}

Weights are the quality term weights, each in [0, 1].

Jump to

Keyboard shortcuts

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