update to the playlists. testing
CI / check (push) Successful in 1m15s
CI / docker (push) Successful in 2m11s

This commit is contained in:
Connor Johnstone
2026-04-01 22:12:58 -04:00
parent f77cea47b1
commit b2f030b52d
8 changed files with 224 additions and 32 deletions
+17 -1
View File
@@ -11,6 +11,8 @@ pub fn generate_playlist(
candidates: &[Candidate],
n: usize,
seed_names: &HashSet<String>,
max_artists: Option<u8>,
skip_seed_enforcement: bool,
) -> Vec<Candidate> {
if candidates.is_empty() {
return Vec::new();
@@ -20,8 +22,14 @@ pub fn generate_playlist(
let mut pool: Vec<&Candidate> = candidates.iter().collect();
let mut result: Vec<Candidate> = Vec::new();
let mut artist_counts: HashMap<String, usize> = HashMap::new();
let mut distinct_artists_set: HashSet<String> = HashSet::new();
let max_distinct = max_artists.map(|m| (m as usize).max(1));
let seed_min = (n / 10).max(1);
let seed_min = if skip_seed_enforcement {
0
} else {
(n / 10).max(1)
};
let distinct_artists: usize = {
let mut seen = HashSet::new();
@@ -54,6 +62,13 @@ pub fn generate_playlist(
.iter()
.enumerate()
.filter(|(_, c)| {
// Max distinct artists: reject new artists once we hit the cap
if let Some(max) = max_distinct
&& distinct_artists_set.len() >= max
&& !distinct_artists_set.contains(&c.artist)
{
return false;
}
if force_seed {
seed_names.contains(&c.artist)
} else {
@@ -79,6 +94,7 @@ pub fn generate_playlist(
let picked = indices[dist.sample(&mut rng)];
let track = pool.remove(picked);
*artist_counts.entry(track.artist.clone()).or_insert(0) += 1;
distinct_artists_set.insert(track.artist.clone());
result.push(Candidate {
score: track.score,
artist: track.artist.clone(),