From 692fba2ea3279fd41f6816b861201c94b806685a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 29 Mar 2011 17:35:44 +0900 Subject: [PATCH] use the deck's groups instead of holding on to a private copy --- anki/cram.py | 9 ++------- anki/deck.py | 4 ++-- tests/test_sched.py | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/anki/cram.py b/anki/cram.py index 1899a2bd6..8070482cc 100644 --- a/anki/cram.py +++ b/anki/cram.py @@ -10,9 +10,8 @@ from anki.sched import Scheduler class CramScheduler(Scheduler): name = "cram" - def __init__(self, deck, gids, order, min=0, max=None): + def __init__(self, deck, order, min=0, max=None): Scheduler.__init__(self, deck) - self.gids = gids # should be the opposite order of what you want self.order = order # days to limit cram to, where tomorrow=0. Max is inclusive. @@ -69,16 +68,12 @@ class CramScheduler(Scheduler): maxlim = "and due <= %d" % (self.today+1+self.max) else: maxlim = "" - if self.gids: - extra = "and gid in "+ids2str(self.gids) - else: - extra = "" self.newQueue = self.db.list(""" select id from cards where queue = 2 and due >= %d %s %s order by %s limit %d""" % (self.today+1+self.min, maxlim, - extra, + self._groupLimit(), self.order, self.reportLimit)) self.newCount = len(self.newQueue) diff --git a/anki/deck.py b/anki/deck.py index 83deb93b2..ad07e542b 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -702,9 +702,9 @@ select conf from gconf where id = (select gcid from groups where id = ?)""", self.sched = self._stdSched return True - def cramGroups(self, gids, order="mod desc", min=0, max=None): + def cramGroups(self, order="mod desc", min=0, max=None): self.stdSched() - self.sched = anki.cram.CramScheduler(self, gids, order, min, max) + self.sched = anki.cram.CramScheduler(self, order, min, max) # Undo ########################################################################## diff --git a/tests/test_sched.py b/tests/test_sched.py index d3b1dc559..35ef0fd3f 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -328,7 +328,8 @@ def test_cram(): c.startTimer() c.flush() cardcopy = copy.copy(c) - d.cramGroups([1]) + d.qconf['groups'] = [1] + d.cramGroups() # first, test with initial intervals preserved conf = d.sched._lrnConf(c) conf['reset'] = False @@ -363,7 +364,7 @@ def test_cram(): # now try again with ivl rescheduling c = copy.copy(cardcopy) c.flush() - d.cramGroups([1]) + d.cramGroups() conf = d.sched._lrnConf(c) conf['reset'] = False conf['resched'] = True @@ -378,7 +379,7 @@ def test_cram(): # try with ivl reset c = copy.copy(cardcopy) c.flush() - d.cramGroups([1]) + d.cramGroups() conf = d.sched._lrnConf(c) conf['reset'] = True conf['resched'] = True @@ -388,7 +389,8 @@ def test_cram(): assert c.ivl == 1 assert c.due == d.sched.today + 1 # users should be able to cram entire deck too - d.cramGroups([]) + d.qconf['groups'] = [] + d.cramGroups() assert d.sched.counts()[0] > 0 def test_cramLimits(): @@ -403,29 +405,30 @@ def test_cramLimits(): c.due = d.sched.today + 1 + i c.flush() # the default cram should return all three - d.cramGroups([1]) + d.qconf['groups'] = [1] + d.cramGroups() assert d.sched.counts()[0] == 3 # if we start from the day after tomorrow, it should be 2 - d.cramGroups([1], min=1) + d.cramGroups(min=1) assert d.sched.counts()[0] == 2 # or after 2 days - d.cramGroups([1], min=2) + d.cramGroups(min=2) assert d.sched.counts()[0] == 1 # we may get nothing - d.cramGroups([1], min=3) + d.cramGroups(min=3) assert d.sched.counts()[0] == 0 # tomorrow(0) + dayAfter(1) = 2 - d.cramGroups([1], max=1) + d.cramGroups(max=1) assert d.sched.counts()[0] == 2 # if max is tomorrow, we get only one - d.cramGroups([1], max=0) + d.cramGroups(max=0) assert d.sched.counts()[0] == 1 # both should work - d.cramGroups([1], min=0, max=0) + d.cramGroups(min=0, max=0) assert d.sched.counts()[0] == 1 - d.cramGroups([1], min=1, max=1) + d.cramGroups(min=1, max=1) assert d.sched.counts()[0] == 1 - d.cramGroups([1], min=0, max=1) + d.cramGroups(min=0, max=1) assert d.sched.counts()[0] == 2 def test_adjIvl():