Skip to content

Commit

Permalink
Add learning module
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed committed Feb 5, 2024
1 parent 0014f03 commit 1ebd03c
Show file tree
Hide file tree
Showing 27 changed files with 562 additions and 59 deletions.
147 changes: 147 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ edition = "2021"

[dependencies]
bincode = "1.3.3"
chrono = "0.4.33"
dirs = "5.0.1"
env_logger = "0.10.1"
hex = "0.4.3"
lazy_static = "1.4.0"
log = "0.4.20"
rand = "0.8.5"
rocket = { version = "=0.5.0-rc.4", features = ["json"] }
Expand Down
8 changes: 8 additions & 0 deletions learning.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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
3 changes: 3 additions & 0 deletions learning.production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
decay_rate_factor_correct: 0.0 # 0.0 no decay
decay_rate_factor_incorrect: 0.0
consecutive_hours_threshold: 0
3 changes: 3 additions & 0 deletions learning.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
decay_rate_factor_correct: 0.0 # 0.0 no decay
decay_rate_factor_incorrect: 0.0
consecutive_hours_threshold: 0
3 changes: 2 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod get_chapters;
pub mod get_labels;
pub mod verse_by_chapter;
pub mod verse_similar_by_chapter;
pub mod ping;
pub mod ping;
pub mod user_stats_analytics;
17 changes: 17 additions & 0 deletions src/api/user_stats_analytics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use rocket::post;
use rocket::{serde::json::Json, State};

use crate::learning::models::{
user_stat::UserStat,
analytic::Analytic,
learning_config::LearningConfig
};
use crate::learning::compute_user_stats_analytics::compute_user_stats_analytics;

#[post("/user-stats-analytics", format = "json", data = "<user_stats>")]
pub fn user_stats_analytics(config: &State<LearningConfig>, user_stats: Json<Vec<UserStat>>)
-> Json<Vec<Analytic>> {
let item_progress = compute_user_stats_analytics(&**config, &user_stats);

Json(item_progress)
}
22 changes: 0 additions & 22 deletions src/cors.rs

This file was deleted.

14 changes: 14 additions & 0 deletions src/learning/calculate_decay_rate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn calculate_decay_rate(elapsed_days: i64, repetitions: Option<i32>) -> f32 {
// Adjust decay rate based on the number of repetitions (if available)
let repetitions_factor = match repetitions {
Some(rep_count) if rep_count > 0 => 1.0 / (rep_count as f32),
_ => 1.0, // Default factor if no repetitions or repetitions is 0
};

// Calculate the decay rate based on elapsed days and repetitions factor
// Adjust these parameters as needed for your specific application
let decay_rate = 1.0 - (elapsed_days as f32 * repetitions_factor * 0.01);

// Ensure the decay rate is within bounds (between 0 and 1)
decay_rate.clamp(0.0, 1.0)
}
Loading

0 comments on commit 1ebd03c

Please sign in to comment.