diff --git a/anki/sched.py b/anki/sched.py
index d8f1f06f0..4ec6f031a 100644
--- a/anki/sched.py
+++ b/anki/sched.py
@@ -475,11 +475,13 @@ where queue = 1 and type = 2
gid, self.today)
def _resetRevCount(self):
+ top = self.deck.groups.top()
+ lim = min(self.reportLimit,
+ max(0, top['revLim'] - top['revToday'][1]))
self.revCount = self.deck.db.scalar("""
select count() from (select id from cards where
-gid in %s and queue = 2 and due <= :lim limit %d)""" % (
- self._groupLimit(), self.reportLimit),
- lim=self.today)
+gid in %s and queue = 2 and due <= :day limit %d)""" % (
+ self._groupLimit(), lim), day=self.today)
def _resetRev(self):
self._resetRevCount()
@@ -683,52 +685,37 @@ gid in %s and queue = 2 and due <= :lim %s limit %d""" % (
##########################################################################
def finishedMsg(self):
- return (
- "
"+_("Congratulations!")+"
"+
- _("You have finished the selected groups for now.") +
- "
"+
- self._nextDueMsg())
+ return (""+_(
+ "Congratulations! You have finished the selected deck for now.")+
+ "
" + self._nextDueMsg())
def _nextDueMsg(self):
line = []
- rev = self.revTomorrow() + self.lrnTomorrow()
- if rev:
- line.append(
- ngettext("There will be %s review.",
- "There will be %s reviews.", rev) % rev)
- new = self.newTomorrow()
- if new:
- line.append(
- ngettext("There will be %d new card.",
- "There will be %d new cards.", new) % new)
- if line:
- line.insert(0, _("At this time tomorrow:"))
- buf = "
".join(line)
- else:
- buf = _("No cards are due tomorrow.")
- buf = '' + buf
- return buf
+ if self.revDue():
+ line.append(_("""\
+Today's review limit has been reached, but there are still cards
+waiting to be reviewed. For optimum memory, consider increasing
+the daily limit in the options."""))
+ if self.newDue():
+ line.append(_("""\
+There are more new cards available, but the daily limit has been
+reached. You can increase the limit in the options, but please
+bear in mind that the more new cards you introduce, the higher
+your short-term review workload will become."""))
+ return "
".join(line)
- def lrnTomorrow(self):
- "Number of cards in the learning queue due tomorrow."
+ def revDue(self):
+ "True if there are any rev cards due."
return self.deck.db.scalar(
- "select count() from cards where queue = 1 and due < ?",
- self.dayCutoff+86400)
+ ("select 1 from cards where gid in %s and queue = 2 "
+ "and due <= ? limit 1") % self._groupLimit(),
+ self.today)
- def revTomorrow(self):
- "Number of reviews due tomorrow."
+ def newDue(self):
+ "True if there are any new cards due."
return self.deck.db.scalar(
- "select count() from cards where gid in %s and queue = 2 and due = ?"%
- self._groupLimit(), self.today+1)
-
- def newTomorrow(self):
- "Number of new cards tomorrow."
- print "fixme: rethink newTomorrow() etc"
- return 1
- lim = self.deck.groups.top()['newPerDay']
- return self.deck.db.scalar(
- "select count() from (select id from cards where "
- "gid in %s and queue = 0 limit %d)" % (self._groupLimit(), lim))
+ ("select 1 from cards where gid in %s and queue = 0 "
+ "limit 1") % self._groupLimit())
# Next time reports
##########################################################################
diff --git a/tests/test_sched.py b/tests/test_sched.py
index e4292df53..eeefb887a 100644
--- a/tests/test_sched.py
+++ b/tests/test_sched.py
@@ -284,18 +284,20 @@ def test_reviews():
def test_finished():
d = getEmptyDeck()
# nothing due
- assert "No cards are due" in d.sched.finishedMsg()
+ assert "Congratulations" in d.sched.finishedMsg()
+ assert "limit" not in d.sched.finishedMsg()
f = d.newFact()
f['Front'] = u"one"; f['Back'] = u"two"
d.addFact(f)
# have a new card
- assert "1 new" in d.sched.finishedMsg()
+ assert "new cards available" in d.sched.finishedMsg()
# turn it into a review
c = f.cards()[0]
c.startTimer()
d.sched.answerCard(c, 3)
# nothing should be due tomorrow, as it's due in a week
- assert "No cards are due" in d.sched.finishedMsg()
+ assert "Congratulations" in d.sched.finishedMsg()
+ assert "limit" not in d.sched.finishedMsg()
def test_nextIvl():
d = getEmptyDeck()
@@ -902,3 +904,21 @@ def test_resched():
c.load()
assert c.due == d.sched.today+1
assert c.ivl == +1
+
+def test_revlim():
+ d = getEmptyDeck()
+ for i in range(20):
+ f = d.newFact()
+ f['Front'] = str(i)
+ d.addFact(f)
+ d.db.execute("update cards set due = 0, queue = 2, type = 2")
+ d.reset()
+ assert d.sched.repCounts()[2] == 20
+ for i in range(5):
+ d.sched.answerCard(d.sched.getCard(), 3)
+ assert d.sched.repCounts()[2] == 15
+ t = d.groups.top()
+ t['revLim'] = 10
+ d.reset()
+ assert d.sched.repCounts()[2] == 5
+
diff --git a/tools/tests.sh b/tools/tests.sh
index 06d454df9..075d9bc18 100755
--- a/tools/tests.sh
+++ b/tools/tests.sh
@@ -5,4 +5,11 @@ if [ -d 'locale' ]; then
else
dir=.
fi
-(cd $dir && nosetests -vs --with-coverage --cover-package=anki $@)
+
+if [ x$coverage != x ]; then
+ args="--with-coverage"
+else
+ args=""
+ echo "Call with coverage=1 to run coverage tests"
+fi
+(cd $dir && nosetests -vs $args --cover-package=anki $@)