release / web (push) Successful in 1m17s
release / go (push) Failing after 1m42s
release / govulncheck (push) Successful in 17s
release / integration (push) Failing after 3m57s
release / android (push) Successful in 4m23s
release / Build signed APK (push) Successful in 4m50s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
Radio returned its picks in score order, and a seed's own artist matches it best, so a DROELOE radio opened with four DROELOE songs in a row. The artist cap bounded how many songs an artist got, not where they played. SpreadArtists reorders picks so an artist doesn't play again within three songs where another choice exists. Each slot takes the best remaining pick outside that gap; when none is, the artist heard longest ago goes next, so two artists alternate. Which songs are picked doesn't change. Radio counts the seed's artist as just played; the library shuffle spreads from a blank start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package recommendation
|
|
|
|
import "github.com/jackc/pgx/v5/pgtype"
|
|
|
|
// artistGap is how many other songs SpreadArtists puts between two songs by
|
|
// one artist when the picks allow it. Radio's best matches are usually the
|
|
// seed artist's own songs, and played in score order they would open the
|
|
// radio back to back; three songs between them keeps the artist present
|
|
// without the radio sounding like an album.
|
|
const artistGap = 3
|
|
|
|
// SpreadArtists reorders picks so that, where another choice exists, an
|
|
// artist doesn't play again within artistGap songs. It changes only the
|
|
// order, never which songs are picked.
|
|
//
|
|
// Each slot takes the best-scoring remaining pick whose artist is outside the
|
|
// gap, so the strongest picks stay near the front. When every remaining pick
|
|
// is by a recently played artist, the slot takes the one whose artist was
|
|
// played longest ago, so a pool of two artists alternates rather than
|
|
// clumping. A pick with no known artist is never held back.
|
|
//
|
|
// lastPlayed lists the artists heard just before these picks, oldest first:
|
|
// a radio's seed song plays first, so its artist counts as just played.
|
|
func SpreadArtists(picks []Candidate, lastPlayed ...pgtype.UUID) []Candidate {
|
|
if len(picks) < 2 {
|
|
return picks
|
|
}
|
|
remaining := append([]Candidate(nil), picks...)
|
|
out := make([]Candidate, 0, len(picks))
|
|
// lastAt is the position each artist last played at, counting the
|
|
// lastPlayed songs as positions before 0.
|
|
lastAt := make(map[[16]byte]int, len(picks))
|
|
for i, a := range lastPlayed {
|
|
if a.Valid {
|
|
lastAt[a.Bytes] = i - len(lastPlayed)
|
|
}
|
|
}
|
|
for len(remaining) > 0 {
|
|
pos := len(out)
|
|
choice := -1
|
|
oldest, oldestAt := -1, 0
|
|
for i, c := range remaining {
|
|
a := c.Track.ArtistID
|
|
at, played := lastAt[a.Bytes]
|
|
if !a.Valid || !played || pos-at > artistGap {
|
|
choice = i
|
|
break
|
|
}
|
|
if oldest < 0 || at < oldestAt {
|
|
oldest, oldestAt = i, at
|
|
}
|
|
}
|
|
if choice < 0 {
|
|
choice = oldest
|
|
}
|
|
c := remaining[choice]
|
|
remaining = append(remaining[:choice], remaining[choice+1:]...)
|
|
if c.Track.ArtistID.Valid {
|
|
lastAt[c.Track.ArtistID.Bytes] = pos
|
|
}
|
|
out = append(out, c)
|
|
}
|
|
return out
|
|
}
|