mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
add a pie graph, add average interval to ivls area
This commit is contained in:
parent
c64c7a2acb
commit
2479913f9b
3 changed files with 79 additions and 9 deletions
|
@ -14,9 +14,7 @@ colRelearn = "#c00"
|
||||||
colCram = "#ff0"
|
colCram = "#ff0"
|
||||||
colIvl = "#077"
|
colIvl = "#077"
|
||||||
colTime = "#770"
|
colTime = "#770"
|
||||||
easesNewC = "#80b3ff"
|
colUnseen = "#000"
|
||||||
easesYoungC = "#5555ff"
|
|
||||||
easesMatureC = "#0f5aff"
|
|
||||||
|
|
||||||
class Graphs(object):
|
class Graphs(object):
|
||||||
|
|
||||||
|
@ -35,6 +33,7 @@ class Graphs(object):
|
||||||
txt += self.ivlGraph()
|
txt += self.ivlGraph()
|
||||||
# other graphs
|
# other graphs
|
||||||
txt += self.easeGraph()
|
txt += self.easeGraph()
|
||||||
|
txt += self.cardGraph()
|
||||||
return "<script>%s\n</script><center>%s</center>" % (anki.js.all, txt)
|
return "<script>%s\n</script><center>%s</center>" % (anki.js.all, txt)
|
||||||
|
|
||||||
# Due and cumulative due
|
# Due and cumulative due
|
||||||
|
@ -199,7 +198,7 @@ group by day order by day""" % lim,
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def ivlGraph(self):
|
def ivlGraph(self):
|
||||||
(ivls, all) = self._ivls()
|
(ivls, all, avg) = self._ivls()
|
||||||
tot = 0
|
tot = 0
|
||||||
totd = []
|
totd = []
|
||||||
if not ivls or not all:
|
if not ivls or not all:
|
||||||
|
@ -215,7 +214,7 @@ group by day order by day""" % lim,
|
||||||
yaxes=[dict(), dict(position="right", max=105)]),
|
yaxes=[dict(), dict(position="right", max=105)]),
|
||||||
info=_("""\
|
info=_("""\
|
||||||
Intervals in the review queue. New cards and cards in (re)learning \
|
Intervals in the review queue. New cards and cards in (re)learning \
|
||||||
are not included."""))
|
are not included.""") + "<p>" + (_("Average interval: %d") % avg))
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def _ivls(self):
|
def _ivls(self):
|
||||||
|
@ -231,7 +230,56 @@ where queue = 2 %s %s
|
||||||
group by grp
|
group by grp
|
||||||
order by grp""" % (self._limit(), lim), chunk=chunk),
|
order by grp""" % (self._limit(), lim), chunk=chunk),
|
||||||
self.deck.db.scalar("""
|
self.deck.db.scalar("""
|
||||||
select count() from cards where queue = 2 %s""" % self._limit()))
|
select count() from cards where queue = 2 %s""" % self._limit()),
|
||||||
|
self.deck.db.scalar("""
|
||||||
|
select avg(ivl) from cards where queue = 2 %s""" % 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
|
||||||
|
info = []
|
||||||
|
def line(a, b):
|
||||||
|
info.append("<tr><td>%s:</td><td><b>%s</b></td></tr>" % (a,b))
|
||||||
|
line(_("Total Cards"), self.deck.cardCount())
|
||||||
|
line(_("Total Facts"), self.deck.factCount())
|
||||||
|
(low, avg, high) = self._factors()
|
||||||
|
line(_("Lowest ease factor"), "%d%%" % low)
|
||||||
|
line(_("Average ease factor"), "%d%%" % avg)
|
||||||
|
line(_("Highest ease factor"), "%d%%" % high)
|
||||||
|
info = "<table width=80%>" + "".join(info) + "</table><p>"
|
||||||
|
info += _('''\
|
||||||
|
A card's <i>ease factor</i> is the size of the next interval \
|
||||||
|
when you answer "good"''')
|
||||||
|
txt = self._graph(id="cards", title=_("Cards"), data=d,
|
||||||
|
info=info, type="pie")
|
||||||
|
return txt
|
||||||
|
|
||||||
|
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
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -288,6 +336,7 @@ order by thetype, ease""")
|
||||||
conf['xaxis'] = {}
|
conf['xaxis'] = {}
|
||||||
if timeTicks:
|
if timeTicks:
|
||||||
conf['timeTicks'] = (_("d"), _("w"), _("m"))[self.type]
|
conf['timeTicks'] = (_("d"), _("w"), _("m"))[self.type]
|
||||||
|
# types
|
||||||
if type == "bars":
|
if type == "bars":
|
||||||
conf['series']['bars'] = dict(
|
conf['series']['bars'] = dict(
|
||||||
show=True, barWidth=0.8, align="center", fill=0.7, lineWidth=0)
|
show=True, barWidth=0.8, align="center", fill=0.7, lineWidth=0)
|
||||||
|
@ -296,6 +345,21 @@ order by thetype, ease""")
|
||||||
show=True, barWidth=0.8, align="center", fill=0.7, lineWidth=3)
|
show=True, barWidth=0.8, align="center", fill=0.7, lineWidth=3)
|
||||||
elif type == "fill":
|
elif type == "fill":
|
||||||
conf['series']['lines'] = dict(show=True, fill=True)
|
conf['series']['lines'] = dict(show=True, fill=True)
|
||||||
|
elif type == "pie":
|
||||||
|
width /= 2
|
||||||
|
height *= 1.5
|
||||||
|
ylabel = ""
|
||||||
|
conf['series']['pie'] = dict(
|
||||||
|
show=True,
|
||||||
|
radius=1,
|
||||||
|
stroke=dict(color="#000", width=3),
|
||||||
|
label=dict(
|
||||||
|
show=True,
|
||||||
|
radius=1, #3/4.0,
|
||||||
|
background=dict(
|
||||||
|
opacity=1,
|
||||||
|
color='#000')))
|
||||||
|
conf['legend'] = dict(show=False)
|
||||||
return (
|
return (
|
||||||
"""
|
"""
|
||||||
<h1>%(title)s</h1>
|
<h1>%(title)s</h1>
|
||||||
|
@ -306,7 +370,7 @@ order by thetype, ease""")
|
||||||
|
|
||||||
<td><div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div></td>
|
<td><div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div></td>
|
||||||
|
|
||||||
<td width=100 valign=top><br>
|
<td width=%(infoW)s valign=top><br>
|
||||||
<div id=%(id)sLegend></div>
|
<div id=%(id)sLegend></div>
|
||||||
<br><small>%(info)s</small>
|
<br><small>%(info)s</small>
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
|
@ -318,11 +382,16 @@ $(function () {
|
||||||
return val.toFixed(0)+conf.timeTicks;
|
return val.toFixed(0)+conf.timeTicks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (conf.series.pie) {
|
||||||
|
conf.series.pie.label.formatter = function(label, series){
|
||||||
|
return '<div style="font-size:10pt; text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%%</div>';
|
||||||
|
};
|
||||||
|
}
|
||||||
$.plot($("#%(id)s"), %(data)s, conf);
|
$.plot($("#%(id)s"), %(data)s, conf);
|
||||||
});
|
});
|
||||||
</script>""" % dict(
|
</script>""" % dict(
|
||||||
id=id, title=title, w=width, h=height, tw=width+100, ylab=ylabel,
|
id=id, title=title, w=width, h=height, tw=width+100, ylab=ylabel,
|
||||||
info=info,
|
info=info, infoW=(type=="pie" and 300 or 100),
|
||||||
data=simplejson.dumps(data), conf=simplejson.dumps(conf)))
|
data=simplejson.dumps(data), conf=simplejson.dumps(conf)))
|
||||||
|
|
||||||
def _limit(self):
|
def _limit(self):
|
||||||
|
|
|
@ -9,7 +9,7 @@ defaultConf = {
|
||||||
'new': {
|
'new': {
|
||||||
'delays': [0.5, 3, 10],
|
'delays': [0.5, 3, 10],
|
||||||
'ints': [1, 7, 4],
|
'ints': [1, 7, 4],
|
||||||
'initialFactor': 2.5,
|
'initialFactor': 2500,
|
||||||
},
|
},
|
||||||
'lapse': {
|
'lapse': {
|
||||||
'delays': [0.5, 3, 10],
|
'delays': [0.5, 3, 10],
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue