aboutsummaryrefslogtreecommitdiff
path: root/src/trajectory.rs
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-07-13 15:06:41 +0100
committertslil <tslil@posteo.de>2026-07-13 21:21:21 +0100
commit3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 (patch)
treeba711eb220e39fe64388d370b16384a7bc84eaab /src/trajectory.rs
parente0241df8afde0483fc36cb2300b53127672486dc (diff)
Pure history
Diffstat (limited to 'src/trajectory.rs')
-rw-r--r--src/trajectory.rs39
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
}