From 47c30f172fd62293289d3c81e627fb8c10234631 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 22 Apr 2011 06:45:04 +0900 Subject: [PATCH] fix issues suspending learning cards - cards in final review are first reset as rev cards so that type==queue and they can be restored correctly - new cards in learning have type set to 1 so they too can be restored correctly --- anki/sched.py | 12 +++++++++-- tests/test_sched.py | 51 ++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/anki/sched.py b/anki/sched.py index 4b7508bdb..2e80259a2 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -49,6 +49,7 @@ class Scheduler(object): if card.queue == 0: # put it in the learn queue card.queue = 1 + card.type = 1 if card.queue == 1: self._answerLrnCard(card, ease) elif card.queue == 2: @@ -382,13 +383,17 @@ limit %d""" % (self._groupLimit(), self.reportLimit), lim=self.dayCutoff) time.sleep(0.01) log() - def removeFailed(self): + def removeFailed(self, ids=None): "Remove failed cards from the learning queue." + extra = "" + if ids: + extra = " and id in "+ids2str(ids) self.deck.db.execute(""" update cards set due = edue, queue = 2, mod = %d where queue = 1 and type = 2 -""" % intTime()) +%s +""" % (intTime(), extra)) # Reviews ########################################################################## @@ -694,6 +699,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % ( def suspendCards(self, ids): "Suspend cards." + self.removeFailed(ids) self.deck.db.execute( "update cards set queue = -1, mod = ? where id in "+ ids2str(ids), intTime()) @@ -708,6 +714,8 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % ( def buryFact(self, fid): "Bury all cards for fact until next session." self.deck.setDirty() + self.removeFailed( + self.deck.db.list("select id from cards where fid = ?", fid)) self.deck.db.execute("update cards set queue = -2 where fid = ?", fid) # Counts diff --git a/tests/test_sched.py b/tests/test_sched.py index 47bd63503..1f300502a 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -28,7 +28,7 @@ def test_new(): t = intTime() d.sched.answerCard(c, 1) assert c.queue == 1 - assert c.type == 0 + assert c.type == 1 assert c.due >= t # the default order should ensure siblings are not seen together, and # should show all cards @@ -96,7 +96,7 @@ def test_learn(): # pass it once d.sched.answerCard(c, 2) # it should by due in 3 minutes - assert round(c.due - time.time()) == 180 + assert round(c.due - time.time()) in (179, 180) # and it should be grade 1 now assert c.grade == 1 assert c.cycles == 2 @@ -108,13 +108,13 @@ def test_learn(): # pass again d.sched.answerCard(c, 2) # it should by due in 10 minutes - assert round(c.due - time.time()) == 600 + assert round(c.due - time.time()) in (599, 600) # and it should be grade 1 now assert c.grade == 2 assert c.cycles == 3 # the next pass should graduate the card assert c.queue == 1 - assert c.type == 0 + assert c.type == 1 d.sched.answerCard(c, 2) assert c.queue == 2 assert c.type == 2 @@ -309,19 +309,9 @@ def test_nextIvl(): def test_misc(): d = getEmptyDeck() f = d.newFact() - f['Front'] = u"one"; f['Back'] = u"two" + f['Front'] = u"one" d.addFact(f) c = f.cards()[0] - # suspending - d.reset() - assert d.sched.getCard() - d.sched.suspendCards([c.id]) - d.reset() - assert not d.sched.getCard() - # unsuspending - d.sched.unsuspendCards([c.id]) - d.reset() - assert d.sched.getCard() # burying d.sched.buryFact(c.fid) d.reset() @@ -337,6 +327,37 @@ def test_misc(): assert d.sched.timeToday() > 0 assert d.sched.repsToday() == 1 +def test_suspend(): + d = getEmptyDeck() + f = d.newFact() + f['Front'] = u"one" + d.addFact(f) + c = f.cards()[0] + # suspending + d.reset() + assert d.sched.getCard() + d.sched.suspendCards([c.id]) + d.reset() + assert not d.sched.getCard() + # unsuspending + d.sched.unsuspendCards([c.id]) + d.reset() + assert d.sched.getCard() + # should cope with rev cards being relearnt + c.due = 0; c.ivl = 100; c.type = 2; c.queue = 2; c.flush() + d.reset() + c = d.sched.getCard() + d.sched.answerCard(c, 1) + assert c.due >= time.time() + assert c.queue == 1 + assert c.type == 2 + d.sched.suspendCards([c.id]) + d.sched.unsuspendCards([c.id]) + c.load() + assert c.queue == 2 + assert c.type == 2 + assert c.due == 1 + def test_cram(): d = getEmptyDeck() f = d.newFact()