Class: KeepYourHead::FlashcardTraining
- Inherits:
-
Object
- Object
- KeepYourHead::FlashcardTraining
- Defined in:
- lib/Keepyourhead/Training.rb
Constant Summary collapse
- StufenSkipTime =
in hours
[ 1, 3, 6, 1*24, 2*24, 4*24, 7*24, 14*24, 1*30*24, 2*30*24 ].map{ |h| h * 60 * 60 }
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#flashcard ⇒ Object
readonly
Returns the value of attribute flashcard.
-
#flashcards ⇒ Object
readonly
Returns the value of attribute flashcards.
-
#flashcardsAsked ⇒ Object
readonly
Returns the value of attribute flashcardsAsked.
-
#flashcardsKnown ⇒ Object
readonly
Returns the value of attribute flashcardsKnown.
-
#flashcardsUnknown ⇒ Object
readonly
Returns the value of attribute flashcardsUnknown.
-
#questionsMax ⇒ Object
readonly
Returns the value of attribute questionsMax.
-
#timeMax ⇒ Object
readonly
Returns the value of attribute timeMax.
-
#timeStarted ⇒ Object
readonly
Returns the value of attribute timeStarted.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(database, questionsMax, timeMax) ⇒ FlashcardTraining
constructor
timemax in seconds.
- #nextFlashcard ⇒ Object
- #onKnown ⇒ Object
- #onUnknown ⇒ Object
- #progressFlashcards ⇒ Object
- #progressTime ⇒ Object
- #timeUsed ⇒ Object
Constructor Details
#initialize(database, questionsMax, timeMax) ⇒ FlashcardTraining
timemax in seconds
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/Keepyourhead/Training.rb', line 42 def initialize( database, questionsMax, timeMax ) @stacksize = 7 @questionsMax, @timeMax = questionsMax, timeMax @flashcardsAsked = Set.new @flashcardsKnown = Set.new @flashcardsUnknown = Set.new @timeStarted = Time.now flashcardsAll = database.collectFlashcards.select { |fc| fc.active? } @flashcards = [] questionsMax.times { if flashcardsAll.length > 0 then idx = rand( flashcardsAll.length ) @flashcards << flashcardsAll.delete_at(idx) end } @countStart = @flashcards.length @flashcard = nil @database = database nextFlashcard end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
23 24 25 |
# File 'lib/Keepyourhead/Training.rb', line 23 def database @database end |
#flashcard ⇒ Object (readonly)
Returns the value of attribute flashcard.
21 22 23 |
# File 'lib/Keepyourhead/Training.rb', line 21 def flashcard @flashcard end |
#flashcards ⇒ Object (readonly)
Returns the value of attribute flashcards.
22 23 24 |
# File 'lib/Keepyourhead/Training.rb', line 22 def flashcards @flashcards end |
#flashcardsAsked ⇒ Object (readonly)
Returns the value of attribute flashcardsAsked.
29 30 31 |
# File 'lib/Keepyourhead/Training.rb', line 29 def flashcardsAsked @flashcardsAsked end |
#flashcardsKnown ⇒ Object (readonly)
Returns the value of attribute flashcardsKnown.
29 30 31 |
# File 'lib/Keepyourhead/Training.rb', line 29 def flashcardsKnown @flashcardsKnown end |
#flashcardsUnknown ⇒ Object (readonly)
Returns the value of attribute flashcardsUnknown.
29 30 31 |
# File 'lib/Keepyourhead/Training.rb', line 29 def flashcardsUnknown @flashcardsUnknown end |
#questionsMax ⇒ Object (readonly)
Returns the value of attribute questionsMax.
28 29 30 |
# File 'lib/Keepyourhead/Training.rb', line 28 def questionsMax @questionsMax end |
#timeMax ⇒ Object (readonly)
Returns the value of attribute timeMax.
26 27 28 |
# File 'lib/Keepyourhead/Training.rb', line 26 def timeMax @timeMax end |
#timeStarted ⇒ Object (readonly)
Returns the value of attribute timeStarted.
25 26 27 |
# File 'lib/Keepyourhead/Training.rb', line 25 def timeStarted @timeStarted end |
Instance Method Details
#close ⇒ Object
124 125 126 |
# File 'lib/Keepyourhead/Training.rb', line 124 def close database.saveAllChanged end |
#nextFlashcard ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/Keepyourhead/Training.rb', line 111 def nextFlashcard # if @flashcards.length > 0 and progressTime < 1.0 then if progressFlashcards < 1.0 and progressTime < 1.0 then assert @flashcards.length > 0 idx = rand( [@flashcards.length, @stacksize].min ) @flashcard = @flashcards.delete_at( @flashcards.length - 1 - idx ) @flashcards.push @flashcard else @flashcard = nil end end |
#onKnown ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/Keepyourhead/Training.rb', line 72 def onKnown @flashcardsKnown << @flashcard @flashcardsAsked << @flashcard @flashcard.nextCheck = Time.now + StufenSkipTime[[@flashcard.level, StufenSkipTime.length-1].min] @flashcard.level = @flashcard.level + 1 @flashcards.pop nextFlashcard end |
#onUnknown ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/Keepyourhead/Training.rb', line 84 def onUnknown @flashcardsUnknown << @flashcard @flashcardsAsked << @flashcard @flashcard.nextCheck = Time.now - 60 @flashcard.level = 0 nextFlashcard end |
#progressFlashcards ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/Keepyourhead/Training.rb', line 95 def progressFlashcards if @countStart > 0 then (@countStart - @flashcards.length) / @countStart else 1.0 end end |
#progressTime ⇒ Object
107 108 109 |
# File 'lib/Keepyourhead/Training.rb', line 107 def progressTime (Time.now - @timeStarted) / @timeMax end |
#timeUsed ⇒ Object
103 104 105 |
# File 'lib/Keepyourhead/Training.rb', line 103 def timeUsed Time.now - @timeStarted end |