Class: Fsrs::Scheduler
- Inherits:
-
Object
- Object
- Fsrs::Scheduler
- Includes:
- Common, LearningState, NewState, ReviewState, Serialization
- Defined in:
- lib/fsrs/fsrs.rb
Overview
Scheduler
Defined Under Namespace
Modules: Common, LearningState, NewState, ReviewState, Serialization
Instance Attribute Summary collapse
-
#decay ⇒ Object
Returns the value of attribute decay.
-
#factor ⇒ Object
Returns the value of attribute factor.
-
#p ⇒ Object
Returns the value of attribute p.
Instance Method Summary collapse
- #card_elapsed_days(card, now) ⇒ Object
-
#initialize ⇒ Scheduler
constructor
A new instance of Scheduler.
- #repeat(card, now) ⇒ Object
- #schedule_card(card_scheduler, card, now) ⇒ Object
Methods included from Serialization
Methods included from Common
#next_difficulty, #next_ds, #next_forget_stability, #next_interval, #next_recall_stability
Methods included from ReviewState
#compute_review_state_intervals_and_schedule, #forgetting_curve, #mean_reversion, #schedule_review_state
Methods included from LearningState
#schedule_learning_relearning_state
Methods included from NewState
#init_difficulty, #init_ds, #init_stability, #schedule_new_state
Constructor Details
#initialize ⇒ Scheduler
Returns a new instance of Scheduler.
269 270 271 272 273 |
# File 'lib/fsrs/fsrs.rb', line 269 def initialize @p = Parameters.new @decay = -0.5 @factor = (0.9**(1 / @decay)) - 1 end |
Instance Attribute Details
#decay ⇒ Object
Returns the value of attribute decay.
267 268 269 |
# File 'lib/fsrs/fsrs.rb', line 267 def decay @decay end |
#factor ⇒ Object
Returns the value of attribute factor.
267 268 269 |
# File 'lib/fsrs/fsrs.rb', line 267 def factor @factor end |
#p ⇒ Object
Returns the value of attribute p.
267 268 269 |
# File 'lib/fsrs/fsrs.rb', line 267 def p @p end |
Instance Method Details
#card_elapsed_days(card, now) ⇒ Object
289 290 291 |
# File 'lib/fsrs/fsrs.rb', line 289 def card_elapsed_days(card, now) card.state == State::NEW ? 0 : (now - card.last_review).to_i end |
#repeat(card, now) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/fsrs/fsrs.rb', line 275 def repeat(card, now) raise Fsrs::InvalidDateError unless now.utc? card = card.clone card.elapsed_days = card_elapsed_days(card, now) card.last_review = now card.reps += 1 card_scheduler = CardScheduler.new(card) card_scheduler.update_state(card.state) schedule_card(card_scheduler, card, now) card_scheduler.record_log(card, now) end |
#schedule_card(card_scheduler, card, now) ⇒ Object
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/fsrs/fsrs.rb', line 293 def schedule_card(card_scheduler, card, now) case card.state when State::NEW schedule_new_state(card_scheduler, now) when State::LEARNING, State::RELEARNING schedule_learning_relearning_state(card_scheduler, now) when State::REVIEW schedule_review_state(card_scheduler, card, now) end end |