repetition 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/repetition.rb +55 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ddc157aefb4b1de78b340222a915e74108558f92
4
+ data.tar.gz: 305bfd203fe920f793a306d21a24f01a38bfe7e6
5
+ SHA512:
6
+ metadata.gz: 0a829dd1a5d6b25cf2e996fde8740a05d55ec66e8db6977080e96d0023deb5ebc33757008315fd99054a4bcd5f5f718ecaa7030e0e16e667db2fe3e585965db5
7
+ data.tar.gz: 142a5b00ded611ff6e2f28ba52f8ea5511ced9a11b8881a491273623cd327d08d603720359303956bc08781fabe75461035cfb3584b7249157aa9e10e7dc3dfc
@@ -0,0 +1,55 @@
1
+ module Repetition
2
+ def reset_spaced_repetition_data
3
+ self.easiness_factor = 2.5
4
+ self.number_repetitions = 0
5
+ self.quality_of_last_recall = nil
6
+ self.repetition_interval = nil
7
+ self.next_repetition = nil
8
+ self.last_studied = nil
9
+ end
10
+
11
+ def process_recall_result(quality_of_recall)
12
+ unless (0..5).include?(quality_of_recall)
13
+ raise 'Invalid quality of recall. Should be in range from 0 to 5.'
14
+ end
15
+
16
+ if quality_of_recall < 3
17
+ self.number_repetitions = 0
18
+ self.repetition_interval = 0
19
+ else
20
+ self.easiness_factor = calculate_easiness_factor(easiness_factor, quality_of_recall)
21
+
22
+ if quality_of_recall == 3
23
+ self.repetition_interval = 0
24
+ else
25
+ self.number_repetitions += 1
26
+
27
+ case number_repetitions
28
+ when 1
29
+ self.repetition_interval = 1
30
+ when 2
31
+ self.repetition_interval = 6
32
+ else
33
+ self.repetition_interval = repetition_interval * easiness_factor
34
+ end
35
+ end
36
+ end
37
+
38
+ self.next_repetition = Date.today + repetition_interval
39
+ self.last_studied = Date.today
40
+ end
41
+
42
+ def scheduled_to_recall?
43
+ !next_repetition.nil? && next_repetition <= Date.today
44
+ end
45
+
46
+ private
47
+
48
+ def calculate_easiness_factor(easiness_factor, quality_of_recall)
49
+ q = quality_of_recall
50
+ ef_old = easiness_factor
51
+
52
+ result = ef_old - 0.8 + (0.28 * q) - (0.02 * q * q)
53
+ result < 1.3 ? 1.3 : result
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repetition
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Danya Kim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Spaced repetition algorithm (SuperMemo 2) module that can be used as
14
+ a mixin
15
+ email: itsdanya@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/repetition.rb
21
+ homepage: http://github.com/danyakim/repetition
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Spaced repetition algorithm
45
+ test_files: []