Module: Lexdrill::Stats

Defined in:
lib/lexdrill/stats.rb

Overview

Tracks how many times each word/phrase has been shown by next, persisted as a word => count JSON object at .drill.stats (same base path as .drill.txt/.drill.counter). Every BUCKET_SIZE shows moves a word into the next display-color bucket (see Lexdrill::Colorizer); once a word reaches GRADUATION_THRESHOLD shows it's considered mastered and next stops selecting it.

Constant Summary collapse

PATH =
Lexdrill::Config::STATS_PATH
BUCKET_SIZE =
100
GRADUATION_THRESHOLD =
1200

Class Method Summary collapse

Class Method Details

.countsObject



22
23
24
# File 'lib/lexdrill/stats.rb', line 22

def self.counts
  load
end

.graduated?(word) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/lexdrill/stats.rb', line 26

def self.graduated?(word)
  counts.fetch(word, 0) >= GRADUATION_THRESHOLD
end

.record(word) ⇒ Object



16
17
18
19
20
# File 'lib/lexdrill/stats.rb', line 16

def self.record(word)
  data = load
  data[word] = data.fetch(word, 0) + 1
  save(data)
end