use a single group setting

This commit is contained in:
Damien Elmes 2011-03-29 11:42:07 +09:00
parent 73625e5751
commit f75e2af195
5 changed files with 14 additions and 26 deletions

View file

@ -18,8 +18,7 @@ import anki.cards, anki.facts, anki.models, anki.template, anki.cram
# Settings related to queue building. These may be loaded without the rest of
# the config to check due counts faster on mobile clients.
defaultQconf = {
'revGroups': [],
'newGroups': [],
'groups': [],
'newPerDay': 20,
'newToday': [0, 0], # currentDay, count
'newTodayOrder': NEW_TODAY_ORD,
@ -574,12 +573,6 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
select conf from gconf where id = (select gcid from groups where id = ?)""",
gid))
def activeGroups(self, type):
return self.qconf[type+"Groups"]
def setActiveGroups(self, type, list):
self.qconf[type+"Groups"] = list
def setGroup(self, cids, gid):
self.db.execute(
"update cards set gid = ? where id in "+ids2str(cids), gid)

View file

@ -313,6 +313,6 @@ $(function () {
def _limit(self):
if self.selective:
return self.deck.sched._groupLimit("rev")
return self.deck.sched._groupLimit()
else:
return ""

View file

@ -65,7 +65,7 @@ select due, count() from cards
where queue = 2 %s
and due between ? and ?
group by due
order by due""" % self._groupLimit("rev"),
order by due""" % self._groupLimit(),
self.today,
self.today+days-1))
for d in range(days):
@ -204,13 +204,13 @@ from cards group by gid""", self.today):
else:
self.newCount = self.db.scalar("""
select count() from (select id from cards where
queue = 0 %s limit %d)""" % (self._groupLimit('new'), lim))
queue = 0 %s limit %d)""" % (self._groupLimit(), lim))
def _resetNew(self):
lim = min(self.queueLimit, self.newCount)
self.newQueue = self.db.all("""
select id, due from cards where
queue = 0 %s order by due limit %d""" % (self._groupLimit('new'),
queue = 0 %s order by due limit %d""" % (self._groupLimit(),
lim))
self.newQueue.reverse()
self._updateNewCardRatio()
@ -377,14 +377,14 @@ where queue = 1 and type = 2
self.revCount = self.db.scalar("""
select count() from (select id from cards where
queue = 2 %s and due <= :lim limit %d)""" % (
self._groupLimit("rev"), self.reportLimit),
self._groupLimit(), self.reportLimit),
lim=self.today)
def _resetRev(self):
self.revQueue = self.db.list("""
select id from cards where
queue = 2 %s and due <= :lim order by %s limit %d""" % (
self._groupLimit("rev"), self._revOrder(), self.queueLimit),
self._groupLimit(), self._revOrder(), self.queueLimit),
lim=self.today)
if self.deck.qconf['revOrder'] == REV_CARDS_RANDOM:
random.shuffle(self.revQueue)
@ -551,10 +551,10 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
self.confCache[id] = self.deck.groupConf(id)
return self.confCache[id]
def _groupLimit(self, type):
def _groupLimit(self):
if not self.useGroups:
return ""
l = self.deck.activeGroups(type)
l = self.deck.qconf['groups']
if not l:
# everything
return ""
@ -586,7 +586,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
self._nextDueMsg())
def _finishedSubtitle(self):
if self.deck.activeGroups("rev") or self.deck.activeGroups("new"):
if self.deck.qconf['groups']:
return _("You have finished the selected groups for now.")
else:
return _("You have finished the deck for now.")
@ -621,7 +621,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
"Number of reviews due tomorrow."
return self.db.scalar(
"select count() from cards where queue = 2 and due = ?"+
self._groupLimit("rev"),
self._groupLimit(),
self.today+1)
def newTomorrow(self):
@ -629,7 +629,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
lim = self.deck.qconf['newPerDay']
return self.db.scalar(
"select count() from (select id from cards where "
"queue = 0 limit %d)" % lim)
"queue = 0 %s limit %d)" % (self._groupLimit(), lim))
# Next time reports
##########################################################################

View file

@ -148,11 +148,7 @@ def test_groups():
conf = deck.groupConf(3)
assert conf == deck.groupConf(1)
# by default, everything should be shown
assert not deck.activeGroups('rev')
assert not deck.activeGroups('new')
# set new cards to only 'another group'
deck.setActiveGroups('new', [3])
assert deck.activeGroups('new') == [3]
assert not deck.qconf['groups']
def test_selective():
deck = getEmptyDeck()

View file

@ -538,8 +538,7 @@ def test_counts():
# with the default settings, there's no count limit
assert d.sched.counts() == (2,2,2)
# check limit to one group
d.qconf['revGroups'] = [1]
d.qconf['newGroups'] = [1]
d.qconf['groups'] = [1]
d.reset()
assert d.sched.counts() == (1,2,1)
# we can disable the groups without forgetting them