Skip to content

Commit

Permalink
Play some more with the trend metric
Browse files Browse the repository at this point in the history
It needs more precision in serealization as well, because the numbers
are between 0 and 1.
  • Loading branch information
ruuda committed May 21, 2024
1 parent 878cfab commit 32ec55f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/playcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_.
Expand Down
6 changes: 5 additions & 1 deletion src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub fn write_brief_album_json<W: Write>(
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,
Expand Down

0 comments on commit 32ec55f

Please sign in to comment.