Class: JLDrill::ItemStats

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ ItemStats

Create a new ItemStats for this item



20
21
22
23
24
25
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 20

def initialize(item)
    @name = "ItemStats"
    @item = item
    @thinkingTimer = Timer.new
    reset
end

Instance Attribute Details

#consecutiveObject

Returns the value of attribute consecutive.



16
17
18
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16

def consecutive
  @consecutive
end

#itemObject

Returns the value of attribute item.



16
17
18
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16

def item
  @item
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16

def name
  @name
end

#thinkingTimerObject

Returns the value of attribute thinkingTimer.



16
17
18
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 16

def thinkingTimer
  @thinkingTimer
end

#timeLimitObject

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

#cloneObject

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

#correctObject

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

#createProblemObject

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

#incorrectObject

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

Returns:

  • (Boolean)


110
111
112
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 110

def inNewSet?
    @item.bin == Strategy.newSetBin
end

#inReviewSet?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/jldrill/model/Quiz/ItemStats.rb', line 118

def inReviewSet?
    @item.bin == Strategy.reviewSetBin
end

#inWorkingSet?Boolean

Returns:

  • (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

#resetObject

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_sObject

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