mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
add a separate _title()
This commit is contained in:
parent
f67c72bec3
commit
a5d751283b
1 changed files with 80 additions and 75 deletions
155
anki/graphs.py
155
anki/graphs.py
|
@ -67,8 +67,10 @@ class Graphs(object):
|
||||||
data.append(
|
data.append(
|
||||||
dict(data=totd, color=colCum, label=_("Cumulative"), yaxis=2,
|
dict(data=totd, color=colCum, label=_("Cumulative"), yaxis=2,
|
||||||
bars={'show': False}, lines=dict(show=True), stack=False))
|
bars={'show': False}, lines=dict(show=True), stack=False))
|
||||||
txt = self._graph(id="due", title=_("Forecast"), data=data,
|
txt = self._title(
|
||||||
info=_("The number of reviews due in the future."), conf=dict(
|
_("Forecast"),
|
||||||
|
_("The number of reviews due in the future."))
|
||||||
|
txt += self._graph(id="due", data=data, conf=dict(
|
||||||
xaxis=dict(tickDecimals=0),
|
xaxis=dict(tickDecimals=0),
|
||||||
yaxes=[dict(), dict(tickDecimals=0, position="right")]))
|
yaxes=[dict(), dict(tickDecimals=0, position="right")]))
|
||||||
return txt
|
return txt
|
||||||
|
@ -114,9 +116,9 @@ group by day order by day""" % (self._limit(), lim),
|
||||||
yaxes=[dict(), dict(position="right")])
|
yaxes=[dict(), dict(position="right")])
|
||||||
if days is not None:
|
if days is not None:
|
||||||
conf['xaxis']['min'] = -days
|
conf['xaxis']['min'] = -days
|
||||||
def plot(id, title, data, ylabel, info):
|
def plot(id, data, ylabel):
|
||||||
return self._graph(id, title=title,
|
return self._graph(
|
||||||
data=data, conf=conf, ylabel=ylabel, info=info)
|
id, data=data, conf=conf, ylabel=ylabel)
|
||||||
# reps
|
# reps
|
||||||
(repdata, repsum) = self._splitRepData(d, (
|
(repdata, repsum) = self._splitRepData(d, (
|
||||||
(3, colMature, _("Mature")),
|
(3, colMature, _("Mature")),
|
||||||
|
@ -124,8 +126,9 @@ group by day order by day""" % (self._limit(), lim),
|
||||||
(4, colRelearn, _("Relearn")),
|
(4, colRelearn, _("Relearn")),
|
||||||
(1, colLearn, _("Learn")),
|
(1, colLearn, _("Learn")),
|
||||||
(5, colCram, _("Cram"))))
|
(5, colCram, _("Cram"))))
|
||||||
txt = plot("reps", reptitle, repdata, ylabel=_("Answers"),
|
txt = self._title(
|
||||||
info=_("The number of questions you have answered."))
|
reptitle, _("The number of questions you have answered."))
|
||||||
|
txt += plot("reps", repdata, ylabel=_("Answers"))
|
||||||
# time
|
# time
|
||||||
(timdata, timsum) = self._splitRepData(d, (
|
(timdata, timsum) = self._splitRepData(d, (
|
||||||
(8, colMature, _("Mature")),
|
(8, colMature, _("Mature")),
|
||||||
|
@ -137,8 +140,8 @@ group by day order by day""" % (self._limit(), lim),
|
||||||
t = _("Minutes")
|
t = _("Minutes")
|
||||||
else:
|
else:
|
||||||
t = _("Hours")
|
t = _("Hours")
|
||||||
txt += plot("time", timetitle, timdata, ylabel=t, info=_(
|
txt += self._title(timetitle, _("The time taken to answer the questions."))
|
||||||
"The time taken to answer the questions."))
|
txt += plot("time", timdata, ylabel=t)
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def _ansInfo(self, data):
|
def _ansInfo(self, data):
|
||||||
|
@ -210,13 +213,14 @@ group by day order by day""" % lim,
|
||||||
for (grp, cnt) in ivls:
|
for (grp, cnt) in ivls:
|
||||||
tot += cnt
|
tot += cnt
|
||||||
totd.append((grp, tot/float(all)*100))
|
totd.append((grp, tot/float(all)*100))
|
||||||
txt = self._graph(id="ivl", title=_("Intervals"), data=[
|
txt = self._title(_("Intervals"),
|
||||||
|
_("Delays until reviews are shown again."))
|
||||||
|
txt += self._graph(id="ivl", data=[
|
||||||
dict(data=ivls, color=colIvl, label=_("All Types")),
|
dict(data=ivls, color=colIvl, label=_("All Types")),
|
||||||
dict(data=totd, color=colCum, label=_("% Total"), yaxis=2,
|
dict(data=totd, color=colCum, label=_("% Total"), yaxis=2,
|
||||||
bars={'show': False}, lines=dict(show=True), stack=False)
|
bars={'show': False}, lines=dict(show=True), stack=False)
|
||||||
], conf=dict(
|
], conf=dict(
|
||||||
yaxes=[dict(), dict(position="right", max=105)]),
|
yaxes=[dict(), dict(position="right", max=105)]))
|
||||||
info=_("Delays until reviews are shown again."))
|
|
||||||
txt += _("Average interval: <b>%s</b>") % fmtTimeSpan(avg*86400)
|
txt += _("Average interval: <b>%s</b>") % fmtTimeSpan(avg*86400)
|
||||||
txt += "<br>" + _("Longest interval: <b>%s</b>") % fmtTimeSpan(max*86400)
|
txt += "<br>" + _("Longest interval: <b>%s</b>") % fmtTimeSpan(max*86400)
|
||||||
return txt
|
return txt
|
||||||
|
@ -237,57 +241,6 @@ order by grp""" % (self._limit(), lim), chunk=chunk)]
|
||||||
select count(), avg(ivl), max(ivl) from cards where queue = 2 %s""" %
|
select count(), avg(ivl), max(ivl) from cards where queue = 2 %s""" %
|
||||||
self._limit()))
|
self._limit()))
|
||||||
|
|
||||||
# Intervals
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
def cardGraph(self):
|
|
||||||
# graph data
|
|
||||||
div = self._cards()
|
|
||||||
d = []
|
|
||||||
for c, (t, col) in enumerate((
|
|
||||||
(_("Mature"), colMature),
|
|
||||||
(_("Young+Learn"), colYoung),
|
|
||||||
(_("Unseen"), colUnseen))):
|
|
||||||
d.append(dict(data=div[c], label=t, color=col))
|
|
||||||
# text data
|
|
||||||
i = []
|
|
||||||
self._line(i, _("Total Cards"), self.deck.cardCount())
|
|
||||||
self._line(i, _("Total Facts"), self.deck.factCount())
|
|
||||||
(low, avg, high) = self._factors()
|
|
||||||
self._line(i, _("Lowest ease factor"), "%d%%" % low)
|
|
||||||
self._line(i, _("Average ease factor"), "%d%%" % avg)
|
|
||||||
self._line(i, _("Highest ease factor"), "%d%%" % high)
|
|
||||||
info = "<table width=80%>" + "".join(i) + "</table><p>"
|
|
||||||
info += _('''\
|
|
||||||
A card's <i>ease factor</i> is the size of the next interval \
|
|
||||||
when you answer "good" on a review.''')
|
|
||||||
txt = "<h1>%s</h1><table width=%d><tr><td>%s</td><td>%s</td></table>" % (
|
|
||||||
_("Cards"),
|
|
||||||
self.width,
|
|
||||||
self._graph(id="cards", data=d, title="", type="pie"),
|
|
||||||
info)
|
|
||||||
return txt
|
|
||||||
|
|
||||||
def _line(self, i, a, b):
|
|
||||||
i.append(("<tr><td>%s:</td><td>%s</td></tr>") % (a,b))
|
|
||||||
|
|
||||||
def _factors(self):
|
|
||||||
return self.deck.db.first("""
|
|
||||||
select
|
|
||||||
min(factor) / 10.0,
|
|
||||||
avg(factor) / 10.0,
|
|
||||||
max(factor) / 10.0
|
|
||||||
from cards where queue = 2 %s""" % self._limit())
|
|
||||||
|
|
||||||
def _cards(self):
|
|
||||||
return self.deck.db.first("""
|
|
||||||
select
|
|
||||||
sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr
|
|
||||||
sum(case when queue=1 or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn
|
|
||||||
sum(case when queue=0 then 1 else 0 end) -- new
|
|
||||||
%s
|
|
||||||
from cards""" % self._limit())
|
|
||||||
|
|
||||||
# Eases
|
# Eases
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
@ -308,13 +261,14 @@ from cards""" % self._limit())
|
||||||
ticks = [[1,1],[2,2],[3,3],
|
ticks = [[1,1],[2,2],[3,3],
|
||||||
[6,1],[7,2],[8,3],[9,4],
|
[6,1],[7,2],[8,3],[9,4],
|
||||||
[11, 1],[12,2],[13,3],[14,4]]
|
[11, 1],[12,2],[13,3],[14,4]]
|
||||||
txt = self._graph(id="ease", title=_("Answer Buttons"), data=[
|
txt = self._title(_("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['lrn'], color=colLearn, label=_("Learning")),
|
||||||
dict(data=d['yng'], color=colYoung, label=_("Young")),
|
dict(data=d['yng'], color=colYoung, label=_("Young")),
|
||||||
dict(data=d['mtr'], color=colMature, label=_("Mature")),
|
dict(data=d['mtr'], color=colMature, label=_("Mature")),
|
||||||
], type="barsLine", info=_(
|
], type="barsLine", conf=dict(
|
||||||
"The number of times you have pressed each button."),
|
xaxis=dict(ticks=ticks, min=0, max=15)),
|
||||||
conf=dict(xaxis=dict(ticks=ticks, min=0, max=15)),
|
|
||||||
ylabel=_("Answers"))
|
ylabel=_("Answers"))
|
||||||
txt += self._easeInfo(eases)
|
txt += self._easeInfo(eases)
|
||||||
return txt
|
return txt
|
||||||
|
@ -350,11 +304,63 @@ ease, count() from revlog
|
||||||
group by thetype, ease
|
group by thetype, ease
|
||||||
order by thetype, ease""")
|
order by thetype, ease""")
|
||||||
|
|
||||||
|
# Cards
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
def cardGraph(self):
|
||||||
|
# graph data
|
||||||
|
div = self._cards()
|
||||||
|
d = []
|
||||||
|
for c, (t, col) in enumerate((
|
||||||
|
(_("Mature"), colMature),
|
||||||
|
(_("Young+Learn"), colYoung),
|
||||||
|
(_("Unseen"), colUnseen))):
|
||||||
|
d.append(dict(data=div[c], label=t, color=col))
|
||||||
|
# text data
|
||||||
|
i = []
|
||||||
|
self._line(i, _("Total Cards"), self.deck.cardCount())
|
||||||
|
self._line(i, _("Total Facts"), self.deck.factCount())
|
||||||
|
(low, avg, high) = self._factors()
|
||||||
|
self._line(i, _("Lowest ease factor"), "%d%%" % low)
|
||||||
|
self._line(i, _("Average ease factor"), "%d%%" % avg)
|
||||||
|
self._line(i, _("Highest ease factor"), "%d%%" % high)
|
||||||
|
info = "<table width=80%>" + "".join(i) + "</table><p>"
|
||||||
|
info += _('''\
|
||||||
|
A card's <i>ease factor</i> is the size of the next interval \
|
||||||
|
when you answer "good" on a review.''')
|
||||||
|
txt = self._title(_("Cards Types"),
|
||||||
|
_("The division of cards in your deck."))
|
||||||
|
txt += "<table width=%d><tr><td>%s</td><td>%s</td></table>" % (
|
||||||
|
self.width,
|
||||||
|
self._graph(id="cards", data=d, type="pie"),
|
||||||
|
info)
|
||||||
|
return txt
|
||||||
|
|
||||||
|
def _line(self, i, a, b):
|
||||||
|
i.append(("<tr><td>%s:</td><td>%s</td></tr>") % (a,b))
|
||||||
|
|
||||||
|
def _factors(self):
|
||||||
|
return self.deck.db.first("""
|
||||||
|
select
|
||||||
|
min(factor) / 10.0,
|
||||||
|
avg(factor) / 10.0,
|
||||||
|
max(factor) / 10.0
|
||||||
|
from cards where queue = 2 %s""" % self._limit())
|
||||||
|
|
||||||
|
def _cards(self):
|
||||||
|
return self.deck.db.first("""
|
||||||
|
select
|
||||||
|
sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr
|
||||||
|
sum(case when queue=1 or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn
|
||||||
|
sum(case when queue=0 then 1 else 0 end) -- new
|
||||||
|
%s
|
||||||
|
from cards""" % self._limit())
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _graph(self, id, title, data, conf={},
|
def _graph(self, id, data, conf={},
|
||||||
type="bars", ylabel=_("Cards"), timeTicks=True, info=""):
|
type="bars", ylabel=_("Cards"), timeTicks=True):
|
||||||
# display settings
|
# display settings
|
||||||
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':10}
|
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':10}
|
||||||
conf['series'] = dict(stack=True)
|
conf['series'] = dict(stack=True)
|
||||||
|
@ -393,17 +399,13 @@ order by thetype, ease""")
|
||||||
conf['legend'] = dict(show=False)
|
conf['legend'] = dict(show=False)
|
||||||
return (
|
return (
|
||||||
"""
|
"""
|
||||||
<h1 style="margin-bottom: 0">%(title)s</h1>
|
|
||||||
%(info)s
|
|
||||||
<table cellpadding=0 cellspacing=10>
|
<table cellpadding=0 cellspacing=10>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div style="width: 10px; -webkit-transform: rotate(-90deg);
|
<td><div style="width: 10px; -webkit-transform: rotate(-90deg);
|
||||||
-moz-transform: rotate(-90deg);">%(ylab)s</div></td>
|
-moz-transform: rotate(-90deg);">%(ylab)s</div></td>
|
||||||
<td>
|
<td>
|
||||||
<center><div id=%(id)sLegend></div></center>
|
<center><div id=%(id)sLegend></div></center>
|
||||||
<div style="alight: right;">
|
|
||||||
<div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div>
|
<div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div>
|
||||||
</div>
|
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
|
@ -421,8 +423,8 @@ $(function () {
|
||||||
$.plot($("#%(id)s"), %(data)s, conf);
|
$.plot($("#%(id)s"), %(data)s, conf);
|
||||||
});
|
});
|
||||||
</script>""" % dict(
|
</script>""" % dict(
|
||||||
id=id, title=title, w=width, h=height,
|
id=id, w=width, h=height,
|
||||||
ylab=ylabel, info=info, infoW=(type=="pie" and 300 or 200),
|
ylab=ylabel,
|
||||||
data=simplejson.dumps(data), conf=simplejson.dumps(conf)))
|
data=simplejson.dumps(data), conf=simplejson.dumps(conf)))
|
||||||
|
|
||||||
def _limit(self):
|
def _limit(self):
|
||||||
|
@ -430,3 +432,6 @@ $(function () {
|
||||||
return self.deck.sched._groupLimit()
|
return self.deck.sched._groupLimit()
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def _title(self, title, subtitle=""):
|
||||||
|
return '<h1 style="margin-bottom: 0; margin-top: 1em;">%s</h1>%s' % (title, subtitle)
|
||||||
|
|
Loading…
Reference in a new issue