update to the playlists. testing
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user