mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
use the deck's groups instead of holding on to a private copy
This commit is contained in:
parent
e93ded1e04
commit
692fba2ea3
3 changed files with 20 additions and 22 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
##########################################################################
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in a new issue