lens

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package lens applies transparent, reusable filters and weighted signals to local corpus candidates. It does not fetch or infer signal values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(def Definition) error

Validate checks whether a lens definition can be stored and applied.

Types

type Candidate

type Candidate struct {
	ID         string
	Repository string
	Kind       string
	State      string
	Language   string
	Archived   bool
	Assigned   bool
	Stars      int
	UpdatedAt  time.Time
	Signals    map[string]float64
}

Candidate is a locally derived item and its named, unnormalized signals.

type Definition

type Definition struct {
	Name              string             `json:"name"`
	Filter            Filter             `json:"filter"`
	Weights           map[string]float64 `json:"weights"`
	MaxResultsPerRepo int                `json:"max_results_per_repo"`
}

Definition is a reusable ranking policy. Negative weights express costs or risks; positive weights express desirable signals.

func (*Definition) UnmarshalJSON

func (d *Definition) UnmarshalJSON(data []byte) error

UnmarshalJSON supports JSON lens definitions where updated_within may be expressed as a Go duration string (e.g. "720h") or as nanoseconds.

type Filter

type Filter struct {
	Kinds           []string      `json:"kinds,omitempty"`
	States          []string      `json:"states,omitempty"`
	Languages       []string      `json:"languages,omitempty"`
	ExcludeArchived bool          `json:"exclude_archived,omitempty"`
	Unassigned      bool          `json:"unassigned,omitempty"`
	UpdatedWithin   time.Duration `json:"updated_within,omitempty"`
	MinStars        int           `json:"min_stars,omitempty"`
}

Filter contains hard eligibility rules evaluated before normalization.

func (Filter) MarshalJSON

func (f Filter) MarshalJSON() ([]byte, error)

MarshalJSON emits updated_within as a Go duration string so JSON lens definitions round-trip with the same format used for input.

func (*Filter) UnmarshalJSON

func (f *Filter) UnmarshalJSON(data []byte) error

UnmarshalJSON supports duration strings for updated_within.

type Result

type Result struct {
	Candidate     Candidate
	Score         float64
	Normalized    map[string]float64
	Contributions map[string]float64
}

Result explains both the normalized values and each weighted contribution.

func Rank

func Rank(def Definition, candidates []Candidate, now time.Time) ([]Result, error)

Rank filters candidates, min-max normalizes each configured signal within the eligible population, and returns a stable descending ranking. A signal with no population variance contributes zero. Missing values also contribute zero and remain absent from Normalized, making incomplete evidence visible.

Jump to

Keyboard shortcuts

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