From 32ec55f81df0f31229ff270e5056dfa8edfb7b06 Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Tue, 21 May 2024 22:22:00 +0200 Subject: [PATCH] Play some more with the trend metric It needs more precision in serealization as well, because the numbers are between 0 and 1. --- src/playcount.rs | 11 ++++++++++- src/serialization.rs | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/playcount.rs b/src/playcount.rs index 69b65ae..3eef49c 100644 --- a/src/playcount.rs +++ b/src/playcount.rs @@ -576,7 +576,16 @@ fn print_ranking( /// Trending entries (tracks, albums, artists) are entries where the recent /// playcount is high compared to the long-term playcount. fn score_trending(counter: &ExpCounter) -> f32 { - 3.0 * counter.n[4] / (counter.n[3] + counter.n[2] + counter.n[1]) + // The trend ratio is the ratio of recent vs. older plays, it is 1.0 for new + // tracks that we just played, and tends to 0.0 for tracks that we played in + // the past but not recently. + let trend = 3.0 * counter.n[4] / (counter.n[3] + counter.n[2] + counter.n[1]); + + // On its own though, the trend counter ignores popularity. The playcount is + // both in the numerator and denominator, it only counts recency. I tried + // various ways of mixing in a recent playcount, but in the end, I find just + // the recency more useful. + trend } /// Score for sorting entries by _falling_. diff --git a/src/serialization.rs b/src/serialization.rs index 946ae8a..5851470 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -41,7 +41,11 @@ pub fn write_brief_album_json( let scores = user_data.get_album_scores(album_id); write!( w, - r#","release_date":"{}","first_seen":"{}","discover_score":{:.3},"trending_score":{:.3}}}"#, + // The discover score can have large-ish magnitude and ranges from negative + // to positive, it does not need a lot of precision. The trending score + // is always between 0 and 1 though, it needs more digits for precision + // near the end of the ranking. + r#","release_date":"{}","first_seen":"{}","discover_score":{:.2},"trending_score":{:.4}}}"#, album.original_release_date, album.first_seen.format_iso8601(), scores.discover_score,