From 0b42787ffc138bab1660e6225363a361407b0da7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 2 Feb 2018 14:30:53 +1000 Subject: [PATCH] fix no relearn steps case in v2 sched --- anki/schedv2.py | 23 +++++++++++++---------- tests/test_schedv2.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/anki/schedv2.py b/anki/schedv2.py index dbb6ba428..3ff1b40ef 100644 --- a/anki/schedv2.py +++ b/anki/schedv2.py @@ -551,20 +551,16 @@ did = ? and queue = 3 and due <= ? limit ?""", self._logLrn(card, ease, conf, leaving, type, lastLeft) + def _updateRevIvlOnFail(self, card, conf): + card.lastIvl = card.ivl + card.ivl = self._lapseIvl(card, conf) + def _moveToFirstStep(self, card, conf): card.left = self._startingLeft(card) - card.lastIvl = card.ivl - # relearning card? - if card.type in (2,3): - card.ivl = self._lapseIvl(card, self._lrnConf(card)) - - # moving from review queue? - if card.type == 2: - card.type = 3 - card.lapses += 1 - card.factor = max(1300, card.factor-200) + if card.type == 3: + self._updateRevIvlOnFail(card, conf) return self._rescheduleLrnCard(card, conf) @@ -831,11 +827,18 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)""" def _rescheduleLapse(self, card): conf = self._lapseConf(card) + + card.lapses += 1 + card.factor = max(1300, card.factor-200) + if conf['delays']: + card.type = 3 delay = self._moveToFirstStep(card, conf) else: # no relearning steps + self._updateRevIvlOnFail(card, conf) self._rescheduleAsRev(card, conf, early=False) + delay = 0 # if suspended as a leech, nothing to do if self._checkLeech(card, conf) and card.queue == -1: diff --git a/tests/test_schedv2.py b/tests/test_schedv2.py index 6d55a3f68..fa732e34b 100644 --- a/tests/test_schedv2.py +++ b/tests/test_schedv2.py @@ -194,6 +194,27 @@ def test_relearn(): assert c.ivl == 1 assert c.due == d.sched.today + c.ivl +def test_relearn_no_steps(): + d = getEmptyCol() + f = d.newNote() + f['Front'] = "one" + d.addNote(f) + c = f.cards()[0] + c.ivl = 100 + c.due = d.sched.today + c.type = c.queue = 2 + c.flush() + + conf = d.decks.confForDid(1) + conf['lapse']['delays'] = [] + d.decks.save(conf) + + # fail the card + d.reset() + c = d.sched.getCard() + d.sched.answerCard(c, 1) + assert c.type == c.queue == 2 + def test_learn_collapsed(): d = getEmptyCol() # add 2 notes