diff --git a/anki/schedv2.py b/anki/schedv2.py index 2514bce00..95b935945 100644 --- a/anki/schedv2.py +++ b/anki/schedv2.py @@ -585,12 +585,13 @@ did = ? and queue = 3 and due <= ? limit ?""", if delay is None: delay = self._delayForGrade(conf, card.left) - if card.due < time.time(): - # not collapsed; add some randomness - delay *= random.uniform(1, 1.25) card.due = int(time.time() + delay) # due today? if card.due < self.dayCutoff: + # add some randomness, up to 5 minutes or 25% + maxExtra = min(300, int(delay*0.25)) + fuzz = random.randrange(0, maxExtra) + card.due = min(self.dayCutoff-1, card.due + fuzz) card.queue = 1 if card.due < (intTime() + self.col.conf['collapseTime']): self.lrnCount += 1 diff --git a/tests/test_schedv2.py b/tests/test_schedv2.py index f666f91f2..3abf183fa 100644 --- a/tests/test_schedv2.py +++ b/tests/test_schedv2.py @@ -136,7 +136,8 @@ def test_learn(): # pass it once d.sched.answerCard(c, 3) # it should by due in 3 minutes - assert round(c.due - time.time()) in (179, 180) + dueIn = c.due - time.time() + assert 179 <= dueIn <= 180*1.25 assert c.left%1000 == 2 assert c.left//1000 == 2 # check log is accurate @@ -147,7 +148,8 @@ def test_learn(): # pass again d.sched.answerCard(c, 3) # it should by due in 10 minutes - assert round(c.due - time.time()) in (599, 600) + dueIn = c.due - time.time() + assert 599 <= dueIn <= 600*1.25 assert c.left%1000 == 1 assert c.left//1000 == 1 # the next pass should graduate the card