diff --git a/anki/sched.py b/anki/sched.py index 1434aa10b..475b47b87 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -95,6 +95,25 @@ order by due""" % self._groupLimit(), self.deck.db.execute( "update cards set queue = type where queue between -3 and -2") + def etaStr(self): + eta = self.eta() + if not eta: + return "" + return fmtTimeSpan(eta) + + def eta(self): + "A very rough estimate of time to review." + (cnt, sum) = self.deck.db.first(""" +select count(), sum(taken) from (select * from revlog +order by time desc limit 100)""") + if not cnt: + return 0 + avg = sum / float(cnt) + c = self.counts() + # Here we just assume new/lrn will require 3x the number of reviews. A + # more complex solution can be added in the future. + return (avg*c[0]*3 + avg*c[1]*3 + avg*c[2]) / 1000.0 + # Counts ########################################################################## diff --git a/tests/test_sched.py b/tests/test_sched.py index 56a6d7d80..bf592808c 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -794,3 +794,15 @@ def test_resched(): c.load() assert c.due == d.sched.today+1 assert c.ivl == +1 + +def test_eta(): + d = getEmptyDeck() + f = d.newFact() + f['Front'] = u"one" + d.addFact(f) + d.reset() + c = d.sched.getCard() + time.sleep(0.1) + d.sched.answerCard(c, 1) + time.sleep(0.1) + d.sched.answerCard(c, 1)