Jldrill Git C0 Coverage Information - RCov

lib/jldrill/model/Quiz/ItemStats.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/jldrill/model/Quiz/ItemStats.rb 122 89
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 require 'jldrill/model/Quiz/Strategy'
2 require 'jldrill/model/Quiz/Timer'
3 
4 module JLDrill
5 
6     # Calculates and stores various statistics for each item in the
7     # Spaced Repetition Drill.
8     #
9     # Consecutive: The number of times this item was remembered correctly
10     #              in the review set
11     class ItemStats
12         CONSECUTIVE_RE = /^Consecutive: (.*)/
13         TIMELIMIT_RE = /^TimeLimit: (.*)/
14 
15         attr_reader :name, :item, :consecutive, :thinkingTimer, :timeLimit
16         attr_writer :item, :consecutive, :thinkingTimer, :timeLimit
17 
18         # Create a new ItemStats for this item
19         def initialize(item)
20             @name = "ItemStats"
21             @item = item
22             @thinkingTimer = Timer.new
23             reset
24         end
25 
26         # Parse a single part of the ItemStats
27         def parse(string)
28             parsed = true
29             case string
30                 when CONSECUTIVE_RE
31                     @consecutive = $1.to_i
32                 when TIMELIMIT_RE
33                     @timeLimit = $1.to_f
34             else
35                 parsed = false
36             end
37             parsed
38         end
39 
40         # Create a clone of the ItemStats and return it
41         def clone
42             retVal = ItemStats.new(@item)
43             retVal.assign(self)
44             return retVal
45         end
46 
47         # Assign this item's stats to be the same as the one passed in
48         def assign(itemStats)
49             @consecutive = itemStats.consecutive
50             @thinkingTimer.assign(itemStats.thinkingTimer)
51             @timeLimit = itemStats.timeLimit
52         end
53 
54         # Reset the statistics for the item
55         def reset
56             @consecutive = 0
57             @thinkingTimer.reset
58             @timeLimit = 0.0
59         end
60 
61         # The item is being used to create a problem
62         def createProblem
63             @thinkingTimer.reset
64             @thinkingTimer.start
65         end
66 
67         # The item was not correctly remembered
68         def incorrect
69             @thinkingTimer.stop
70             @consecutive = 0
71             @timeLimit = 0.0
72         end
73 
74         # The item was correctly remembered
75         def correct
76             @thinkingTimer.stop
77             if @item.bin == 4
78                 @consecutive += 1
79                 @timeLimit = @thinkingTimer.total
80             end
81         end
82 
83         def exp(number, places)
84             retVal = 1
85             if places != 0
86                 retVal = number
87                 1.upto(places - 1) do
88                     retVal = retVal * number
89                 end
90             end
91             retVal
92         end
93 
94 
95         def round(number, places)
96             mult = exp(10, places)
97             (number * mult).round.to_f / mult
98         end
99 
100         # Output the ItemStats in save format
101         def to_s
102             retVal = "/Consecutive: #{@consecutive.to_i}"
103             if @timeLimit != 0
104                 retVal += "/TimeLimit: #{self.round(@timeLimit, 3)}"
105             end
106             retVal
107         end
108 
109         def inNewSet?
110             @item.bin == Strategy.newSetBin
111         end
112 
113         def inWorkingSet?
114             Strategy.workingSetBins.include?(@item.bin)
115         end
116 
117         def inReviewSet?
118             @item.bin == Strategy.reviewSetBin
119         end
120 
121     end
122 end

Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8