add short interval alternatives

This commit is contained in:
Damien Elmes 2008-10-16 00:02:34 +09:00
parent c8bae8002f
commit 12e4953dc9
2 changed files with 25 additions and 9 deletions

View file

@ -300,8 +300,9 @@ 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."
if updateRelative:
self.updateRelativeDelays()
self.markExpiredCardsDue()
# cache global/daily stats
@ -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 _('''

View file

@ -22,19 +22,34 @@ 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)
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
if short:
fmt = shortTimeTable[type]
else:
fmt = timeTable[type](2)
timestr = "%(a)d.%(b)df" % {'a': 0, 'b': point}
finalstr = "%s-%s" % (