Class: ActiveRecall::SM2

Inherits:
Object
  • Object
show all
Defined in:
lib/active_recall/algorithms/sm2.rb

Constant Summary collapse

MIN_EASINESS_FACTOR =
1.3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current) ⇒ SM2

Returns a new instance of SM2.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_recall/algorithms/sm2.rb', line 24

def initialize(box:, easiness_factor:, times_right:, times_wrong:, grade:, 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
  @current_time = current_time
  @interval = case box
  when 0 then 1  # First review
  when 1 then 6  # Second review
  else 17       # Will be overwritten for boxes > 1
  end
end

Class Method Details

.required_attributesObject



5
6
7
# File 'lib/active_recall/algorithms/sm2.rb', line 5

def self.required_attributes
  REQUIRED_ATTRIBUTES
end

.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_recall/algorithms/sm2.rb', line 9

def self.score(box:, easiness_factor:, times_right:, times_wrong:, grade:, current_time: Time.current)
  new(
    box: box,
    easiness_factor: easiness_factor,
    times_right: times_right,
    times_wrong: times_wrong,
    grade: grade,
    current_time: current_time
  ).score
end

.typeObject



20
21
22
# File 'lib/active_recall/algorithms/sm2.rb', line 20

def self.type
  :gradable
end

Instance Method Details

#scoreObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_recall/algorithms/sm2.rb', line 38

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