mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
tweak graph layout and separate cumul graph into young/mature
This commit is contained in:
parent
72ed9ceb02
commit
43f8623d78
1 changed files with 51 additions and 50 deletions
|
@ -6,21 +6,15 @@ import os, sys, time, datetime, simplejson
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
import anki.js
|
import anki.js
|
||||||
|
|
||||||
#colours for graphs
|
colYoung = "#7c7"
|
||||||
dueYoungC = "#ffb380"
|
colMature = "#070"
|
||||||
dueMatureC = "#ff5555"
|
colLearn = "#007"
|
||||||
dueCumulC = "#ff8080"
|
colRelearn = "#700"
|
||||||
reviewNewC = "#80ccff"
|
colCram = "#ff0"
|
||||||
reviewYoungC = "#3377ff"
|
colIvl = "#077"
|
||||||
reviewMatureC = "#0000ff"
|
|
||||||
lrnTimeC = "#0fcaff"
|
|
||||||
revTimeC = "#ffcaff"
|
|
||||||
easesNewC = "#80b3ff"
|
easesNewC = "#80b3ff"
|
||||||
easesYoungC = "#5555ff"
|
easesYoungC = "#5555ff"
|
||||||
easesMatureC = "#0f5aff"
|
easesMatureC = "#0f5aff"
|
||||||
addedC = "#b3ff80"
|
|
||||||
firstC = "#b380ff"
|
|
||||||
intervC = "#80e5ff"
|
|
||||||
|
|
||||||
class Graphs(object):
|
class Graphs(object):
|
||||||
|
|
||||||
|
@ -31,12 +25,12 @@ class Graphs(object):
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
txt = (self.dueGraph() +
|
txt = (self.dueGraph() +
|
||||||
|
self.cumDueGraph() +
|
||||||
self.repsGraph() +
|
self.repsGraph() +
|
||||||
self.timeGraph() +
|
self.timeGraph() +
|
||||||
self.cumDueGraph() +
|
|
||||||
self.ivlGraph() +
|
self.ivlGraph() +
|
||||||
self.easeGraph())
|
self.easeGraph())
|
||||||
return "<script>%s</script>%s" % (anki.js.all, txt)
|
return "<script>%s</script><center>%s</center>" % (anki.js.all, txt)
|
||||||
|
|
||||||
# Due and cumulative due
|
# Due and cumulative due
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -49,22 +43,27 @@ class Graphs(object):
|
||||||
for day in d:
|
for day in d:
|
||||||
yng.append((day[0], day[1]))
|
yng.append((day[0], day[1]))
|
||||||
mtr.append((day[0], day[2]))
|
mtr.append((day[0], day[2]))
|
||||||
txt = self._graph(id="due", data=[
|
txt = self._graph(id="due", title=_("Due Forecast"), data=[
|
||||||
dict(data=yng, color=dueYoungC, label=_("Young")),
|
dict(data=mtr, color=colMature, label=_("Mature")),
|
||||||
dict(data=mtr, color=dueMatureC, label=_("Mature"))
|
dict(data=yng, color=colYoung, label=_("Young"))
|
||||||
])
|
])
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def cumDueGraph(self):
|
def cumDueGraph(self):
|
||||||
self._calcStats()
|
self._calcStats()
|
||||||
d = self._stats['due']
|
d = self._stats['due']
|
||||||
tot = 0
|
toty = 0
|
||||||
days = []
|
totm = 0
|
||||||
|
ydays = []
|
||||||
|
mdays = []
|
||||||
for day in d:
|
for day in d:
|
||||||
tot += day[1]+day[2]
|
toty += day[1]
|
||||||
days.append((day[0], tot))
|
totm += day[2]
|
||||||
txt = self._graph(id="cum", data=[
|
ydays.append((day[0], toty))
|
||||||
dict(data=days, color=dueCumulC, label=_("Cards")),
|
mdays.append((day[0], totm))
|
||||||
|
txt = self._graph(id="cum", title=_("Cumulative Due"), data=[
|
||||||
|
dict(data=mdays, color=colMature, label=_("Mature")),
|
||||||
|
dict(data=ydays, color=colYoung, label=_("Young")),
|
||||||
], type="fill")
|
], type="fill")
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -94,12 +93,12 @@ group by due order by due""" % self._limit(),
|
||||||
mtr.append((row[0], row[3]))
|
mtr.append((row[0], row[3]))
|
||||||
lapse.append((row[0], row[4]))
|
lapse.append((row[0], row[4]))
|
||||||
cram.append((row[0], row[5]))
|
cram.append((row[0], row[5]))
|
||||||
txt = self._graph(id="reps", data=[
|
txt = self._graph(id="reps", title=_("Repetitions"), data=[
|
||||||
dict(data=lrn, color=reviewNewC, label=_("Learning")),
|
dict(data=mtr, color=colMature, label=_("Mature")),
|
||||||
dict(data=lapse, color=reviewMatureC, label=_("Relearning")),
|
dict(data=yng, color=colYoung, label=_("Young")),
|
||||||
dict(data=yng, color=reviewYoungC, label=_("Young")),
|
dict(data=lapse, color=colRelearn, label=_("Relearning")),
|
||||||
dict(data=mtr, color=reviewMatureC, label=_("Mature")),
|
dict(data=lrn, color=colLearn, label=_("Learning")),
|
||||||
dict(data=cram, color=reviewMatureC, label=_("Cramming")),
|
dict(data=cram, color=colCram, label=_("Cramming")),
|
||||||
])
|
])
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -116,12 +115,12 @@ group by due order by due""" % self._limit(),
|
||||||
mtr.append((row[0], row[8]))
|
mtr.append((row[0], row[8]))
|
||||||
lapse.append((row[0], row[9]))
|
lapse.append((row[0], row[9]))
|
||||||
cram.append((row[0], row[10]))
|
cram.append((row[0], row[10]))
|
||||||
txt = self._graph(id="time", data=[
|
txt = self._graph(id="time", title=_("Time Spent"), data=[
|
||||||
dict(data=lrn, color=lrnTimeC, label=_("Learning")),
|
dict(data=mtr, color=colMature, label=_("Mature")),
|
||||||
dict(data=lapse, color=revTimeC, label=_("Relearning")),
|
dict(data=yng, color=colYoung, label=_("Young")),
|
||||||
dict(data=yng, color=revTimeC, label=_("Young")),
|
dict(data=lapse, color=colRelearn, label=_("Relearning")),
|
||||||
dict(data=mtr, color=revTimeC, label=_("Mature")),
|
dict(data=lrn, color=colLearn, label=_("Learning")),
|
||||||
dict(data=cram, color=revTimeC, label=_("Cramming")),
|
dict(data=cram, color=colCram, label=_("Cramming")),
|
||||||
])
|
])
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -148,16 +147,16 @@ from revlog group by day order by day""", cut=self.deck.sched.dayCutoff)
|
||||||
|
|
||||||
def _ivls(self):
|
def _ivls(self):
|
||||||
return self.deck.db.all("""
|
return self.deck.db.all("""
|
||||||
select ivl / 7, count() from cards
|
select ivl / 7 as grp, count() from cards
|
||||||
where queue = 2 %s
|
where queue = 2 %s
|
||||||
group by ivl / 7
|
group by grp
|
||||||
order by ivl / 7""" % self._limit())
|
order by grp""" % self._limit())
|
||||||
|
|
||||||
def ivlGraph(self):
|
def ivlGraph(self):
|
||||||
self._calcStats()
|
self._calcStats()
|
||||||
ivls = self._stats['ivls']
|
ivls = self._stats['ivls']
|
||||||
txt = self._graph(id="ivl", data=[
|
txt = self._graph(id="ivl", title=_("Intervals"), data=[
|
||||||
dict(data=ivls, color=intervC)
|
dict(data=ivls, color=colIvl)
|
||||||
])
|
])
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -192,7 +191,7 @@ order by thetype, ease""")
|
||||||
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", data=[
|
txt = self._graph(id="ease", title=_("Eases"), data=[
|
||||||
dict(data=d['lrn'], color=easesNewC, label=_("Learning")),
|
dict(data=d['lrn'], color=easesNewC, label=_("Learning")),
|
||||||
dict(data=d['yng'], color=easesYoungC, label=_("Young")),
|
dict(data=d['yng'], color=easesYoungC, label=_("Young")),
|
||||||
dict(data=d['mtr'], color=easesMatureC, label=_("Mature")),
|
dict(data=d['mtr'], color=easesMatureC, label=_("Mature")),
|
||||||
|
@ -212,25 +211,27 @@ order by thetype, ease""")
|
||||||
self._stats['done'] = self._done()
|
self._stats['done'] = self._done()
|
||||||
self._stats['eases'] = self._eases()
|
self._stats['eases'] = self._eases()
|
||||||
|
|
||||||
def _graph(self, id, data, conf={}, width=600, height=200, type="bars"):
|
def _graph(self, id, title, data, conf={}, width=600, height=200, type="bars"):
|
||||||
|
# display settings
|
||||||
conf['legend'] = {'container': "#%sLegend" % id}
|
conf['legend'] = {'container': "#%sLegend" % id}
|
||||||
|
conf['series'] = dict(stack=True)
|
||||||
if type == "bars":
|
if type == "bars":
|
||||||
conf['series'] = dict(
|
conf['series']['bars'] = dict(
|
||||||
bars=dict(show=True, barWidth=0.8, align="center"))
|
show=True, barWidth=0.8, align="center", fill=0.7, lineWidth=0)
|
||||||
elif type == "fill":
|
elif type == "fill":
|
||||||
conf['series'] = dict(
|
conf['series']['lines'] = dict(show=True, fill=True)
|
||||||
lines=dict(show=True, fill=True))
|
|
||||||
return (
|
return (
|
||||||
"""
|
"""
|
||||||
<table>
|
<h1>%(title)s</h1>
|
||||||
|
<table width=%(tw)s>
|
||||||
<tr><td><div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div></td>
|
<tr><td><div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div></td>
|
||||||
<td valign=top><br><div id=%(id)sLegend></div></td></tr></table>
|
<td width=100 valign=top><br><div id=%(id)sLegend></div></td></tr></table>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
$.plot($("#%(id)s"), %(data)s, %(conf)s);
|
$.plot($("#%(id)s"), %(data)s, %(conf)s);
|
||||||
});
|
});
|
||||||
</script>""" % dict(
|
</script>""" % dict(
|
||||||
id=id, w=width, h=height,
|
id=id, title=title, w=width, h=height, tw=width+100,
|
||||||
data=simplejson.dumps(data),
|
data=simplejson.dumps(data),
|
||||||
conf=simplejson.dumps(conf)))
|
conf=simplejson.dumps(conf)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue