diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-02-19 22:38:14 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-02-19 22:38:14 +0100 |
| commit | c0a5deab2e4d4501e5a5d277c591bb444512613e (patch) | |
| tree | c08c9005aa082f230eaef60a528df8c78df98fd5 /pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs | |
| parent | pkgs/mpdpopmd: Don't add a new song to playlist for every event (diff) | |
| download | nixos-config-c0a5deab2e4d4501e5a5d277c591bb444512613e.zip | |
pkgs/mpdpopmd: Make the {positive,neutral,negative} chances configurable
Diffstat (limited to 'pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs')
| -rw-r--r-- | pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs index 5ddfc7cb..fcb7a88d 100644 --- a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs +++ b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs @@ -13,8 +13,11 @@ pub(crate) trait Algorithm { /// Generates generic discovery playlist, that fulfills following requirements: /// - Will (eventually) include every not-played song. (So it can be used to rank a library) /// - Returns liked songs more often then not-played or negative songs. -pub(crate) struct Discovery { +pub struct Discovery { already_done: HashSet<String>, + negative_chance: f64, + neutral_chance: f64, + positive_chance: f64, } impl Algorithm for Discovery { @@ -106,8 +109,15 @@ impl Algorithm for Discovery { }; let pick = rng.sample( - distr::weighted::WeightedIndex::new([0.65, 0.5, 0.2].iter()) - .expect("to be valid, as hardcoded"), + distr::weighted::WeightedIndex::new( + [ + self.positive_chance, + self.neutral_chance, + self.negative_chance, + ] + .iter(), + ) + .expect("to be valid, as hardcoded"), ); let next = match pick { @@ -124,9 +134,12 @@ impl Algorithm for Discovery { } impl Discovery { - pub(crate) fn new() -> Self { + pub(crate) fn new(positive_chance: f64, neutral_chance: f64, negative_chance: f64) -> Self { Self { already_done: HashSet::new(), + positive_chance, + neutral_chance, + negative_chance, } } |
