Class: JLDrill::ItemStats
- Inherits:
-
Object
- Object
- JLDrill::ItemStats
- Defined in:
- lib/jldrill/model/Quiz/ItemStats.rb
Overview
Calculates and stores various statistics for each item in the Spaced Repetition Drill.
Consecutive: The number of times this item was remembered correctly
in the review set
Constant Summary collapse
- CONSECUTIVE_RE =
/^Consecutive: (.*)/
- TIMELIMIT_RE =
/^TimeLimit: (.*)/
Instance Attribute Summary collapse
-
#consecutive ⇒ Object
Returns the value of attribute consecutive.
-
#item ⇒ Object
Returns the value of attribute item.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#thinkingTimer ⇒ Object
Returns the value of attribute thinkingTimer.
-
#timeLimit ⇒ Object
Returns the value of attribute timeLimit.
Instance Method Summary collapse
-
#assign(itemStats) ⇒ Object
Assign this item’s stats to be the same as the one passed in.
-
#clone ⇒ Object
Create a clone of the ItemStats and return it.
-
#correct ⇒ Object
The item was correctly remembered.
-
#createProblem ⇒ Object
The item is being used to create a problem.
- #exp(number, places) ⇒ Object
-
#incorrect ⇒ Object
The item was not correctly remembered.
-
#initialize(item) ⇒ ItemStats
constructor
Create a new ItemStats for this item.
- #inNewSet? ⇒ Boolean
- #inReviewSet? ⇒ Boolean
- #inWorkingSet? ⇒ Boolean
-
#parse(string) ⇒ Object
Parse a single part of the ItemStats.
-
#reset ⇒ Object
Reset the statistics for the item.
- #round(number, places) ⇒ Object
-
#to_s ⇒ Object
Output the ItemStats in save format.
Constructor Details
Instance Attribute Details
#consecutive ⇒ Object
Returns the value of attribute consecutive.
16 17 18 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16 def consecutive @consecutive end |
#item ⇒ Object
Returns the value of attribute item.
16 17 18 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16 def item @item end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16 def name @name end |
#thinkingTimer ⇒ Object
Returns the value of attribute thinkingTimer.
16 17 18 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16 def thinkingTimer @thinkingTimer end |
#timeLimit ⇒ Object
Returns the value of attribute timeLimit.
16 17 18 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16 def timeLimit @timeLimit end |
Instance Method Details
#assign(itemStats) ⇒ Object
Assign this item’s stats to be the same as the one passed in
49 50 51 52 53 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 49 def assign(itemStats) @consecutive = itemStats.consecutive @thinkingTimer.assign(itemStats.thinkingTimer) @timeLimit = itemStats.timeLimit end |
#clone ⇒ Object
Create a clone of the ItemStats and return it
42 43 44 45 46 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 42 def clone retVal = ItemStats.new(@item) retVal.assign(self) return retVal end |
#correct ⇒ Object
The item was correctly remembered
76 77 78 79 80 81 82 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 76 def correct @thinkingTimer.stop if @item.bin == 4 @consecutive += 1 @timeLimit = @thinkingTimer.total end end |
#createProblem ⇒ Object
The item is being used to create a problem
63 64 65 66 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 63 def createProblem @thinkingTimer.reset @thinkingTimer.start end |
#exp(number, places) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 84 def exp(number, places) retVal = 1 if places != 0 retVal = number 1.upto(places - 1) do retVal = retVal * number end end retVal end |
#incorrect ⇒ Object
The item was not correctly remembered
69 70 71 72 73 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 69 def incorrect @thinkingTimer.stop @consecutive = 0 @timeLimit = 0.0 end |
#inNewSet? ⇒ Boolean
110 111 112 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 110 def inNewSet? @item.bin == Strategy.newSetBin end |
#inReviewSet? ⇒ Boolean
118 119 120 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 118 def inReviewSet? @item.bin == Strategy.reviewSetBin end |
#inWorkingSet? ⇒ Boolean
114 115 116 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 114 def inWorkingSet? Strategy.workingSetBins.include?(@item.bin) end |
#parse(string) ⇒ Object
Parse a single part of the ItemStats
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 28 def parse(string) parsed = true case string when CONSECUTIVE_RE @consecutive = $1.to_i when TIMELIMIT_RE @timeLimit = $1.to_f else parsed = false end parsed end |
#reset ⇒ Object
Reset the statistics for the item
56 57 58 59 60 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 56 def reset @consecutive = 0 @thinkingTimer.reset @timeLimit = 0.0 end |
#round(number, places) ⇒ Object
96 97 98 99 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 96 def round(number, places) mult = exp(10, places) (number * mult).round.to_f / mult end |
#to_s ⇒ Object
Output the ItemStats in save format
102 103 104 105 106 107 108 |
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 102 def to_s retVal = "/Consecutive: #{@consecutive.to_i}" if @timeLimit != 0 retVal += "/TimeLimit: #{self.round(@timeLimit, 3)}" end retVal end |