From 12e4953dc979e6df330abe4b8ecbf2ab024d2080 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 16 Oct 2008 00:02:34 +0900 Subject: [PATCH] add short interval alternatives --- anki/deck.py | 11 ++++++----- anki/utils.py | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index c2b26e5df..95971b238 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -300,9 +300,10 @@ where isDue = 0 and priority in (1,2,3,4) and combinedDue < :now""", set relativeDelay = interval / (strftime("%s", "now") - due + 1) where isDue = 1""") - def rebuildQueue(self): + def rebuildQueue(self, updateRelative=True): "Update relative delays based on current time." - self.updateRelativeDelays() + if updateRelative: + self.updateRelativeDelays() self.markExpiredCardsDue() # cache global/daily stats self._globalStats = globalStats(self) @@ -466,7 +467,7 @@ order by combinedDue limit 1""") select count(id) from cards where combinedDue < :time and priority != 0 and type != 2""", time=time) - def nextIntervalStr(self, card, ease): + def nextIntervalStr(self, card, ease, short=False): "Return the next interval for CARD given EASE as a string." delay = self._adjustedDelay(card, ease) if card.due > time.time() and ease < 2: @@ -484,11 +485,11 @@ and priority != 0 and type != 2""", time=time) interval[0] = interval[0] * 86400.0 interval[1] = interval[1] * 86400.0 if interval[0] != interval[1]: - return anki.utils.fmtTimeSpanPair(*interval) + return anki.utils.fmtTimeSpanPair(interval[0], interval[1], short=short) interval = interval[0] else: interval = self.nextInterval(card, ease) * 86400.0 - return anki.utils.fmtTimeSpan(interval) + return anki.utils.fmtTimeSpan(interval, short=short) def deckFinishedMsg(self): return _(''' diff --git a/anki/utils.py b/anki/utils.py index 9dc4166ab..f116e87d9 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -22,20 +22,35 @@ timeTable = { "seconds": lambda n: ngettext("%s second", "%s seconds", n), } -def fmtTimeSpan(time, pad=0, point=0): +shortTimeTable = { + "years": "%sy", + "months": "%sm", + "days": "%sd", + "hours": "%sh", + "minutes": "%sm", + "seconds": "%ss", + } + +def fmtTimeSpan(time, pad=0, point=0, short=False): "Return a string representing a time span (eg '2 days')." (type, point) = optimalPeriod(time, point) time = convertSecondsTo(time, type) - fmt = timeTable[type](_pluralCount(round(time, point))) + if short: + fmt = shortTimeTable[type] + else: + fmt = timeTable[type](_pluralCount(round(time, point))) timestr = "%(a)d.%(b)df" % {'a': pad, 'b': point} return ("%" + (fmt % timestr)) % time -def fmtTimeSpanPair(time1, time2): +def fmtTimeSpanPair(time1, time2, short=False): (type, point) = optimalPeriod(time1, 0) time1 = convertSecondsTo(time1, type) time2 = convertSecondsTo(time2, type) # a pair is always should always be read as plural - fmt = timeTable[type](2) + if short: + fmt = shortTimeTable[type] + else: + fmt = timeTable[type](2) timestr = "%(a)d.%(b)df" % {'a': 0, 'b': point} finalstr = "%s-%s" % ( ('%' + timestr) % time1,