mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
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
This commit is contained in:
parent
6946dc2eaa
commit
47c30f172f
2 changed files with 46 additions and 17 deletions
|
@ -49,6 +49,7 @@ class Scheduler(object):
|
||||||
if card.queue == 0:
|
if card.queue == 0:
|
||||||
# put it in the learn queue
|
# put it in the learn queue
|
||||||
card.queue = 1
|
card.queue = 1
|
||||||
|
card.type = 1
|
||||||
if card.queue == 1:
|
if card.queue == 1:
|
||||||
self._answerLrnCard(card, ease)
|
self._answerLrnCard(card, ease)
|
||||||
elif card.queue == 2:
|
elif card.queue == 2:
|
||||||
|
@ -382,13 +383,17 @@ limit %d""" % (self._groupLimit(), self.reportLimit), lim=self.dayCutoff)
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
log()
|
log()
|
||||||
|
|
||||||
def removeFailed(self):
|
def removeFailed(self, ids=None):
|
||||||
"Remove failed cards from the learning queue."
|
"Remove failed cards from the learning queue."
|
||||||
|
extra = ""
|
||||||
|
if ids:
|
||||||
|
extra = " and id in "+ids2str(ids)
|
||||||
self.deck.db.execute("""
|
self.deck.db.execute("""
|
||||||
update cards set
|
update cards set
|
||||||
due = edue, queue = 2, mod = %d
|
due = edue, queue = 2, mod = %d
|
||||||
where queue = 1 and type = 2
|
where queue = 1 and type = 2
|
||||||
""" % intTime())
|
%s
|
||||||
|
""" % (intTime(), extra))
|
||||||
|
|
||||||
# Reviews
|
# Reviews
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -694,6 +699,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
|
|
||||||
def suspendCards(self, ids):
|
def suspendCards(self, ids):
|
||||||
"Suspend cards."
|
"Suspend cards."
|
||||||
|
self.removeFailed(ids)
|
||||||
self.deck.db.execute(
|
self.deck.db.execute(
|
||||||
"update cards set queue = -1, mod = ? where id in "+
|
"update cards set queue = -1, mod = ? where id in "+
|
||||||
ids2str(ids), intTime())
|
ids2str(ids), intTime())
|
||||||
|
@ -708,6 +714,8 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
def buryFact(self, fid):
|
def buryFact(self, fid):
|
||||||
"Bury all cards for fact until next session."
|
"Bury all cards for fact until next session."
|
||||||
self.deck.setDirty()
|
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)
|
self.deck.db.execute("update cards set queue = -2 where fid = ?", fid)
|
||||||
|
|
||||||
# Counts
|
# Counts
|
||||||
|
|
|
@ -28,7 +28,7 @@ def test_new():
|
||||||
t = intTime()
|
t = intTime()
|
||||||
d.sched.answerCard(c, 1)
|
d.sched.answerCard(c, 1)
|
||||||
assert c.queue == 1
|
assert c.queue == 1
|
||||||
assert c.type == 0
|
assert c.type == 1
|
||||||
assert c.due >= t
|
assert c.due >= t
|
||||||
# the default order should ensure siblings are not seen together, and
|
# the default order should ensure siblings are not seen together, and
|
||||||
# should show all cards
|
# should show all cards
|
||||||
|
@ -96,7 +96,7 @@ def test_learn():
|
||||||
# pass it once
|
# pass it once
|
||||||
d.sched.answerCard(c, 2)
|
d.sched.answerCard(c, 2)
|
||||||
# it should by due in 3 minutes
|
# 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
|
# and it should be grade 1 now
|
||||||
assert c.grade == 1
|
assert c.grade == 1
|
||||||
assert c.cycles == 2
|
assert c.cycles == 2
|
||||||
|
@ -108,13 +108,13 @@ def test_learn():
|
||||||
# pass again
|
# pass again
|
||||||
d.sched.answerCard(c, 2)
|
d.sched.answerCard(c, 2)
|
||||||
# it should by due in 10 minutes
|
# 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
|
# and it should be grade 1 now
|
||||||
assert c.grade == 2
|
assert c.grade == 2
|
||||||
assert c.cycles == 3
|
assert c.cycles == 3
|
||||||
# the next pass should graduate the card
|
# the next pass should graduate the card
|
||||||
assert c.queue == 1
|
assert c.queue == 1
|
||||||
assert c.type == 0
|
assert c.type == 1
|
||||||
d.sched.answerCard(c, 2)
|
d.sched.answerCard(c, 2)
|
||||||
assert c.queue == 2
|
assert c.queue == 2
|
||||||
assert c.type == 2
|
assert c.type == 2
|
||||||
|
@ -309,19 +309,9 @@ def test_nextIvl():
|
||||||
def test_misc():
|
def test_misc():
|
||||||
d = getEmptyDeck()
|
d = getEmptyDeck()
|
||||||
f = d.newFact()
|
f = d.newFact()
|
||||||
f['Front'] = u"one"; f['Back'] = u"two"
|
f['Front'] = u"one"
|
||||||
d.addFact(f)
|
d.addFact(f)
|
||||||
c = f.cards()[0]
|
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
|
# burying
|
||||||
d.sched.buryFact(c.fid)
|
d.sched.buryFact(c.fid)
|
||||||
d.reset()
|
d.reset()
|
||||||
|
@ -337,6 +327,37 @@ def test_misc():
|
||||||
assert d.sched.timeToday() > 0
|
assert d.sched.timeToday() > 0
|
||||||
assert d.sched.repsToday() == 1
|
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():
|
def test_cram():
|
||||||
d = getEmptyDeck()
|
d = getEmptyDeck()
|
||||||
f = d.newFact()
|
f = d.newFact()
|
||||||
|
|
Loading…
Reference in a new issue