From 3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 Mon Sep 17 00:00:00 2001 From: tslil Date: Mon, 13 Jul 2026 15:06:41 +0100 Subject: Pure history --- src/trajectory.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/trajectory.rs') 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, } -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] pub enum Action { Skip, More, @@ -26,8 +26,8 @@ impl From> 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 } -- cgit v1.2.3