Class: SRS::Schedulers::SuperMemo2

Inherits:
Object
  • Object
show all
Defined in:
lib/srs/schedulers/SuperMemo2.rb

Constant Summary collapse

DEFAULT_EF =
2.5
MIN_EF =
1.3
FIRST_INTERVAL =
1
SECOND_INTERVAL =
6
ITERATION_RESET_BOUNDARY =
3.0 / 5.0
REPEAT_BOUNDARY =
4.0 / 5.0

Instance Method Summary collapse

Constructor Details

#initialize ⇒ SuperMemo2

Returns a new instance of SuperMemo2.



15
16
# File 'lib/srs/schedulers/SuperMemo2.rb', line 15

def initialize()
end

Instance Method Details

#adjust_efactor(ef, score) ⇒ Object



59
60
61
62
63
64
# File 'lib/srs/schedulers/SuperMemo2.rb', line 59

def adjust_efactor(ef, score)
  q = score * 5
  adjusted_efactor = ef + (0.1-(5.0 - q) * (0.08 + (5.0 - q) * 0.02))

  adjusted_efactor < MIN_EF ? MIN_EF : adjusted_efactor
end

#adjust_interval(interval, ef) ⇒ Object



66
67
68
# File 'lib/srs/schedulers/SuperMemo2.rb', line 66

def adjust_interval(interval, ef)
  (interval * ef).round
end

#first_rep(score) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/srs/schedulers/SuperMemo2.rb', line 18

def first_rep(score)
  fields = {
    "Due"           => (Date.today + FIRST_INTERVAL).to_time,
    "Repeat"        => score < REPEAT_BOUNDARY ? true : false,
    "E-Factor"      => adjust_efactor(DEFAULT_EF, score),
    "Interval"      => FIRST_INTERVAL,
    "Iteration"     => 1
  }

  return fields
end

#rep(score, fields) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/srs/schedulers/SuperMemo2.rb', line 30

def rep(score, fields)
  ef = fields["E-Factor"].to_f
  interval = fields["Interval"].to_i
  iteration = fields["Iteration"].to_i
  repeat = (fields["Repeat"] == "true")

  if not repeat then
    iteration = 0 if score < ITERATION_RESET_BOUNDARY
    case iteration
    when 0
      interval = FIRST_INTERVAL
    when 1
      interval = SECOND_INTERVAL
    else
      interval = adjust_interval(interval, ef)
    end

    ef = adjust_efactor(ef, score)
  end

  fields["Due"] = (Date.today + interval).to_time
  fields["Repeat"] = score < REPEAT_BOUNDARY ? true : false
  fields["E-Factor"] = ef
  fields["Interval"] = interval
  fields["Iteration"] = iteration + 1

  return fields
end