drop i18n references in old stats

This commit is contained in:
Damien Elmes 2020-11-18 08:51:57 +10:00
parent e527d31dfc
commit e9cd956acd
3 changed files with 94 additions and 110 deletions

View file

@ -14,7 +14,6 @@ from xml.dom.minidom import Element, Text
from anki.collection import Collection
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
from anki.lang import _, ngettext
from anki.stdmodels import addBasicModel
@ -198,9 +197,7 @@ class SupermemoXmlImporter(NoteImporter):
# Return imported cards
self.total = len(self.notes)
self.log.append(
ngettext("%d card imported.", "%d cards imported.", self.total) % self.total
)
self.log.append("%d cards imported." % self.total)
return self.notes
def fields(self) -> int:
@ -295,7 +292,7 @@ class SupermemoXmlImporter(NoteImporter):
+ " - "
+ dLevels[level].ljust(9)
+ " -\t"
+ _(text)
+ text
)
# OPEN AND LOAD

View file

@ -10,7 +10,6 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
import anki
from anki.consts import *
from anki.lang import _, ngettext
from anki.rsbackend import TR, FormatTimeSpanContext
from anki.utils import ids2str
@ -116,7 +115,7 @@ body { direction: ltr !important; }
######################################################################
def todayStats(self) -> str:
b = self._title(_("Today"))
b = self._title("Today")
# studied today
lim = self._revlogLimit()
if lim:
@ -149,16 +148,16 @@ from revlog where id > ? """
cards=cards, seconds=float(thetime)
)
# again/pass count
b += "<br>" + _("Again count: %s") % bold(failed)
b += "<br>" + "Again count: %s" % bold(failed)
if cards:
b += " " + _("(%s correct)") % bold(
b += " " + "(%s correct)" % bold(
"%0.1f%%" % ((1 - failed / float(cards)) * 100)
)
# type breakdown
b += "<br>"
b += _(
"Learn: %(a)s, Review: %(b)s, Relearn: %(c)s, Filtered: %(d)s"
) % dict(a=bold(lrn), b=bold(rev), c=bold(relrn), d=bold(filt))
b += "Learn: %(a)s, Review: %(b)s, Relearn: %(c)s, Filtered: %(d)s" % dict(
a=bold(lrn), b=bold(rev), c=bold(relrn), d=bold(filt)
)
# mature today
mcnt, msum = self.col.db.first(
"""
@ -169,13 +168,13 @@ from revlog where id > ? """
)
b += "<br>"
if mcnt:
b += _(
"Correct answers on mature cards: %(a)d/%(b)d (%(c).1f%%)"
) % dict(a=msum, b=mcnt, c=(msum / float(mcnt) * 100))
b += "Correct answers on mature cards: %(a)d/%(b)d (%(c).1f%%)" % dict(
a=msum, b=mcnt, c=(msum / float(mcnt) * 100)
)
else:
b += _("No mature cards were studied today.")
b += "No mature cards were studied today."
else:
b += _("No cards have been studied today.")
b += "No cards have been studied today."
return b
# Due and cumulative due
@ -210,22 +209,22 @@ from revlog where id > ? """
tot += day[1] + day[2]
totd.append((day[0], tot))
data = [
dict(data=mtr, color=colMature, label=_("Mature")),
dict(data=yng, color=colYoung, label=_("Young")),
dict(data=mtr, color=colMature, label="Mature"),
dict(data=yng, color=colYoung, label="Young"),
]
if len(totd) > 1:
data.append(
dict(
data=totd,
color=colCum,
label=_("Cumulative"),
label="Cumulative",
yaxis=2,
bars={"show": False},
lines=dict(show=True),
stack=False,
)
)
txt = self._title(_("Forecast"), _("The number of reviews due in the future."))
txt = self._title("Forecast", "The number of reviews due in the future.")
xaxis = dict(tickDecimals=0, min=-0.5)
if end is not None:
xaxis["max"] = end - 0.5
@ -233,7 +232,7 @@ from revlog where id > ? """
id="due",
data=data,
xunit=chunk,
ylabel2=_("Cumulative Cards"),
ylabel2="Cumulative Cards",
conf=dict(
xaxis=xaxis,
yaxes=[dict(min=0), dict(min=0, tickDecimals=0, position="right")],
@ -246,10 +245,10 @@ from revlog where id > ? """
i: List[str] = []
self._line(
i,
_("Total"),
"Total",
self.col.tr(TR.STATISTICS_REVIEWS, reviews=tot),
)
self._line(i, _("Average"), self._avgDay(tot, num, _("reviews")))
self._line(i, "Average", self._avgDay(tot, num, "reviews"))
tomorrow = self.col.db.scalar(
f"""
select count() from cards where did in %s and queue in ({QUEUE_TYPE_REV},{QUEUE_TYPE_DAY_LEARN_RELEARN})
@ -257,8 +256,8 @@ and due = ?"""
% self._limit(),
self.col.sched.today + 1,
)
tomorrow = ngettext("%d card", "%d cards", tomorrow) % tomorrow
self._line(i, _("Due tomorrow"), tomorrow)
tomorrow = "%d cards" % tomorrow
self._line(i, "Due tomorrow", tomorrow)
return self._lineTbl(i)
def _due(
@ -306,8 +305,8 @@ group by day order by day"""
# graph
repdata, repsum = self._splitRepData(data, ((1, colLearn, ""),))
txt = self._title(_("Added"), _("The number of new cards you have added."))
txt += plot("intro", repdata, ylabel=_("Cards"), ylabel2=_("Cumulative Cards"))
txt = self._title("Added", "The number of new cards you have added.")
txt += plot("intro", repdata, ylabel="Cards", ylabel2="Cumulative Cards")
# total and per day average
tot = sum([i[1] for i in data])
period = self._periodDays()
@ -315,8 +314,8 @@ group by day order by day"""
# base off date of earliest added card
period = self._deckAge("add")
i: List[str] = []
self._line(i, _("Total"), ngettext("%d card", "%d cards", tot) % tot)
self._line(i, _("Average"), self._avgDay(tot, period, _("cards")))
self._line(i, "Total", "%d cards" % tot)
self._line(i, "Average", self._avgDay(tot, period, "cards"))
txt += self._lineTbl(i)
return txt
@ -343,45 +342,39 @@ group by day order by day"""
(repdata, repsum) = self._splitRepData(
data,
(
(3, colMature, _("Mature")),
(2, colYoung, _("Young")),
(4, colRelearn, _("Relearn")),
(1, colLearn, _("Learn")),
(5, colCram, _("Cram")),
(3, colMature, "Mature"),
(2, colYoung, "Young"),
(4, colRelearn, "Relearn"),
(1, colLearn, "Learn"),
(5, colCram, "Cram"),
),
)
txt1 = self._title(
_("Review Count"), _("The number of questions you have answered.")
)
txt1 += plot(
"reps", repdata, ylabel=_("Answers"), ylabel2=_("Cumulative Answers")
)
txt1 = self._title("Review Count", "The number of questions you have answered.")
txt1 += plot("reps", repdata, ylabel="Answers", ylabel2="Cumulative Answers")
(daysStud, fstDay) = self._daysStudied()
rep, tot = self._ansInfo(repsum, daysStud, fstDay, _("reviews"))
rep, tot = self._ansInfo(repsum, daysStud, fstDay, "reviews")
txt1 += rep
# time
(timdata, timsum) = self._splitRepData(
data,
(
(8, colMature, _("Mature")),
(7, colYoung, _("Young")),
(9, colRelearn, _("Relearn")),
(6, colLearn, _("Learn")),
(10, colCram, _("Cram")),
(8, colMature, "Mature"),
(7, colYoung, "Young"),
(9, colRelearn, "Relearn"),
(6, colLearn, "Learn"),
(10, colCram, "Cram"),
),
)
if self.type == PERIOD_MONTH:
t = _("Minutes")
t = "Minutes"
convHours = False
else:
t = _("Hours")
t = "Hours"
convHours = True
txt2 = self._title(
_("Review Time"), _("The time taken to answer the questions.")
)
txt2 += plot("time", timdata, ylabel=t, ylabel2=_("Cumulative %s") % t)
txt2 = self._title("Review Time", "The time taken to answer the questions.")
txt2 += plot("time", timdata, ylabel=t, ylabel2="Cumulative %s" % t)
rep, tot2 = self._ansInfo(
timsum, daysStud, fstDay, _("minutes"), convHours, total=tot
timsum, daysStud, fstDay, "minutes", convHours, total=tot
)
txt2 += rep
return self._section(txt1) + self._section(txt2)
@ -404,34 +397,30 @@ group by day order by day"""
i: List[str] = []
self._line(
i,
_("Days studied"),
_("<b>%(pct)d%%</b> (%(x)s of %(y)s)")
"Days studied",
"<b>%(pct)d%%</b> (%(x)s of %(y)s)"
% dict(x=studied, y=period, pct=studied / float(period) * 100),
bold=False,
)
if convHours:
tunit = _("hours")
tunit = "hours"
else:
tunit = unit
# T: unit: can be hours, minutes, reviews... tot: the number of unit.
self._line(
i, _("Total"), _("%(tot)s %(unit)s") % dict(unit=tunit, tot=int(tot))
)
self._line(i, "Total", "%(tot)s %(unit)s" % dict(unit=tunit, tot=int(tot)))
if convHours:
# convert to minutes
tot *= 60
self._line(i, _("Average for days studied"), self._avgDay(tot, studied, unit))
self._line(i, "Average for days studied", self._avgDay(tot, studied, unit))
if studied != period:
# don't display if you did study every day
self._line(
i, _("If you studied every day"), self._avgDay(tot, period, unit)
)
self._line(i, "If you studied every day", self._avgDay(tot, period, unit))
if total and tot:
perMin = total / float(tot)
average_secs = (tot * 60) / total
self._line(
i,
_("Average answer time"),
"Average answer time",
self.col.tr(
TR.STATISTICS_AVERAGE_ANSWER_TIME,
**{"cards-per-minute": perMin, "average-seconds": average_secs},
@ -593,10 +582,10 @@ group by day order by day)"""
ivlmax = 52
else:
ivlmax = max(5, ivls[-1][0])
txt = self._title(_("Intervals"), _("Delays until reviews are shown again."))
txt = self._title("Intervals", "Delays until reviews are shown again.")
txt += self._graph(
id="ivl",
ylabel2=_("Percentage"),
ylabel2="Percentage",
xunit=chunk,
data=[
dict(data=ivls, color=colIvl),
@ -615,8 +604,8 @@ group by day order by day)"""
),
)
i: List[str] = []
self._line(i, _("Average interval"), self.col.format_timespan(avg * 86400))
self._line(i, _("Longest interval"), self.col.format_timespan(max_ * 86400))
self._line(i, "Average interval", self.col.format_timespan(avg * 86400))
self._line(i, "Longest interval", self.col.format_timespan(max_ * 86400))
return txt + self._lineTbl(i)
def _ivls(self) -> Tuple[List[Any], int]:
@ -678,18 +667,18 @@ select count(), avg(ivl), max(ivl) from cards where did in %s and queue = {QUEUE
if self.col.schedVer() != 1:
ticks.insert(3, [4, 4])
txt = self._title(
_("Answer Buttons"), _("The number of times you have pressed each button.")
"Answer Buttons", "The number of times you have pressed each button."
)
txt += self._graph(
id="ease",
data=[
dict(data=d["lrn"], color=colLearn, label=_("Learning")),
dict(data=d["yng"], color=colYoung, label=_("Young")),
dict(data=d["mtr"], color=colMature, label=_("Mature")),
dict(data=d["lrn"], color=colLearn, label="Learning"),
dict(data=d["yng"], color=colYoung, label="Young"),
dict(data=d["mtr"], color=colMature, label="Mature"),
],
type="bars",
conf=dict(xaxis=dict(ticks=ticks, min=0, max=15)),
ylabel=_("Answers"),
ylabel="Answers",
)
txt += self._easeInfo(eases)
return txt
@ -710,7 +699,7 @@ select count(), avg(ivl), max(ivl) from cards where did in %s and queue = {QUEUE
except:
pct = 0
i.append(
_("Correct: <b>%(pct)0.2f%%</b><br>(%(good)d of %(tot)d)")
"Correct: <b>%(pct)0.2f%%</b><br>(%(good)d of %(tot)d)"
% dict(pct=pct, good=good, tot=tot)
)
return (
@ -788,16 +777,16 @@ order by thetype, ease"""
diff = round(diff, 1)
trend.append((hour, prev + diff))
txt = self._title(
_("Hourly Breakdown"), _("Review success rate for each hour of the day.")
"Hourly Breakdown", "Review success rate for each hour of the day."
)
txt += self._graph(
id="hour",
data=[
dict(data=shifted, color=colCum, label=_("% Correct")),
dict(data=shifted, color=colCum, label="% Correct"),
dict(
data=counts,
color=colHour,
label=_("Answers"),
label="Answers",
yaxis=2,
bars=dict(barWidth=0.2),
stack=False,
@ -806,19 +795,19 @@ order by thetype, ease"""
conf=dict(
xaxis=dict(
ticks=[
[0, _("4AM")],
[6, _("10AM")],
[12, _("4PM")],
[18, _("10PM")],
[23, _("3AM")],
[0, "4AM"],
[6, "10AM"],
[12, "4PM"],
[18, "10PM"],
[23, "3AM"],
]
),
yaxes=[dict(max=peak), dict(position="right", max=mcount)],
),
ylabel=_("% Correct"),
ylabel2=_("Reviews"),
ylabel="% Correct",
ylabel2="Reviews",
)
txt += _("Hours with less than 30 reviews are not shown.")
txt += "Hours with less than 30 reviews are not shown."
return txt
def _hourRet(self) -> Any:
@ -855,10 +844,10 @@ group by hour having count() > 30 order by hour"""
d = []
for c, (t, col) in enumerate(
(
(_("Mature"), colMature),
(_("Young+Learn"), colYoung),
(_("Unseen"), colUnseen),
(_("Suspended+Buried"), colSusp),
("Mature", colMature),
("Young+Learn", colYoung),
("Unseen", colUnseen),
("Suspended+Buried", colSusp),
)
):
d.append(dict(data=div[c], label="%s: %s" % (t, div[c]), color=col))
@ -870,20 +859,18 @@ select count(id), count(distinct nid) from cards
where did in %s """
% self._limit()
)
self._line(i, _("Total cards"), c)
self._line(i, _("Total notes"), f)
self._line(i, "Total cards", c)
self._line(i, "Total notes", f)
(low, avg, high) = self._factors()
if low:
self._line(i, _("Lowest ease"), "%d%%" % low)
self._line(i, _("Average ease"), "%d%%" % avg)
self._line(i, _("Highest ease"), "%d%%" % high)
self._line(i, "Lowest ease", "%d%%" % low)
self._line(i, "Average ease", "%d%%" % avg)
self._line(i, "Highest ease", "%d%%" % high)
info = "<table width=100%>" + "".join(i) + "</table><p>"
info += _(
"""\
info += """\
A card's <i>ease</i> is the size of the next interval \
when you answer "good" on a review."""
)
txt = self._title(_("Card Types"), _("The division of cards in your deck(s)."))
txt = self._title("Card Types", "The division of cards in your deck(s).")
txt += "<table width=%d><tr><td>%s</td><td>%s</td></table>" % (
self.width,
self._graph(id="cards", data=d, type="pie"),
@ -895,7 +882,7 @@ when you answer "good" on a review."""
self, i: List[str], a: str, b: Union[int, str], bold: bool = True
) -> None:
# T: Symbols separating first and second column in a statistics table. Eg in "Total: 3 reviews".
colon = _(":")
colon = ":"
if bold:
i.append(
("<tr><td width=200 align=right>%s%s</td><td><b>%s</b></td></tr>")
@ -938,15 +925,15 @@ from cards where did in %s"""
def footer(self) -> str:
b = "<br><br><font size=1>"
b += _("Generated on %s") % time.asctime(time.localtime(time.time()))
b += "Generated on %s" % time.asctime(time.localtime(time.time()))
b += "<br>"
if self.wholeCollection:
deck = _("whole collection")
deck = "whole collection"
else:
deck = self.col.decks.current()["name"]
b += _("Scope: %s") % deck
b += "Scope: %s" % deck
b += "<br>"
b += _("Period: %s") % [_("1 month"), _("1 year"), _("deck life")][self.type]
b += "Period: %s" % ["1 month", "1 year", "deck life"][self.type]
return b
# Tools
@ -959,7 +946,7 @@ from cards where did in %s"""
conf: Optional[Any] = None,
type: str = "bars",
xunit: int = 1,
ylabel: str = _("Cards"),
ylabel: str = "Cards",
ylabel2: str = "",
) -> str:
if conf is None:
@ -979,11 +966,11 @@ from cards where did in %s"""
conf["timeTicks"] = False
else:
# T: abbreviation of day
d = _("d")
d = "d"
# T: abbreviation of week
w = _("w")
w = "w"
# T: abbreviation of month
mo = _("mo")
mo = "mo"
conf["timeTicks"] = {1: d, 7: w, 31: mo}[xunit]
# types
width = self.width
@ -1109,7 +1096,7 @@ $(function () {
def _avgDay(self, tot: float, num: int, unit: str) -> str:
vals = []
try:
vals.append(_("%(a)0.1f %(b)s/day") % dict(a=tot / float(num), b=unit))
vals.append("%(a)0.1f %(b)s/day" % dict(a=tot / float(num), b=unit))
return ", ".join(vals)
except ZeroDivisionError:
return ""

View file

@ -155,7 +155,7 @@ the legacy addHook() API.
# %s</a><div id="%s" class=hint style="display: none">%s</div>
# """ % (
# domid,
# _("Show %s") % tag,
# "Show %s" % tag,
# domid,
# txt,
# )