From 3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 Mon Sep 17 00:00:00 2001 From: tslil Date: Mon, 13 Jul 2026 15:06:41 +0100 Subject: Pure history --- src/config.rs | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 0be1d09..f38b571 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,26 +1,44 @@ use directories::{ProjectDirs, UserDirs}; use serde::{Deserialize, Serialize}; +use std::fs; + +use expanduser::expanduser; #[derive(Serialize, Deserialize)] pub struct Config { pub music_roots: Vec, pub audio_exts: Vec, pub skip_window_secs: u64, - pub learning_rate: f32, - pub decay_rate: f32, - pub min_score_thresh: f32, pub temperature: f32, + pub low_weight: f32, + pub mid_weight: f32, + pub high_weight: f32, + pub max_weight: f32, } -pub fn default_state_path() -> String { +fn default_config_path() -> String { + let name = "mood.json"; ProjectDirs::from("qualifier", "organisation", "mood") - .and_then(|pd| { - pd.config_dir() - .join("mood.ron") - .to_str() - .map(|x| x.to_string()) - }) - .unwrap_or("~/.config/mood/mood.ron".to_string()) + .and_then(|pd| pd.config_dir().join(name).to_str().map(|x| x.to_string())) + .unwrap_or(format!("~/.config/mood/{name}")) +} + +impl Config { + pub fn try_load() -> Result { + expanduser(default_config_path()) + .map_err(|e| e.to_string()) + .and_then(|p| fs::read_to_string(p).map_err(|e| e.to_string())) + .and_then(|contents| serde_json::from_str(&contents).map_err(|e| e.to_string())) + } + + pub fn try_save(&self) -> Result<(), String> { + let path = expanduser(default_config_path()).map_err(|e| e.to_string())?; + _ = path.parent().map(std::fs::create_dir_all); + let serialised = serde_json::to_string_pretty(self) + .map_err(|e| format!("Failed to serialize config: {}", e))?; + fs::write(&path, serialised).map_err(|e| format!("Failed to write config file: {}", e))?; + Ok(()) + } } impl Default for Config { @@ -39,10 +57,11 @@ impl Default for Config { .map(String::from) .collect(), skip_window_secs: 60, - learning_rate: 0.1, - decay_rate: 0.001, - min_score_thresh: 1e-5, temperature: 0.6, + low_weight: 0.25, + mid_weight: 0.5, + high_weight: 0.75, + max_weight: 1.0, } } } -- cgit v1.2.3