feat: genre mixes pick specific genres that don't share songs (#6933)
release / go (push) Successful in 2m0s
release / web (push) Successful in 1m33s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 5m11s
release / android (push) Successful in 4m14s
release / Build signed APK (push) Successful in 4m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 2m0s
release / web (push) Successful in 1m33s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 5m11s
release / android (push) Successful in 4m14s
release / Build signed APK (push) Successful in 4m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
The shelf had four mixes built largely from the same lo-fi beats: about 1,250 tracks carry Hip Hop, Lo-Fi, Instrumental, Downtempo and four more tags at once, and the near-duplicate guard compared artists, not songs, so each tag passed as its own channel. Genre selection now works on songs: - ListGenreMixCandidates returns each genre's track ids instead of its artist ids. - A broad genre, one whose songs mostly also carry clearly narrower candidates (Rock over Pop Punk and Ska Punk), is considered after the specific genres of its tier. - A genre is kept only when at least half its songs are not already in a kept genre. - Each mix leaves out songs tagged with a genre kept before it (ListGenreMixTracks exclude_genres), so a song is in one mix at most. The tiers, the minimum shelf and the minimum mix length are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -92,39 +92,85 @@ func TestComposeGenreMix_CapsOneArtistThenTopsUpANarrowGenre(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func artists(ns ...int) []pgtype.UUID {
|
||||
out := make([]pgtype.UUID, len(ns))
|
||||
for i, n := range ns {
|
||||
out[i] = uuidN(n)
|
||||
// songs returns the track ids from..to inclusive.
|
||||
func songs(from, to int) []pgtype.UUID {
|
||||
out := make([]pgtype.UUID, 0, to-from+1)
|
||||
for n := from; n <= to; n++ {
|
||||
out = append(out, uuidN(n))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestOverlapsKept_NearDuplicatesCollapseButSubgenresOfABroadGenreStay(t *testing.T) {
|
||||
rock := genreCandidate{Label: "Rock", ArtistIDs: artists(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)}
|
||||
altRock := genreCandidate{Label: "Alternative Rock", ArtistIDs: artists(1, 2, 3)}
|
||||
lofi := genreCandidate{Label: "Lo-Fi", ArtistIDs: artists(20, 21, 22, 23)}
|
||||
lofiHipHop := genreCandidate{Label: "Lo-Fi Hip Hop", ArtistIDs: artists(20, 21, 22, 24)}
|
||||
func genreOf(label string, tier int32, ids ...[]pgtype.UUID) genreCandidate {
|
||||
var all []pgtype.UUID
|
||||
for _, part := range ids {
|
||||
all = append(all, part...)
|
||||
}
|
||||
return genreCandidate{Key: label, Label: label, Tier: tier, TrackIDs: all}
|
||||
}
|
||||
|
||||
if overlapsKept(altRock, []genreCandidate{rock}) {
|
||||
t.Error("Alternative Rock (3 of Rock's 10 artists) collapsed into Rock; a subgenre of a broad genre should stay")
|
||||
// A genre whose songs mostly sit in one already picked is the same channel
|
||||
// under another name: Lo-Fi Hip Hop after Lo-Fi.
|
||||
func TestSelectGenreMixes_AGenreOfMostlyPickedSongsGivesWay(t *testing.T) {
|
||||
cands := []genreCandidate{
|
||||
genreOf("Lo-Fi", 1, songs(1, 100)),
|
||||
genreOf("Lo-Fi Hip Hop", 1, songs(1, 80), songs(500, 510)),
|
||||
genreOf("Jazz", 1, songs(1000, 1100)),
|
||||
}
|
||||
if !overlapsKept(lofiHipHop, []genreCandidate{rock, lofi}) {
|
||||
t.Error("Lo-Fi Hip Hop (3 of 5 artists shared with Lo-Fi) was kept; near duplicates should collapse")
|
||||
got := labels(selectGenreMixes(cands, buildN(30)))
|
||||
if len(got) != 2 || got[0] != "Lo-Fi mix" || got[1] != "Jazz mix" {
|
||||
t.Fatalf("mixes = %v, want [Lo-Fi mix Jazz mix]", got)
|
||||
}
|
||||
if overlapsKept(lofi, nil) {
|
||||
t.Error("nothing kept yet, but overlap reported")
|
||||
}
|
||||
|
||||
// A broad genre whose songs mostly carry narrower genres gives way to them,
|
||||
// even when it ranks higher, and each later mix leaves out the songs of the
|
||||
// genres picked before it.
|
||||
func TestSelectGenreMixes_ABroadGenreGivesWayToItsSpecificOnes(t *testing.T) {
|
||||
cands := []genreCandidate{
|
||||
genreOf("Rock", 1, songs(1, 1000)),
|
||||
genreOf("Pop Punk", 1, songs(1, 300)),
|
||||
genreOf("Ska Punk", 1, songs(250, 600)),
|
||||
}
|
||||
excluded := map[string][]string{}
|
||||
build := func(c genreCandidate, exclude []string) []rankedCandidate {
|
||||
excluded[c.Label] = append([]string(nil), exclude...)
|
||||
return make([]rankedCandidate, 30)
|
||||
}
|
||||
got := labels(selectGenreMixes(cands, build))
|
||||
if len(got) != 2 || got[0] != "Pop Punk mix" || got[1] != "Ska Punk mix" {
|
||||
t.Fatalf("mixes = %v, want [Pop Punk mix Ska Punk mix]", got)
|
||||
}
|
||||
if ex := excluded["Ska Punk"]; len(ex) != 1 || ex[0] != "Pop Punk" {
|
||||
t.Fatalf("Ska Punk mix excludes %v, want [Pop Punk]", ex)
|
||||
}
|
||||
if ex := excluded["Pop Punk"]; len(ex) != 0 {
|
||||
t.Fatalf("first mix excludes %v, want nothing", ex)
|
||||
}
|
||||
}
|
||||
|
||||
// A genre only partly covered by narrower ones is a channel of its own, and
|
||||
// keeps its rank.
|
||||
func TestSelectGenreMixes_AGenreMostlyItsOwnKeepsItsRank(t *testing.T) {
|
||||
cands := []genreCandidate{
|
||||
genreOf("Rock", 1, songs(1, 2000)),
|
||||
genreOf("Pop Punk", 1, songs(1, 300)),
|
||||
genreOf("Jazz", 1, songs(3000, 3100)),
|
||||
}
|
||||
got := labels(selectGenreMixes(cands, buildN(30)))
|
||||
if len(got) != 2 || got[0] != "Rock mix" || got[1] != "Jazz mix" {
|
||||
t.Fatalf("mixes = %v, want [Rock mix Jazz mix]", got)
|
||||
}
|
||||
}
|
||||
|
||||
// buildN returns a builder that gives every genre n tracks, except those
|
||||
// listed in short, which get too few to make a mix.
|
||||
func buildN(n int, short ...string) func(genreCandidate) []rankedCandidate {
|
||||
func buildN(n int, short ...string) func(genreCandidate, []string) []rankedCandidate {
|
||||
thin := map[string]bool{}
|
||||
for _, s := range short {
|
||||
thin[s] = true
|
||||
}
|
||||
return func(c genreCandidate) []rankedCandidate {
|
||||
return func(c genreCandidate, _ []string) []rankedCandidate {
|
||||
if thin[c.Label] {
|
||||
return make([]rankedCandidate, genreMixMinLen-1)
|
||||
}
|
||||
@@ -140,8 +186,9 @@ func labels(built []builtPlaylist) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// distinctGenre is a genre of 100 songs of its own, numbered from n*100.
|
||||
func distinctGenre(label string, tier int32, n int) genreCandidate {
|
||||
return genreCandidate{Key: label, Label: label, Tier: tier, ArtistIDs: artists(n)}
|
||||
return genreOf(label, tier, songs(n*100, n*100+99))
|
||||
}
|
||||
|
||||
func TestSelectGenreMixes_TakesTheUsersGenresAndStopsAtTheCount(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user