diff options
Diffstat (limited to 'src/trajectory.rs')
| -rw-r--r-- | src/trajectory.rs | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/trajectory.rs b/src/trajectory.rs index 214e16c..cbb0661 100644 --- a/src/trajectory.rs +++ b/src/trajectory.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, time::SystemTime}; use crate::learner::Learning; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] struct LastData { timestamp: SystemTime, album: String, @@ -16,7 +16,7 @@ pub struct Trajectory { history: Vec<String>, } -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] pub enum Action { Skip, More, @@ -26,8 +26,8 @@ impl From<Option<&Learning>> for Action { fn from(learning: Option<&Learning>) -> Action { if let Some(ts) = learning { match ts { - Learning::SkipExtend | Learning::MoreToSkip(_, _) => Action::Skip, - Learning::MoreExtend(_, _) | Learning::SkipToMore(_, _) => Action::More, + Learning::MoreToSkip(_, _) => Action::Skip, + Learning::SkipToMore(_, _) => Action::More, } } else { Action::Skip @@ -71,26 +71,29 @@ impl Trajectory { let last_album = last_data.album.clone(); let current_streak = self.history.clone(); + let learnt_nothing = self + .streak_kind + .as_ref() + .map(|kind| *kind == action) + .unwrap_or(false); - let learning = if let Some(ref kind) = self.streak_kind - && kind == &action - { - self.history.push(last_album.clone()); - match action { - Action::Skip => Learning::SkipExtend, - Action::More => Learning::MoreExtend(current_streak, last_album), + let learning = match (learnt_nothing, &action) { + (false, Action::Skip) => { + Some(Learning::MoreToSkip(current_streak, last_album.clone())) } - } else { - self.history.clear(); - self.history.push(last_album.clone()); - match action { - Action::Skip => Learning::MoreToSkip(current_streak, last_album), - Action::More => Learning::SkipToMore(current_streak, last_album), + (false, Action::More) => { + Some(Learning::SkipToMore(current_streak, last_album.clone())) } + _ => None, + }; + + if !learnt_nothing { + self.history.clear(); }; + self.history.push(last_album); self.streak_kind = Some(action); - Some(learning) + learning } else { None } |
