From 88c4f010d38260cf27e8232939222a0f6c9e4120 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 21 Apr 2011 12:21:50 +0900 Subject: [PATCH] update rescheduling like forgetCards(), we no longer adjust the stats or revlog for the card --- anki/sched.py | 44 ++++++++++++++++---------------------------- tests/test_sched.py | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/anki/sched.py b/anki/sched.py index 0b9d19838..e48a22be8 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -747,38 +747,26 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % ( ########################################################################## def forgetCards(self, ids): - "Put cards back in the new queue." - sql = """ -update cards set type=0, queue=0, ivl=0, data=''""" - sids = ids2str(ids) - sql += " where id in "+sids - self.deck.db.execute(sql) + "Put cards at the end of the new queue." + self.deck.db.execute( + "update cards set type=0, queue=0, ivl=0 where id in "+ids2str(ids)) pmax = self.deck.db.scalar("select max(due) from cards where type=0") self.sortCards(ids, start=pmax+1, shuffle=self.deck.randomNew()) - def rescheduleCards(self, ids, min, max): - "Reset cards and schedule with new interval in days (min, max)." - self.resetCards(ids) - vals = [] + def reschedCards(self, ids, min, max): + "Put cards in review queue with a new interval in days (min, max)." + self.deck.db.execute( + "update cards set type=2, queue=2 where id in "+ids2str(ids)) + + d = [] + t = self.today + mod = intTime() for id in ids: - r = random.uniform(min*86400, max*86400) - vals.append({ - 'id': id, - 'due': r + time.time(), - 'int': r / 86400.0, - 't': time.time(), - }) - self.deck.db.executemany(""" -update cards set -interval = :int, -due = :due, -reps = 1, -successive = 1, -yesCount = 1, -firstAnswered = :t, -queue = 1, -type = 1, -where id = :id""", vals) + r = random.randint(min, max) + d.append(dict(id=id, due=r+t, ivl=r, mod=mod)) + self.deck.db.executemany( + "update cards set type=2,queue=2,ivl=:ivl,due=:due where id=:id", + d) # Repositioning new cards ########################################################################## diff --git a/tests/test_sched.py b/tests/test_sched.py index 0d159b704..1fd28895b 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -726,7 +726,6 @@ def test_reorder(): def test_forget(): d = getEmptyDeck() - # add a fact with default group f = d.newFact() f['Front'] = u"one" d.addFact(f) @@ -738,3 +737,19 @@ def test_forget(): d.sched.forgetCards([c.id]) d.reset() assert d.sched.counts() == (1, 0, 0) + +def test_resched(): + d = getEmptyDeck() + f = d.newFact() + f['Front'] = u"one" + d.addFact(f) + c = f.cards()[0] + d.sched.reschedCards([c.id], 0, 0) + c.load() + assert c.due == d.sched.today + assert c.ivl == 0 + assert c.queue == c.type == 2 + d.sched.reschedCards([c.id], 1, 1) + c.load() + assert c.due == d.sched.today+1 + assert c.ivl == +1