fix zerodiv and other errors

This commit is contained in:
Damien Elmes 2011-03-30 21:50:26 +09:00
parent a856665824
commit 4be8b9d38c
2 changed files with 17 additions and 13 deletions

View file

@ -98,12 +98,15 @@ table * { font-size: 14px; }
else: else:
days = num*30 days = num*30
vals = [] vals = []
vals.append(_("%d/day") % (tot/days)) try:
if self.type > 0: vals.append(_("%d/day") % (tot/days))
vals.append(_("%d/week") % (tot/(days/7))) if self.type > 0:
if self.type > 1: vals.append(_("%d/week") % (tot/(days/7)))
vals.append(_("%d/month") % (tot/(days/30))) if self.type > 1:
txt = _("Average reviews: <b>%s</b>") % ", ".join(vals) vals.append(_("%d/month") % (tot/(days/30)))
txt = _("Average reviews: <b>%s</b>") % ", ".join(vals)
except ZeroDivisionError:
return ""
return txt return txt
def _due(self, start=None, end=None, chunk=1): def _due(self, start=None, end=None, chunk=1):
@ -367,9 +370,10 @@ where 1 """ + self._limit())
self._line(i, _("Total Cards"), c) self._line(i, _("Total Cards"), c)
self._line(i, _("Total Facts"), f) self._line(i, _("Total Facts"), f)
(low, avg, high) = self._factors() (low, avg, high) = self._factors()
self._line(i, _("Lowest ease factor"), "%d%%" % low) if low:
self._line(i, _("Average ease factor"), "%d%%" % avg) self._line(i, _("Lowest ease factor"), "%d%%" % low)
self._line(i, _("Highest ease factor"), "%d%%" % high) self._line(i, _("Average ease factor"), "%d%%" % avg)
self._line(i, _("Highest ease factor"), "%d%%" % high)
min = self.deck.db.scalar( min = self.deck.db.scalar(
"select min(crt) from cards where 1 " + self._limit()) "select min(crt) from cards where 1 " + self._limit())
if min: if min:

View file

@ -598,7 +598,7 @@ def test_groupCounts():
# and one that's a child # and one that's a child
f = d.newFact() f = d.newFact()
f['Front'] = u"two" f['Front'] = u"two"
f.gid = d.groupId("Default Group::1") f.gid = d.groupId("Default::1")
d.addFact(f) d.addFact(f)
# make it a review card # make it a review card
c = f.cards()[0] c = f.cards()[0]
@ -619,12 +619,12 @@ def test_groupCounts():
assert d.sched.counts() == (3, 0, 1) assert d.sched.counts() == (3, 0, 1)
assert len(d.groups()) == 4 assert len(d.groups()) == 4
cnts = d.sched.groupCounts() cnts = d.sched.groupCounts()
assert cnts[0] == ["Default Group", 1, 1, 0, 1] assert cnts[0] == ["Default", 1, 1, 0, 1]
assert cnts[1] == ["Default Group::1", 2, 1, 1, 0] assert cnts[1] == ["Default::1", 2, 1, 1, 0]
assert cnts[2] == ["foo::bar", 3, 1, 0, 1] assert cnts[2] == ["foo::bar", 3, 1, 0, 1]
assert cnts[3] == ["foo::baz", 4, 1, 0, 1] assert cnts[3] == ["foo::baz", 4, 1, 0, 1]
tree = d.sched.groupCountTree() tree = d.sched.groupCountTree()
assert tree[0][0] == "Default Group" assert tree[0][0] == "Default"
# sum of child and parent # sum of child and parent
assert tree[0][1] == 1 assert tree[0][1] == 1
assert tree[0][2] == 2 assert tree[0][2] == 2