active_recall 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +23 -0
- data/README.md +123 -0
- data/Rakefile +8 -0
- data/active_recall.gemspec +42 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/lib/active_recall.rb +11 -0
- data/lib/active_recall/algorithms/leitner_system.rb +60 -0
- data/lib/active_recall/base.rb +16 -0
- data/lib/active_recall/deck_methods.rb +20 -0
- data/lib/active_recall/item_methods.rb +17 -0
- data/lib/active_recall/models/deck.rb +97 -0
- data/lib/active_recall/models/item.rb +33 -0
- data/lib/active_recall/version.rb +5 -0
- data/lib/generators/active_recall/active_recall_generator.rb +35 -0
- data/lib/generators/active_recall/templates/add_active_recall_item_answer_counts.rb +13 -0
- data/lib/generators/active_recall/templates/create_active_recall_tables.rb +26 -0
- data/lib/generators/active_recall/templates/migrate_okubo_to_active_recall.rb +30 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23d2bc7c301e4f8414d1f922f66647fb95312ee96987c9c9616eb746a24f8969
|
4
|
+
data.tar.gz: ca1cc3c4178ed1cfe7773ec6654356da5cd56cd97ffe2992920939ebaecb9674
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa6f8bfc09eff467cf8393e5edde292ad49bb8ad129e8bf03d5ea8372b1bc1ba501675264e393052eb081849cb59ac1fbe74af50b69b35a53040539ed1f3e53b
|
7
|
+
data.tar.gz: cd53131d9482b62010135d5d4354fbbf398e9eb4ff5019b8f9046ea7d80599f05444bfc5db4150b2da70dc637628c2e60a5d12c7a3bdb8b1c4f3084439e80d34
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_recall (1.0.0)
|
5
|
+
activerecord (~> 5.2.3)
|
6
|
+
activesupport (~> 5.2.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.2.3)
|
12
|
+
activesupport (= 5.2.3)
|
13
|
+
activerecord (5.2.3)
|
14
|
+
activemodel (= 5.2.3)
|
15
|
+
activesupport (= 5.2.3)
|
16
|
+
arel (>= 9.0)
|
17
|
+
activesupport (5.2.3)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (9.0.0)
|
23
|
+
concurrent-ruby (1.1.5)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
i18n (1.6.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
minitest (5.11.3)
|
28
|
+
rake (10.5.0)
|
29
|
+
rdoc (6.2.0)
|
30
|
+
rspec (3.8.0)
|
31
|
+
rspec-core (~> 3.8.0)
|
32
|
+
rspec-expectations (~> 3.8.0)
|
33
|
+
rspec-mocks (~> 3.8.0)
|
34
|
+
rspec-core (3.8.2)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-expectations (3.8.4)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-mocks (3.8.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-support (3.8.2)
|
43
|
+
sqlite3 (1.4.1)
|
44
|
+
thread_safe (0.3.6)
|
45
|
+
tzinfo (1.2.5)
|
46
|
+
thread_safe (~> 0.1)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
active_recall!
|
53
|
+
bundler (~> 1.16)
|
54
|
+
rake (~> 10.0)
|
55
|
+
rdoc
|
56
|
+
rspec (~> 3.0)
|
57
|
+
sqlite3
|
58
|
+
|
59
|
+
RUBY VERSION
|
60
|
+
ruby 2.5.3p105
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2012 Robert Gravina
|
2
|
+
Copyright (c) 2019 Jayson Virissimo
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# ActiveRecall [![Build Status](https://travis-ci.org/jaysonvirissimo/active_recall.svg?branch=master)](https://travis-ci.org/jaysonvirissimo/active_recall)
|
2
|
+
|
3
|
+
**ActiveRecall** is a spaced-repetition system that allows you to treat arbitrary [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord) models as if they were flashcards to be learned and reviewed.
|
4
|
+
It it based on, and is intended to be backwards compatible with, the [okubo](https://github.com/rgravina/okubo) gem.
|
5
|
+
The primary differentiating features are that it lets the user specify the scheduling algorithm and is fully compatible with Rails 6.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'active_recall'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
$ rails generate active_recall
|
19
|
+
$ rails db:migrate
|
20
|
+
|
21
|
+
Or, if you were using the Okubo gem and want to migrate your data over, execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
$ rails generate active_recall --migrate_data true
|
25
|
+
$ rails db:migrate
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install active_recall
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Assume you have an application allowing your users to study words in a foreign language. Using the <code>has_deck</code> method
|
34
|
+
you can set up a deck of flashcards that the user will study:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Word < ActiveRecord::Base
|
38
|
+
end
|
39
|
+
|
40
|
+
class User < ActiveRecord::Base
|
41
|
+
has_deck :words
|
42
|
+
end
|
43
|
+
|
44
|
+
user = User.create!(:name => "Robert")
|
45
|
+
word = Word.create!(:kanji => "日本語", :kana => "にほんご", :translation => "Japanese language")
|
46
|
+
```
|
47
|
+
|
48
|
+
You can add words and record attempts to guess the word as right or wrong. Various methods exist to allow you to access subsets of this collection:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Initally adding a word
|
52
|
+
user.words << word
|
53
|
+
user.words.untested #=> [word]
|
54
|
+
|
55
|
+
# Guessing a word correctly
|
56
|
+
user.right_answer_for!(word)
|
57
|
+
user.words.known #=> [word]
|
58
|
+
|
59
|
+
# Guessing a word incorrectly
|
60
|
+
user.wrong_answer_for!(word)
|
61
|
+
user.words.failed #=> [word]
|
62
|
+
|
63
|
+
# Listing all words
|
64
|
+
user.words #=> [word]
|
65
|
+
```
|
66
|
+
|
67
|
+
As time passes words need to be reviewed to keep them fresh in memory:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Three days later...
|
71
|
+
user.words.known #=> []
|
72
|
+
user.words.expired #=> [word]
|
73
|
+
```
|
74
|
+
|
75
|
+
Guessing a word correcly several times in a row results in the word taking longer to expire, and demonstrates mastery of that word.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
user.right_answer_for!(word)
|
79
|
+
# One week later...
|
80
|
+
user.words.expired #=> [word]
|
81
|
+
user.right_answer_for!(word)
|
82
|
+
# Two weeks later...
|
83
|
+
user.words.expired #=> [word]
|
84
|
+
user.right_answer_for!(word)
|
85
|
+
# One month later...
|
86
|
+
user.words.expired #=> [word]
|
87
|
+
```
|
88
|
+
|
89
|
+
Reviewing
|
90
|
+
---------
|
91
|
+
|
92
|
+
In addition to an <code>expired</code> method, ActiveRecall provides a suggested reviewing sequence for all unknown words in the deck.
|
93
|
+
Words are randomly chosen from all untested words, failed, and finally expired in order of precedence.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
user.words.review #=> [word]
|
97
|
+
user.right_answer_for!(word)
|
98
|
+
# ... continuing until all untested, failed, and expired words have been guessed correctly.
|
99
|
+
user.words.review #=> []
|
100
|
+
```
|
101
|
+
|
102
|
+
You can also just get the next word to review:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
user.words.next #=> word
|
106
|
+
user.right_answer_for!(word)
|
107
|
+
# ... continuing until all untested, failed, and expired words have been guessed correctly.
|
108
|
+
user.words.next #=> nil
|
109
|
+
```
|
110
|
+
|
111
|
+
## Development
|
112
|
+
|
113
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
114
|
+
|
115
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jaysonvirissimo/active_recall.
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'active_recall/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'active_recall'
|
9
|
+
spec.version = ActiveRecall::VERSION
|
10
|
+
spec.authors = ['Robert Gravina', 'Jayson Virissimo']
|
11
|
+
spec.email = ['robert.gravina@gmail.com', 'jayson.virissimo@asu.edu']
|
12
|
+
spec.summary = 'A spaced-repetition system'
|
13
|
+
spec.description = 'A spaced-repetition system to be used with ActiveRecord models'
|
14
|
+
spec.homepage = 'https://github.com/jaysonvirissimo/active_recall'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rdoc'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
+
spec.add_development_dependency 'sqlite3'
|
40
|
+
spec.add_runtime_dependency 'activerecord', '~> 5.2.3'
|
41
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.2.3'
|
42
|
+
end
|
data/bin/console
ADDED
File without changes
|
data/bin/setup
ADDED
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_recall/base'
|
4
|
+
require 'active_recall/deck_methods'
|
5
|
+
require 'active_recall/item_methods'
|
6
|
+
require 'active_recall/algorithms/leitner_system'
|
7
|
+
require 'active_recall/models/deck'
|
8
|
+
require 'active_recall/models/item'
|
9
|
+
require 'active_recall/version'
|
10
|
+
|
11
|
+
ActiveRecord::Base.send(:include, ActiveRecall::Base)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
class LeitnerSystem
|
5
|
+
DELAYS = [3, 7, 14, 30, 60, 120, 240].freeze
|
6
|
+
|
7
|
+
def self.right(box:, current_time: Time.current, times_right:, times_wrong:)
|
8
|
+
new(
|
9
|
+
box: box,
|
10
|
+
current_time: current_time,
|
11
|
+
times_right: times_right,
|
12
|
+
times_wrong: times_wrong
|
13
|
+
).right
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.wrong(box:, current_time: Time.current, times_right:, times_wrong:)
|
17
|
+
new(
|
18
|
+
box: box,
|
19
|
+
current_time: current_time,
|
20
|
+
times_right: times_right,
|
21
|
+
times_wrong: times_wrong
|
22
|
+
).wrong
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(box:, current_time: Time.current, times_right:, times_wrong:)
|
26
|
+
@box = box
|
27
|
+
@current_time = current_time
|
28
|
+
@times_right = times_right
|
29
|
+
@times_wrong = times_wrong
|
30
|
+
end
|
31
|
+
|
32
|
+
def right
|
33
|
+
{
|
34
|
+
box: box + 1,
|
35
|
+
times_right: times_right + 1,
|
36
|
+
times_wrong: times_wrong,
|
37
|
+
last_reviewed: current_time,
|
38
|
+
next_review: next_review
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def wrong
|
43
|
+
{
|
44
|
+
box: 0,
|
45
|
+
times_right: times_right,
|
46
|
+
times_wrong: times_wrong + 1,
|
47
|
+
last_reviewed: current_time,
|
48
|
+
next_review: nil
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
attr_reader :box, :current_time, :times_right, :times_wrong
|
55
|
+
|
56
|
+
def next_review
|
57
|
+
(current_time + DELAYS[[DELAYS.count, box + 1].min - 1].days)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
module Base
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
module ClassMethods
|
7
|
+
def has_deck(name)
|
8
|
+
define_method(:deck_name) { name }
|
9
|
+
include ActiveRecall::DeckMethods
|
10
|
+
include ActiveRecall::ItemMethods
|
11
|
+
define_method(name) { deck }
|
12
|
+
after_destroy(:remove_deck)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
module DeckMethods
|
5
|
+
def deck
|
6
|
+
d = ActiveRecall::Deck.where(user_id: id, user_type: self.class.name).first_or_create
|
7
|
+
d.source_class.module_eval do
|
8
|
+
def stats
|
9
|
+
ActiveRecall::Item.where(source_id: id, source_type: self.class.name).first
|
10
|
+
end
|
11
|
+
end
|
12
|
+
d
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_deck
|
16
|
+
deck = ActiveRecall::Deck.where(user_id: id, user_type: self.class.name).first
|
17
|
+
deck.destroy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
module ItemMethods
|
5
|
+
def right_answer_for!(item)
|
6
|
+
i = deck.items.where(source_id: item.id).first
|
7
|
+
i.right!
|
8
|
+
i.save!
|
9
|
+
end
|
10
|
+
|
11
|
+
def wrong_answer_for!(item)
|
12
|
+
i = deck.items.where(source_id: item.id).first
|
13
|
+
i.wrong!
|
14
|
+
i.save!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
class Deck < ActiveRecord::Base
|
5
|
+
include Enumerable
|
6
|
+
include ActiveRecall::Base
|
7
|
+
self.table_name = 'active_recall_decks'
|
8
|
+
belongs_to :user, polymorphic: true
|
9
|
+
has_many :items, class_name: 'ActiveRecall::Item', dependent: :destroy
|
10
|
+
|
11
|
+
def each
|
12
|
+
_items.each do |item|
|
13
|
+
if block_given?
|
14
|
+
yield item
|
15
|
+
else
|
16
|
+
yield item
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
_items == other
|
23
|
+
end
|
24
|
+
|
25
|
+
def _items
|
26
|
+
source_class.find(items.pluck(:source_id))
|
27
|
+
end
|
28
|
+
|
29
|
+
def <<(source)
|
30
|
+
raise ArgumentError, 'Word already in the stack' if include?(source)
|
31
|
+
|
32
|
+
items << ActiveRecall::Item.new(deck: self, source_id: source.id, source_type: source.class.name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.add_deck(user)
|
36
|
+
create!(user)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(source)
|
40
|
+
item = ActiveRecall::Item.new(deck: self, source_id: source.id, source_type: source.class.name)
|
41
|
+
item.destroy
|
42
|
+
end
|
43
|
+
|
44
|
+
def review
|
45
|
+
%i[untested failed expired].inject([]) do |words, s|
|
46
|
+
words += items.send(s).order(random_order_function).map(&:source)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def next
|
51
|
+
word = nil
|
52
|
+
%i[untested failed expired].each do |category|
|
53
|
+
word = items.send(category).order(random_order_function).limit(1).map(&:source).first
|
54
|
+
break if word
|
55
|
+
end
|
56
|
+
word
|
57
|
+
end
|
58
|
+
|
59
|
+
def last
|
60
|
+
items.order('created_at desc').limit(1).first.try(:source)
|
61
|
+
end
|
62
|
+
|
63
|
+
def untested
|
64
|
+
source_class.find(items.untested.pluck(:source_id))
|
65
|
+
end
|
66
|
+
|
67
|
+
def failed
|
68
|
+
source_class.find(items.failed.pluck(:source_id))
|
69
|
+
end
|
70
|
+
|
71
|
+
def known
|
72
|
+
source_class.find(items.known.pluck(:source_id))
|
73
|
+
end
|
74
|
+
|
75
|
+
def expired
|
76
|
+
source_class.find(items.expired.pluck(:source_id))
|
77
|
+
end
|
78
|
+
|
79
|
+
def box(number)
|
80
|
+
source_class.find(items.where(box: number).pluck(:source_id))
|
81
|
+
end
|
82
|
+
|
83
|
+
def source_class
|
84
|
+
user.deck_name.to_s.singularize.titleize.constantize
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def random_order_function
|
90
|
+
Arel.sql(mysql? ? 'RAND()' : 'random()')
|
91
|
+
end
|
92
|
+
|
93
|
+
def mysql?
|
94
|
+
source_class.connection.adapter_name == 'Mysql2'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecall
|
4
|
+
class Item < ActiveRecord::Base
|
5
|
+
self.table_name = 'active_recall_items'
|
6
|
+
belongs_to :deck
|
7
|
+
belongs_to :source, polymorphic: true
|
8
|
+
scope :untested, -> { where(['box = ? and last_reviewed is null', 0]) }
|
9
|
+
scope :failed, -> { where(['box = ? and last_reviewed is not null', 0]) }
|
10
|
+
|
11
|
+
def self.expired(current_time: Time.current)
|
12
|
+
where(['box > ? and next_review <= ?', 0, current_time])
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.known(current_time: Time.current)
|
16
|
+
where(['box > ? and next_review > ?', 0, current_time])
|
17
|
+
end
|
18
|
+
|
19
|
+
def right!
|
20
|
+
update!(LeitnerSystem.right(scoring_attributes))
|
21
|
+
end
|
22
|
+
|
23
|
+
def wrong!
|
24
|
+
update!(LeitnerSystem.wrong(scoring_attributes))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def scoring_attributes
|
30
|
+
attributes.symbolize_keys.slice(:box, :times_right, :times_wrong)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
require 'rails/generators/active_record'
|
6
|
+
|
7
|
+
class ActiveRecallGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
class_option :migrate_data, type: :boolean, default: false
|
11
|
+
|
12
|
+
desc 'Creates migration files required by the active_recall spaced repetition gem.'
|
13
|
+
|
14
|
+
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
15
|
+
|
16
|
+
def self.next_migration_number(path)
|
17
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_migration_files
|
21
|
+
create_migration_file_if_not_exist 'create_active_recall_tables'
|
22
|
+
create_migration_file_if_not_exist 'add_active_recall_item_answer_counts'
|
23
|
+
if options['migrate_data']
|
24
|
+
create_migration_file_if_not_exist 'migrate_okubo_to_active_recall'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def create_migration_file_if_not_exist(file_name)
|
31
|
+
unless self.class.migration_exists?(File.dirname(File.expand_path("db/migrate/#{file_name}")), file_name)
|
32
|
+
migration_template "#{file_name}.rb", "db/migrate/#{file_name}.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddActiveRecallItemAnswerCounts < ActiveRecord::Migration[5.2]
|
4
|
+
def self.up
|
5
|
+
add_column :active_recall_items, :times_right, :integer, default: 0
|
6
|
+
add_column :active_recall_items, :times_wrong, :integer, default: 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
remove_column :active_recall_items, :times_right
|
11
|
+
remove_column :active_recall_items, :times_wrong
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateActiveRecallTables < ActiveRecord::Migration[5.2]
|
4
|
+
def self.up
|
5
|
+
create_table :active_recall_decks do |t|
|
6
|
+
t.references :user, polymorphic: true
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :active_recall_decks, %i[user_id user_type]
|
10
|
+
|
11
|
+
create_table :active_recall_items do |t|
|
12
|
+
t.references :deck
|
13
|
+
t.references :source, polymorphic: true
|
14
|
+
t.integer :box, default: 0
|
15
|
+
t.timestamp :last_reviewed
|
16
|
+
t.timestamp :next_review
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
add_index :active_recall_items, %i[source_id source_type]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
drop_table :active_recall_decks
|
24
|
+
drop_table :active_recall_items
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MigrateOkuboToActiveRecall < ActiveRecord::Migration[5.2]
|
4
|
+
DECK_SQL = 'SELECT "okubo_decks".* FROM "okubo_decks"'
|
5
|
+
ITEM_SQL = 'SELECT "okubo_items".* FROM "okubo_items"'
|
6
|
+
|
7
|
+
def self.up
|
8
|
+
connection = ActiveRecord::Base.connection
|
9
|
+
decks = connection.execute(DECK_SQL).to_a.map(&:symbolize_keys)
|
10
|
+
items = connection.execute(ITEM_SQL).to_a.map(&:symbolize_keys)
|
11
|
+
|
12
|
+
decks.each do |deck_attributes|
|
13
|
+
deck_create_attributes = deck_attributes.except(:id, :created_at, :updated_at)
|
14
|
+
deck = ActiveRecall::Deck.create!(deck_create_attributes)
|
15
|
+
|
16
|
+
items.select do |item_attributes|
|
17
|
+
deck_attributes[:id] == item_attributes[:deck_id]
|
18
|
+
end.each do |item_attributes|
|
19
|
+
item_create_attributes = item_attributes
|
20
|
+
.except(:id, :created_at, :updated_at)
|
21
|
+
.merge(deck_id: deck.id)
|
22
|
+
ActiveRecall::Item.create!(item_create_attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.down
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_recall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Gravina
|
8
|
+
- Jayson Virissimo
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-09-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.16'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.16'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rdoc
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: sqlite3
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: activerecord
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 5.2.3
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 5.2.3
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: activesupport
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 5.2.3
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 5.2.3
|
112
|
+
description: A spaced-repetition system to be used with ActiveRecord models
|
113
|
+
email:
|
114
|
+
- robert.gravina@gmail.com
|
115
|
+
- jayson.virissimo@asu.edu
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".ruby-version"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- active_recall.gemspec
|
130
|
+
- bin/console
|
131
|
+
- bin/setup
|
132
|
+
- lib/active_recall.rb
|
133
|
+
- lib/active_recall/algorithms/leitner_system.rb
|
134
|
+
- lib/active_recall/base.rb
|
135
|
+
- lib/active_recall/deck_methods.rb
|
136
|
+
- lib/active_recall/item_methods.rb
|
137
|
+
- lib/active_recall/models/deck.rb
|
138
|
+
- lib/active_recall/models/item.rb
|
139
|
+
- lib/active_recall/version.rb
|
140
|
+
- lib/generators/active_recall/active_recall_generator.rb
|
141
|
+
- lib/generators/active_recall/templates/add_active_recall_item_answer_counts.rb
|
142
|
+
- lib/generators/active_recall/templates/create_active_recall_tables.rb
|
143
|
+
- lib/generators/active_recall/templates/migrate_okubo_to_active_recall.rb
|
144
|
+
homepage: https://github.com/jaysonvirissimo/active_recall
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata:
|
148
|
+
allowed_push_host: https://rubygems.org/
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.7.6
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: A spaced-repetition system
|
169
|
+
test_files: []
|