aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs21
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/dj/mod.rs2
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/messanges/mod.rs26
3 files changed, 41 insertions, 8 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,
}
}
diff --git a/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs b/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
index a211a571..548ed4f4 100644
--- a/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
@@ -3,7 +3,7 @@ use tracing::info;
use crate::{clients::Client, dj::algorithms::Algorithm};
-pub(crate) mod algorithms;
+pub mod algorithms;
pub(crate) struct Dj<A: Algorithm> {
algo: A,
diff --git a/pkgs/by-name/mp/mpdpopm/src/messanges/mod.rs b/pkgs/by-name/mp/mpdpopm/src/messanges/mod.rs
index ac0b9cbe..7db75672 100644
--- a/pkgs/by-name/mp/mpdpopm/src/messanges/mod.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/messanges/mod.rs
@@ -27,7 +27,19 @@ enum SubCommand {
#[derive(Subcommand)]
enum DjCommand {
- Start {},
+ Start {
+ /// The chance to select a "positive" track
+ #[arg(long)]
+ positive_chance: f64,
+
+ /// The chance to select a "neutral" track
+ #[arg(long)]
+ neutral_chance: f64,
+
+ /// The chance to select a "negative" track
+ #[arg(long)]
+ negative_chance: f64,
+ },
Stop {},
}
@@ -101,9 +113,17 @@ impl MessageQueue {
match args.command {
SubCommand::Dj { command } => match command {
- DjCommand::Start {} => {
+ DjCommand::Start {
+ positive_chance,
+ neutral_chance,
+ negative_chance,
+ } => {
info!("Dj started");
- self.dj = Some(Dj::new(Discovery::new()));
+ self.dj = Some(Dj::new(Discovery::new(
+ positive_chance,
+ neutral_chance,
+ negative_chance,
+ )));
self.advance_dj(client).await?;
}
DjCommand::Stop {} => {