From a9c93d933cadbf5d9c7e3e2b4f7a25d2c59da5d3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 19 Jan 2020 15:41:58 +1000 Subject: [PATCH] fix incorrectly logged repeat step https://anki.tenderapp.com/discussions/ankidesktop/38130-anki-21-scheduler-misleads-on-hard-button-for-learning-cards --- pylib/anki/schedv2.py | 8 +++++++- pylib/tests/test_schedv2.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index f3c02126b..ff6d438a7 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -798,7 +798,13 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", lastLeft: int, ) -> None: lastIvl = -(self._delayForGrade(conf, lastLeft)) - ivl = card.ivl if leaving else -(self._delayForGrade(conf, card.left)) + if leaving: + ivl = card.ivl + else: + if ease == 2: + ivl = -self._delayForRepeatingGrade(conf, card.left) + else: + ivl = -self._delayForGrade(conf, card.left) def log(): self.col.db.execute( diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index dc61543c4..2f3865ff5 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -1281,3 +1281,23 @@ def test_negativeDueFilter(): c.load() assert c.due == -5 + + +# hard on the first step should be the average of again and good, +# and it should be logged properly +def test_initial_repeat(): + d = getEmptyCol() + f = d.newNote() + f["Front"] = "one" + f["Back"] = "two" + d.addNote(f) + + d.reset() + c = d.sched.getCard() + d.sched.answerCard(c, 2) + # should be due in ~ 5.5 mins + expected = time.time() + 5.5 * 60 + assert expected - 10 < c.due < expected * 1.25 + + ivl = d.db.scalar("select ivl from revlog") + assert ivl == -5.5 * 60