Class: Engine::AnkiStrategy

Inherits:
BaseStrategy show all
Defined in:
lib/engine/strategies.rb

Constant Summary collapse

LEARNING_INTERVALS =
[0, 1, 10, 25].map(&:to_f)
INITIAL_INTERVALS =
[1, 2].map {|min| min*60*24 }.map(&:to_f)
LEARNING_STEPS =
LEARNING_INTERVALS.length - 1

Instance Attribute Summary

Attributes inherited from BaseStrategy

#card_state, #data_point

Instance Method Summary collapse

Instance Method Details

#learning?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/engine/strategies.rb', line 31

def learning?
  steps_to_graduation > 0
end

#next_factorObject



43
44
45
46
47
48
49
# File 'lib/engine/strategies.rb', line 43

def next_factor
  if learning?
    factor
  else
    [factor + [0.15, 0, -0.15, -0.3].fetch(neg_rating) {0}, 1.3].max
  end
end

#next_intervalObject



56
57
58
59
60
61
62
63
64
# File 'lib/engine/strategies.rb', line 56

def next_interval
  if learning?
    LEARNING_INTERVALS.fetch(-steps_to_graduation)
  else
    INITIAL_INTERVALS.fetch(next_streak) do
      interval * next_factor
    end
  end * (0.8 + pseudo_rand * 0.4) # 0.8 - 1.2
end

#next_streakObject



39
40
41
# File 'lib/engine/strategies.rb', line 39

def next_streak
  fail? || learning? ? 0 : streak + 1
end

#pseudo_randObject

Good enough for our purposes, and stable for a given card-state



52
53
54
# File 'lib/engine/strategies.rb', line 52

def pseudo_rand
  data_point.timestamp.to_f % 1
end

#steps_to_graduationObject



35
36
37
# File 'lib/engine/strategies.rb', line 35

def steps_to_graduation
  data_points.map(&:rating).inject(LEARNING_STEPS, :-)
end