diff options
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, } } |
