Comment blocks in cmd/minstrel and 30 smaller internal packages, rewritten
to rule 32's standard with each citation read in context: task, milestone
and rule ids go, and so do the stories they were attached to ("used to",
"Before #N", measurements from one install, quotes, pointers to Fabled
Librarian's records and to docs/superpowers files that are not in the
repo). Where a story wrapped a real constraint, the constraint stays as a
present-tense fact.
Comments that had gone stale are corrected:
- taste.Config: the tuned values are overlaid by internal/recsettings;
it is no longer "a later follow-up".
- StorageConfig: the data dir holds art, caches and the stream secret,
not only playlist covers.
- the Subsonic album list and getUser comments describe what they do
today rather than a milestone that would change it.
Checked: the non-comment token stream of every changed file matches
HEAD, and gofmt -l is empty.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
// Package taste builds a persistent, decaying per-user taste profile.
|
|
// engagement.go is the pure core: it turns a single play's completion ratio
|
|
// into a graded taste signal in [-1, +1], replacing the binary was_skipped
|
|
// for learning purposes (was_skipped stays as-is for History display).
|
|
package taste
|
|
|
|
import "math"
|
|
|
|
// EngagementParams tune the completion→engagement curve. All in [0,1] and
|
|
// ordered HardSkip < NeutralCompletion < FullCompletion.
|
|
type EngagementParams struct {
|
|
// HardSkip: completion at/below which a play is a strong reject (-1).
|
|
HardSkip float64
|
|
// NeutralCompletion: completion at which a play is neutral (0). Set low
|
|
// (~0.30) because people enjoy plenty of tracks they don't finish; only
|
|
// genuinely-early abandons read as negative.
|
|
NeutralCompletion float64
|
|
// FullCompletion: completion at/above which a play is a full positive
|
|
// (+1).
|
|
FullCompletion float64
|
|
}
|
|
|
|
// DefaultEngagementParams returns the tuned starting curve.
|
|
func DefaultEngagementParams() EngagementParams {
|
|
return EngagementParams{HardSkip: 0.05, NeutralCompletion: 0.30, FullCompletion: 0.90}
|
|
}
|
|
|
|
// Engagement maps a play's completion ratio to a taste signal in [-1, +1]
|
|
// via two linear ramps meeting at the neutral point:
|
|
//
|
|
// completion <= HardSkip → -1
|
|
// HardSkip < c < Neutral → ramp -1 → 0
|
|
// Neutral <= c < Full → ramp 0 → +1
|
|
// completion >= Full → +1
|
|
//
|
|
// Completion is clamped to [0,1]. Degenerate params (non-increasing
|
|
// thresholds) collapse the affected ramp to its endpoint rather than
|
|
// dividing by zero.
|
|
func Engagement(completion float64, p EngagementParams) float64 {
|
|
c := clamp01(completion)
|
|
if c <= p.HardSkip {
|
|
return -1
|
|
}
|
|
if c < p.NeutralCompletion {
|
|
span := p.NeutralCompletion - p.HardSkip
|
|
if span <= 0 {
|
|
return 0
|
|
}
|
|
return -1 + (c-p.HardSkip)/span
|
|
}
|
|
if c < p.FullCompletion {
|
|
span := p.FullCompletion - p.NeutralCompletion
|
|
if span <= 0 {
|
|
return 1
|
|
}
|
|
return (c - p.NeutralCompletion) / span
|
|
}
|
|
return 1
|
|
}
|
|
|
|
// decay is the exponential time-decay applied to a play's engagement:
|
|
// 1.0 at age 0, 0.5 at age == halfLifeDays. Negative ages clamp to 0.
|
|
func decay(ageDays, halfLifeDays float64) float64 {
|
|
if ageDays < 0 {
|
|
ageDays = 0
|
|
}
|
|
if halfLifeDays <= 0 {
|
|
return 1
|
|
}
|
|
return math.Exp(-math.Ln2 * ageDays / halfLifeDays)
|
|
}
|
|
|
|
func clamp01(x float64) float64 {
|
|
if x < 0 {
|
|
return 0
|
|
}
|
|
if x > 1 {
|
|
return 1
|
|
}
|
|
return x
|
|
}
|