Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bennekrouf/similar-sled
Browse files Browse the repository at this point in the history
  • Loading branch information
bennekrouf committed Feb 8, 2024
2 parents 195d769 + 0547e92 commit 1c23255
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 64 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ else
echo "Source and destination are the same. Skipping move operation."
fi
cp -r config.${ENV}.yml /home/similar/${ENV}/similar/
cp -r learning.${ENV}.yml /home/similar/${ENV}/similar/
11 changes: 8 additions & 3 deletions learning.production.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
decay_rate_factor_correct: 0.0 # 0.0 no decay
decay_rate_factor_incorrect: 0.0
consecutive_hours_threshold: 0
decay_rate_factor_correct: 0.5 # 0.0 no decay 0.1 - 0.9 (positive effect fades faster, requiring more frequent review)
decay_rate_factor_incorrect: 0.3 # 0.1 to 0.5 - up to 0.5 increases the penalty for incorrect answers
consecutive_hours_threshold: 3 # 2 to 6 hours
progress_threshold: 40 # higher means easier to recall 20 to 60
streak_bonus: 5
min_score: 2
max_score: 120
decimals: 0
11 changes: 8 additions & 3 deletions learning.staging.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
decay_rate_factor_correct: 0.0 # 0.0 no decay
decay_rate_factor_incorrect: 0.0
consecutive_hours_threshold: 0
decay_rate_factor_correct: 0.5 # 0.0 no decay 0.1 - 0.9 (positive effect fades faster, requiring more frequent review)
decay_rate_factor_incorrect: 0.3 # 0.1 to 0.5 - up to 0.5 increases the penalty for incorrect answers
consecutive_hours_threshold: 3 # 2 to 6 hours
progress_threshold: 40 # higher means easier to recall 20 to 60
streak_bonus: 5
min_score: 2
max_score: 120
decimals: 0
58 changes: 0 additions & 58 deletions src/learning/compute_user_stat_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,3 @@ pub fn compute_user_stat_progress(config: &LearningConfig, stat: &UserStat) -> f

formatted_percentage.parse().unwrap_or(0.0)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::learning::models::learning_config::LearningConfig;
use crate::learning::models::user_stat::UserStat;

use chrono::{TimeZone, Utc};

#[test]
fn test_basic_progress_calculation() {
let config = LearningConfig {
streak_bonus: 3,
consecutive_hours_threshold: 24,
min_score: 0,
max_score: 100,
// Other fields as necessary...
};
let stat = UserStat {
updated_at: Utc.ymd(2022, 5, 1).and_hms(12, 0, 0).timestamp(),
g: 10,
w: 5,
repetitions: Some(2),
// Other fields as necessary...
};
let progress = compute_user_stat_progress(&config, &stat);
assert!(progress > 0.0); // The exact assertion might need adjustment based on decay_factor and scale_to_percentage calculations
}

#[test]
fn test_streak_bonus() {
let config = LearningConfig {
streak_bonus: 2, // Lower threshold for testing
// Other configurations...
};
let stat = UserStat {
repetitions: Some(3), // Exceeds streak bonus threshold
// Populate other necessary fields...
};
let progress = compute_user_stat_progress(&config, &stat);
assert!(progress > 0.0); // Check that the progress includes the streak bonus
}

#[test]
fn test_consecutive_hours_bonus() {
// This test assumes has_reached_consecutive_hours would return true for the given stat
let config = LearningConfig {
// Configuration that would trigger the consecutive hours bonus...
};
let stat = UserStat {
// UserStat configuration that would simulate reaching consecutive hours threshold...
};
let initial_progress = compute_user_stat_progress(&config, &stat);
// Potentially manipulate stat to not meet the threshold and compute again
let adjusted_progress = compute_user_stat_progress(&config, &stat); // Adjust stat accordingly
assert!(initial_progress < adjusted_progress); // Assuming the score doubles when the threshold is met
}
}
4 changes: 4 additions & 0 deletions src/utils/yml_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub fn load_config<T>(config_path: &str) -> T
where T: DeserializeOwned,
{
let app_env = env::var("APP_ENV").unwrap_or_else(|_| "local".to_string());
println!("APP_ENV: {}", app_env);

let config_path = format!("{}.{}.yml", config_path, app_env);
println!("Looking for config file at: {}", config_path);

let config_str = std::fs::read_to_string(&config_path)
.expect("Failed to read config file");
serde_yaml::from_str(&config_str).expect("Failed to parse config file")
Expand Down

0 comments on commit 1c23255

Please sign in to comment.