tworgy-spaced-repetition 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/spaced-repetition/sm2.rb +18 -11
- data/spec/lib/spaced-repetition/sm2_spec.rb +46 -30
- metadata +2 -2
@@ -16,6 +16,7 @@ module SuperMemo
|
|
16
16
|
self.quality_of_last_recall = nil
|
17
17
|
self.repetition_interval = nil
|
18
18
|
self.next_repetition = nil
|
19
|
+
self.last_studied = nil
|
19
20
|
end
|
20
21
|
|
21
22
|
def process_recall_result(quality_of_recall)
|
@@ -26,23 +27,28 @@ module SuperMemo
|
|
26
27
|
|
27
28
|
if quality_of_recall < 3
|
28
29
|
self.number_repetitions = 0
|
30
|
+
self.repetition_interval = 0
|
29
31
|
else
|
30
|
-
self.number_repetitions += 1
|
31
32
|
self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall)
|
32
|
-
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
if quality_of_recall == 3
|
35
|
+
self.repetition_interval = 0
|
36
|
+
else
|
37
|
+
self.number_repetitions += 1
|
38
|
+
|
39
|
+
case number_repetitions
|
40
|
+
when 1
|
41
|
+
self.repetition_interval = 1
|
42
|
+
when 2
|
43
|
+
self.repetition_interval = 6
|
44
|
+
else
|
45
|
+
self.repetition_interval = repetition_interval * easiness_factor
|
46
|
+
end
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
self.next_repetition = Date.today + repetition_interval
|
51
|
+
self.last_studied = Date.today
|
46
52
|
end
|
47
53
|
|
48
54
|
def scheduled_to_recall?
|
@@ -56,6 +62,7 @@ module SuperMemo
|
|
56
62
|
send(:quality_of_last_recall)
|
57
63
|
send(:next_repetition)
|
58
64
|
send(:repetition_interval)
|
65
|
+
send(:last_studied)
|
59
66
|
rescue NoMethodError => e
|
60
67
|
DBC.assert(false, e.message)
|
61
68
|
end
|
@@ -6,7 +6,8 @@ describe SuperMemo::SM2 do
|
|
6
6
|
|
7
7
|
it 'should work fine when including' do
|
8
8
|
class Temp
|
9
|
-
attr_accessor :easiness_factor, :number_repetitions,
|
9
|
+
attr_accessor :easiness_factor, :number_repetitions,
|
10
|
+
:quality_of_last_recall, :next_repetition, :repetition_interval, :last_studied
|
10
11
|
include SuperMemo::SM2
|
11
12
|
end
|
12
13
|
|
@@ -30,18 +31,19 @@ describe SuperMemo::SM2 do
|
|
30
31
|
describe 'exclude mixin' do
|
31
32
|
|
32
33
|
before :each do
|
33
|
-
@
|
34
|
+
@card = {
|
34
35
|
:easiness_factor => nil,
|
35
36
|
:number_repetitions => nil,
|
36
37
|
:quality_of_last_recall => nil,
|
37
38
|
:next_repetition => nil,
|
38
39
|
:repetition_interval => nil,
|
40
|
+
:last_studied => nil,
|
39
41
|
:question => "Who is the most awesome of them all?",
|
40
42
|
:answer => 'Me!'
|
41
43
|
}.ostructify
|
42
44
|
|
43
|
-
@
|
44
|
-
@
|
45
|
+
@card.extend SuperMemo::SM2
|
46
|
+
@card.reset_spaced_repetition_data
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'should raise DBC exception if class extended is missing fields' do
|
@@ -49,49 +51,63 @@ describe SuperMemo::SM2 do
|
|
49
51
|
end
|
50
52
|
|
51
53
|
it 'should initialize values' do
|
52
|
-
@
|
53
|
-
@
|
54
|
-
@
|
55
|
-
@
|
56
|
-
@
|
54
|
+
@card.easiness_factor.should == 2.5
|
55
|
+
@card.number_repetitions.should == 0
|
56
|
+
@card.repetition_interval.should == nil
|
57
|
+
@card.quality_of_last_recall.should == nil
|
58
|
+
@card.next_repetition.should == nil
|
59
|
+
@card.last_studied.should == nil
|
57
60
|
end
|
58
61
|
|
59
62
|
it 'should schedule next repetition for tomorrow if repetition_interval = 0 and quality_of_last_recall = 4' do
|
60
|
-
@
|
63
|
+
@card.process_recall_result(4)
|
61
64
|
|
62
|
-
@
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
65
|
+
@card.number_repetitions.should == 1
|
66
|
+
@card.repetition_interval.should == 1
|
67
|
+
@card.last_studied.should == Date.today
|
68
|
+
@card.next_repetition.should == (Date.today + 1)
|
69
|
+
@card.easiness_factor.should be_close(2.5, 0.01)
|
66
70
|
end
|
67
71
|
|
68
72
|
it 'should schedule next repetition for 6 days if repetition_interval = 1 and quality_of_last_recall = 4' do
|
69
|
-
@
|
70
|
-
@
|
73
|
+
@card.process_recall_result(4)
|
74
|
+
@card.process_recall_result(4)
|
71
75
|
|
72
|
-
@
|
73
|
-
@
|
74
|
-
@
|
75
|
-
@
|
76
|
+
@card.number_repetitions.should == 2
|
77
|
+
@card.repetition_interval.should == 6
|
78
|
+
@card.last_studied.should == Date.today
|
79
|
+
@card.next_repetition.should == (Date.today + 6)
|
80
|
+
@card.easiness_factor.should be_close(2.5, 0.01)
|
76
81
|
end
|
77
82
|
|
78
83
|
it 'should report as scheduled to recall (for today)' do
|
79
|
-
@
|
80
|
-
@
|
84
|
+
@card.next_repetition = Date.today
|
85
|
+
@card.scheduled_to_recall?.should == true
|
81
86
|
|
82
|
-
@
|
83
|
-
@
|
87
|
+
@card.next_repetition = Date.today - 1
|
88
|
+
@card.scheduled_to_recall?.should == true
|
84
89
|
end
|
85
90
|
|
86
91
|
it 'should not be scheduled to recall' do
|
87
|
-
@
|
88
|
-
@
|
92
|
+
@card.next_repetition = nil
|
93
|
+
@card.scheduled_to_recall?.should == false
|
89
94
|
|
90
|
-
@
|
91
|
-
@
|
95
|
+
@card.next_repetition = Date.today + 1
|
96
|
+
@card.scheduled_to_recall?.should == false
|
92
97
|
|
93
|
-
@
|
94
|
-
@
|
98
|
+
@card.next_repetition = Date.today + 99
|
99
|
+
@card.scheduled_to_recall?.should == false
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should require repeating items that scored 3' do
|
103
|
+
@card.process_recall_result(3)
|
104
|
+
@card.next_repetition.should == Date.today
|
105
|
+
|
106
|
+
@card.process_recall_result(3)
|
107
|
+
@card.next_repetition.should == Date.today
|
108
|
+
|
109
|
+
@card.process_recall_result(4)
|
110
|
+
@card.next_repetition.should == Date.today + 1
|
95
111
|
end
|
96
112
|
|
97
113
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tworgy-spaced-repetition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Holroyd
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-26 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|