Class: ActiveRecall::SM2
- Inherits:
-
Object
- Object
- ActiveRecall::SM2
- Defined in:
- lib/active_recall/algorithms/sm2.rb
Constant Summary collapse
- MIN_EASINESS_FACTOR =
1.3
Class Method Summary collapse
- .required_attributes ⇒ Object
- .score(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
-
#initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) ⇒ SM2
constructor
A new instance of SM2.
- #score ⇒ Object
Constructor Details
#initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) ⇒ SM2
Returns a new instance of SM2.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_recall/algorithms/sm2.rb', line 28 def initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) @box = box # box serves as repetition number n @easiness_factor = easiness_factor || 2.5 @times_right = times_right @times_wrong = times_wrong @grade = grade @last_reviewed = last_reviewed # the card's prior review time @previous_next_review = next_review # the card's prior scheduled due date @current_time = current_time @interval = 1 end |
Class Method Details
.required_attributes ⇒ Object
7 8 9 |
# File 'lib/active_recall/algorithms/sm2.rb', line 7 def self.required_attributes REQUIRED_ATTRIBUTES end |
.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_recall/algorithms/sm2.rb', line 11 def self.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, last_reviewed: nil, next_review: nil, current_time: Time.current) new( box: box, easiness_factor: easiness_factor, times_right: times_right, times_wrong: times_wrong, grade: grade, last_reviewed: last_reviewed, next_review: next_review, current_time: current_time ).score end |
.type ⇒ Object
24 25 26 |
# File 'lib/active_recall/algorithms/sm2.rb', line 24 def self.type :gradable end |
Instance Method Details
#score ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_recall/algorithms/sm2.rb', line 40 def score raise "Grade must be between 0-5!" unless GRADES.include?(@grade) old_ef = @easiness_factor update_easiness_factor update_repetition_and_interval(old_ef) { box: @box, easiness_factor: @easiness_factor, times_right: @times_right, times_wrong: @times_wrong, last_reviewed: @current_time, next_review: next_review } end |