update to the playlists. testing
This commit is contained in:
@@ -21,6 +21,8 @@ pub fn score_tracks(
|
||||
tracks_by_artist: &HashMap<String, Vec<Track>>,
|
||||
top_tracks_by_artist: &HashMap<String, Vec<PopularTrack>>,
|
||||
popularity_bias: u8,
|
||||
_global_popularity: u8,
|
||||
max_tracks_per_artist: Option<u8>,
|
||||
) -> Vec<ScoredTrack> {
|
||||
let bias = popularity_bias.min(10) as usize;
|
||||
let mut scored = Vec::new();
|
||||
@@ -108,7 +110,9 @@ pub fn score_tracks(
|
||||
by_artist.entry(key).or_default().push(t);
|
||||
}
|
||||
|
||||
let cap = if popularity_bias == 0 {
|
||||
let cap = if let Some(explicit) = max_tracks_per_artist {
|
||||
Some((explicit as usize).max(1))
|
||||
} else if popularity_bias == 0 {
|
||||
None
|
||||
} else {
|
||||
let b = popularity_bias as f64;
|
||||
@@ -147,5 +151,49 @@ pub fn score_tracks(
|
||||
}
|
||||
}
|
||||
|
||||
by_artist.into_values().flatten().collect()
|
||||
let mut result: Vec<ScoredTrack> = by_artist.into_values().flatten().collect();
|
||||
|
||||
// Step 3: Apply global popularity weighting
|
||||
if _global_popularity > 0 {
|
||||
let gp = _global_popularity.min(10) as usize;
|
||||
let gp_exponent = POPULARITY_EXPONENTS[gp];
|
||||
let gp_strength = _global_popularity as f64 / 10.0;
|
||||
|
||||
// Find max playcount across ALL artists
|
||||
let global_max: u64 = top_tracks_by_artist
|
||||
.values()
|
||||
.flat_map(|tracks| tracks.iter().map(|t| t.playcount))
|
||||
.max()
|
||||
.unwrap_or(1)
|
||||
.max(1);
|
||||
|
||||
// Build a global playcount lookup (lowercase name -> max playcount)
|
||||
let mut global_playcounts: HashMap<String, u64> = HashMap::new();
|
||||
for tracks in top_tracks_by_artist.values() {
|
||||
for t in tracks {
|
||||
let key = t.name.to_lowercase();
|
||||
global_playcounts
|
||||
.entry(key)
|
||||
.and_modify(|c| *c = (*c).max(t.playcount))
|
||||
.or_insert(t.playcount);
|
||||
}
|
||||
}
|
||||
|
||||
for t in &mut result {
|
||||
let playcount = t
|
||||
.title
|
||||
.as_ref()
|
||||
.and_then(|title| global_playcounts.get(&title.to_lowercase()).copied())
|
||||
.unwrap_or(0);
|
||||
|
||||
if playcount > 0 {
|
||||
let global_pop = (playcount as f64 / global_max as f64).powf(gp_exponent);
|
||||
// lerp(1.0, global_pop, gp_strength)
|
||||
let factor = 1.0 + gp_strength * (global_pop - 1.0);
|
||||
t.score *= factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user