Use locale decimal point

This commit is contained in:
Susanna Björverud 2009-03-25 11:15:04 +01:00
parent 7bbbc3bd65
commit 57ca74ce34

View file

@ -260,6 +260,7 @@ class CardStats(object):
def report(self): def report(self):
c = self.card c = self.card
fmt = anki.utils.fmtTimeSpan fmt = anki.utils.fmtTimeSpan
fmtFloat = anki.utils.fmtFloat
self.txt = "<table>" self.txt = "<table>"
self.addLine(_("Added"), self.strTime(c.created)) self.addLine(_("Added"), self.strTime(c.created))
if c.firstAnswered: if c.firstAnswered:
@ -272,21 +273,21 @@ class CardStats(object):
next = _("in %s") % fmt(abs(next)) next = _("in %s") % fmt(abs(next))
self.addLine(_("Due"), next) self.addLine(_("Due"), next)
self.addLine(_("Interval"), fmt(c.interval * 86400)) self.addLine(_("Interval"), fmt(c.interval * 86400))
self.addLine(_("Ease"), "%0.2f" % c.factor) self.addLine(_("Ease"), fmtFloat(c.factor, point=2))
if c.lastDue: if c.lastDue:
last = _("%s ago") % fmt(time.time() - c.lastDue) last = _("%s ago") % fmt(time.time() - c.lastDue)
self.addLine(_("Last Due"), last) self.addLine(_("Last Due"), last)
if c.interval != c.lastInterval: if c.interval != c.lastInterval:
# don't show the last interval if it hasn't been updated yet # don't show the last interval if it hasn't been updated yet
self.addLine(_("Last Interval"), fmt(c.lastInterval * 86400)) self.addLine(_("Last Interval"), fmt(c.lastInterval * 86400))
self.addLine(_("Last Ease"), "%0.2f" % c.lastFactor) self.addLine(_("Last Ease"), fmtFloat(c.lastFactor, point=2))
if c.reps: if c.reps:
self.addLine(_("Reviews"), "%d/%d (s=%d)" % ( self.addLine(_("Reviews"), "%d/%d (s=%d)" % (
c.yesCount, c.reps, c.successive)) c.yesCount, c.reps, c.successive))
self.addLine(_("Average Time"), _("%0.1f seconds") % avg = fmt(c.averageTime, point=2)
c.averageTime) self.addLine(_("Average Time"),avg)
self.addLine(_("Total Time"), _("%0.1f seconds") % total = fmt(c.reviewTime, point=2)
c.reviewTime) self.addLine(_("Total Time"), total)
self.addLine(_("Model Tags"), c.fact.model.tags) self.addLine(_("Model Tags"), c.fact.model.tags)
self.addLine(_("Card Template") + "&nbsp;"*5, c.cardModel.name) self.addLine(_("Card Template") + "&nbsp;"*5, c.cardModel.name)
self.txt += "</table>" self.txt += "</table>"
@ -309,8 +310,10 @@ class DeckStats(object):
def report(self): def report(self):
"Return an HTML string with a report." "Return an HTML string with a report."
fmtPerc = anki.utils.fmtPercentage
fmtFloat = anki.utils.fmtFloat
if self.deck.isEmpty(): if self.deck.isEmpty():
return _("Please add some cards first.<p/>") return _("Please add some cards first.") + "<p/>"
d = self.deck d = self.deck
html="<h1>" + _("Deck Statistics") + "</h1>" html="<h1>" + _("Deck Statistics") + "</h1>"
html += _("Deck created: <b>%s</b> ago<br>") % self.createdTimeStr() html += _("Deck created: <b>%s</b> ago<br>") % self.createdTimeStr()
@ -325,60 +328,60 @@ class DeckStats(object):
(stats["new"], stats["newP"]) = (new, newP) (stats["new"], stats["newP"]) = (new, newP)
(stats["old"], stats["oldP"]) = (old, oldP) (stats["old"], stats["oldP"]) = (old, oldP)
(stats["young"], stats["youngP"]) = (young, youngP) (stats["young"], stats["youngP"]) = (young, youngP)
html += _("Total number of cards: <b>%d</b><br>") % total html += _("Total number of cards:") + " <b>%d</b><br>" % total
html += _("Total number of facts: <b>%d</b><br><br>") % d.factCount html += _("Total number of facts:") + " <b>%d</b><br><br>" % d.factCount
html += _("<b>Card counts</b><br>") html += "<b>" + _("Card counts") + "</b><br>"
html += _("Mature cards: <b>%(old)d</b> " html += _("Mature cards:") + " <b>%(old)d</b> (%(oldP)s)<br>" % {'old': stats['old'], 'oldP' : fmtPerc(stats['oldP'])}
"(<b>%(oldP)0.2f%%</b>)<br>") % stats html += _("Young cards:") + " <b>%(young)d</b> (%(youngP)s)<br>" % {'young': stats['young'], 'youngP' : fmtPerc(stats['youngP'])}
html += _("Young cards: <b>%(young)d</b> " html += _("Unseen cards:") + " <b>%(new)d</b> (%(newP)s)<br><br>" % {'new': stats['new'], 'newP' : fmtPerc(stats['newP'])}
"(<b>%(youngP)0.2f%%</b>)<br>") % stats
html += _("Unseen cards: <b>%(new)d</b> "
"(<b>%(newP)0.2f%%</b>)<br><br>") % stats
html += _("<b>Correct answers</b><br>") html += "<b>" + _("Correct answers") + "</b><br>"
html += _("Mature cards: <b>%(gMatureYes%)0.1f%%</b> " html += _("Mature cards:") + "<b>" + fmtPerc(stats['gMatureYes%']) + (
"(<b>%(gMatureYes)d</b> of <b>%(gMatureTotal)d</b>)<br>") % stats "</b> " + _("%(partOf)d of %(totalSum)d") % {'partOf' : stats['gMatureYes'],
html += _("Young cards: <b>%(gYoungYes%)0.1f%%</b> " 'totalSum' : stats['gMatureTotal'] } + "<br>")
"(<b>%(gYoungYes)d</b> of <b>%(gYoungTotal)d</b>)<br>") % stats html += _("Young cards:") + " <b>" + fmtPerc(stats['gYoungYes%']) + (
html += _("First-seen cards: <b>%(gNewYes%)0.1f%%</b> " "</b> " + _("%(partOf)d of %(totalSum)d") % {'partOf' : stats['gYoungYes'],
"(<b>%(gNewYes)d</b> of <b>%(gNewTotal)d</b>)<br><br>") % stats 'totalSum' : stats['gYoungTotal'] } + "<br>")
html += _("First-seen cards:") + " <b>" + fmtPerc(stats['gNewYes%']) + (
"</b> " + _("%(partOf)d of %(totalSum)d") % {'partOf' : stats['gNewYes'],
'totalSum' : stats['gNewTotal'] } + "<br><br>")
# average pending time # average pending time
existing = d.cardCount - d.newCountToday existing = d.cardCount - d.newCountToday
avgInt = self.getAverageInterval() avgInt = self.getAverageInterval()
def tr(a, b): def tr(a, b):
return "<tr><td>%s</td><td align=right>%s</td></tr>" % (a, b) return "<tr><td>%s</td><td align=right>%s</td></tr>" % (a, b)
if existing and avgInt: if existing and avgInt:
html += _("<b>Averages</b><br>") html += "<b>" + _("Averages") + "</b>"
if sys.platform.startswith("darwin"): if sys.platform.startswith("darwin"):
html += "<table width=250>" html += "<table width=250>"
else: else:
html += "<table width=200>" html += "<table width=200>"
html += tr(_("Interval"), _("<b>%0.0f</b> days") % avgInt) html += tr(_("Interval"), ("<b>%s</b> ") % fmtFloat(avgInt) + _("days") )
html += tr(_("Average reps"), _("<b>%0.1f</b> cards/day") % ( html += tr(_("Average reps"), ("<b>%s</b> ") % (
self.getSumInverseRoundInterval())) fmtFloat(self.getSumInverseRoundInterval())) + _("cards/day"))
html += tr(_("Reps next week"), _("<b>%0.1f</b> cards/day") % ( html += tr(_("Reps next week"), ("<b>%s</b> ") % (
self.getWorkloadPeriod(7))) fmtFloat(self.getWorkloadPeriod(7))) + _("cards/day"))
html += tr(_("Reps next month"), _("<b>%0.1f</b> cards/day") % ( html += tr(_("Reps next month"), ("<b>%s</b> ") % (
self.getWorkloadPeriod(30))) fmtFloat(self.getWorkloadPeriod(30))) + _("cards/day"))
html += tr(_("Reps last week"), _("<b>%0.1f</b> cards/day") % ( html += tr(_("Reps last week"), ("<b>%s</b> ") % (
self.getPastWorkloadPeriod(7))) fmtFloat(self.getPastWorkloadPeriod(7))) + _("cards/day"))
html += tr(_("Reps last month"), _("<b>%0.1f</b> cards/day") % ( html += tr(_("Reps last month"), ("<b>%s</b> ") % (
self.getPastWorkloadPeriod(30))) fmtFloat(self.getPastWorkloadPeriod(30))) + _("cards/day"))
html += tr(_("Avg. added"), _("<b>%(a)d</b>/day, <b>%(b)d</b>/mon") % { html += tr(_("Avg. added"), _("<b>%(a)s</b>/day, <b>%(b)s</b>/mon") % {
'a': self.newAverage(), 'b': self.newAverage()*30}) 'a': fmtFloat(self.newAverage()), 'b': fmtFloat(self.newAverage()*30)})
np = self.getNewPeriod(7) np = self.getNewPeriod(7)
html += tr(_("Added last week"), _("<b>%(a)d</b> (<b>%(b)0.1f</b>/day)") % ( html += tr(_("Added last week"), _("<b>%(a)d</b> (<b>%(b)s</b>/day)") % (
{'a': np, 'b': np / float(7)})) {'a': np, 'b': fmtFloat(np / float(7))}))
np = self.getNewPeriod(30) np = self.getNewPeriod(30)
html += tr(_("Added last month"), _("<b>%(a)d</b> (<b>%(b)0.1f</b>/day)") % ( html += tr(_("Added last month"), _("<b>%(a)d</b> (<b>%(b)s</b>/day)") % (
{'a': np, 'b': np / float(30)})) {'a': np, 'b': fmtFloat(np / float(30))}))
np = self.getFirstPeriod(7) np = self.getFirstPeriod(7)
html += tr(_("First last week"), _("<b>%(a)d</b> (<b>%(b)0.1f</b>/day)") % ( html += tr(_("First last week"), _("<b>%(a)d</b> (<b>%(b)s</b>/day)") % (
{'a': np, 'b': np / float(7)})) {'a': np, 'b': fmtFloat(np / float(7))}))
np = self.getFirstPeriod(30) np = self.getFirstPeriod(30)
html += tr(_("First last month"), _("<b>%(a)d</b> (<b>%(b)0.1f</b>/day)") % ( html += tr(_("First last month"), _("<b>%(a)d</b> (<b>%(b)s</b>/day)") % (
{'a': np, 'b': np / float(30)})) {'a': np, 'b': fmtFloat(np / float(30))}))
html += "</table>" html += "</table>"
return html return html
@ -394,10 +397,10 @@ class DeckStats(object):
html = "" html = ""
for key in keys: for key in keys:
html += ("<tr><td align=right>%s</td><td align=right>" + html += ("<tr><td align=right>%s</td><td align=right>" +
"%d</td><td align=right>%0.2f%%</td></tr>") % ( "%d</td><td align=right>%s</td></tr>") % (
labels[key], labels[key],
boxes[key], boxes[key],
boxes[key] / float(total) * 100) fmtPerc(boxes[key] / float(total) * 100))
return html return html
def splitIntoIntervals(self, intervals): def splitIntoIntervals(self, intervals):