add extra data to reps/time graphs, simplify graph building

This commit is contained in:
Damien Elmes 2011-03-26 09:20:21 +09:00
parent c7eb4253bd
commit d6f968a47f

View file

@ -50,10 +50,8 @@ class Graphs(object):
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", data=[
dict(data=yng, bars=dict(show=True, barWidth=0.8), dict(data=yng, color=dueYoungC, label=_("Young")),
color=dueYoungC, label=_("Young")), dict(data=mtr, color=dueMatureC, label=_("Mature"))
dict(data=mtr, bars=dict(show=True, barWidth=0.8),
color=dueMatureC, label=_("Mature"))
]) ])
return txt return txt
@ -66,9 +64,8 @@ class Graphs(object):
tot += day[1]+day[2] tot += day[1]+day[2]
days.append((day[0], tot)) days.append((day[0], tot))
txt = self._graph(id="cum", data=[ txt = self._graph(id="cum", data=[
dict(data=days, lines=dict(show=True, fill=True), dict(data=days, color=dueCumulC, label=_("Cards")),
color=dueCumulC, label=_("Cards")), ], type="fill")
])
return txt return txt
def _due(self, days=7): def _due(self, days=7):
@ -89,32 +86,42 @@ group by due order by due""" % self._limit(),
lrn = [] lrn = []
yng = [] yng = []
mtr = [] mtr = []
lapse = []
cram = []
for row in self._stats['done']: for row in self._stats['done']:
lrn.append((row[0], row[1])) lrn.append((row[0], row[1]))
yng.append((row[0], row[2])) yng.append((row[0], row[2]))
mtr.append((row[0], row[3])) mtr.append((row[0], row[3]))
lapse.append((row[0], row[4]))
cram.append((row[0], row[5]))
txt = self._graph(id="reps", data=[ txt = self._graph(id="reps", data=[
dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=lrn, color=reviewNewC, label=_("Learning")),
color=reviewNewC, label=_("Learning")), dict(data=lapse, color=reviewMatureC, label=_("Relearning")),
dict(data=yng, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=yng, color=reviewYoungC, label=_("Young")),
color=reviewYoungC, label=_("Young")), dict(data=mtr, color=reviewMatureC, label=_("Mature")),
dict(data=mtr, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=cram, color=reviewMatureC, label=_("Cramming")),
color=reviewMatureC, label=_("Mature")),
]) ])
return txt return txt
def timeGraph(self): def timeGraph(self):
self._calcStats() self._calcStats()
lrn = [] lrn = []
rev = [] yng = []
mtr = []
lapse = []
cram = []
for row in self._stats['done']: for row in self._stats['done']:
lrn.append((row[0], row[4])) lrn.append((row[0], row[6]))
rev.append((row[0], row[5])) yng.append((row[0], row[7]))
mtr.append((row[0], row[8]))
lapse.append((row[0], row[9]))
cram.append((row[0], row[10]))
txt = self._graph(id="time", data=[ txt = self._graph(id="time", data=[
dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=lrn, color=lrnTimeC, label=_("Learning")),
color=lrnTimeC, label=_("Learning")), dict(data=lapse, color=revTimeC, label=_("Relearning")),
dict(data=rev, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=yng, color=revTimeC, label=_("Young")),
color=revTimeC, label=_("Reviews")), dict(data=mtr, color=revTimeC, label=_("Mature")),
dict(data=cram, color=revTimeC, label=_("Cramming")),
]) ])
return txt return txt
@ -126,8 +133,14 @@ cast((time/1000 - :cut) / 86400.0 as int)+1 as day,
sum(case when type = 0 then 1 else 0 end), -- lrn count sum(case when type = 0 then 1 else 0 end), -- lrn count
sum(case when type = 1 and lastIvl < 21 then 1 else 0 end), -- yng count sum(case when type = 1 and lastIvl < 21 then 1 else 0 end), -- yng count
sum(case when type = 1 and lastIvl >= 21 then 1 else 0 end), -- mtr count sum(case when type = 1 and lastIvl >= 21 then 1 else 0 end), -- mtr count
sum(case when type = 2 then 1 else 0 end), -- lapse count
sum(case when type = 3 then 1 else 0 end), -- cram count
sum(case when type = 0 then taken/1000 else 0 end)/3600.0, -- lrn time sum(case when type = 0 then taken/1000 else 0 end)/3600.0, -- lrn time
sum(case when type = 1 then taken/1000 else 0 end)/3600.0 -- rev time -- yng + mtr time
sum(case when type = 1 and lastIvl < 21 then taken/1000 else 0 end)/3600.0,
sum(case when type = 1 and lastIvl >= 21 then taken/1000 else 0 end)/3600.0,
sum(case when type = 2 then taken/1000 else 0 end)/3600.0, -- lapse time
sum(case when type = 3 then taken/1000 else 0 end)/3600.0 -- cram time
from revlog group by day order by day""", cut=self.deck.sched.dayCutoff) from revlog group by day order by day""", cut=self.deck.sched.dayCutoff)
# Intervals # Intervals
@ -144,8 +157,7 @@ order by ivl / 7""" % self._limit())
self._calcStats() self._calcStats()
ivls = self._stats['ivls'] ivls = self._stats['ivls']
txt = self._graph(id="ivl", data=[ txt = self._graph(id="ivl", data=[
dict(data=ivls, bars=dict(show=True, barWidth=0.8), dict(data=ivls, color=intervC)
color=intervC)
]) ])
return txt return txt
@ -156,8 +168,8 @@ order by ivl / 7""" % self._limit())
# ignores selective, at least for now # ignores selective, at least for now
return self.deck.db.all(""" return self.deck.db.all("""
select (case select (case
when type = 0 then 0 when type in (0,2) then 0
when lastIvl <= 21 then 1 when lastIvl < 21 then 1
else 2 end) as thetype, else 2 end) as thetype,
ease, count() from revlog ease, count() from revlog
group by thetype, ease group by thetype, ease
@ -181,12 +193,9 @@ order by thetype, ease""")
[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", data=[
dict(data=d['lrn'], bars=dict(show=True, barWidth=0.8, align="center"), dict(data=d['lrn'], color=easesNewC, label=_("Learning")),
color=easesNewC, label=_("Learning")), dict(data=d['yng'], color=easesYoungC, label=_("Young")),
dict(data=d['yng'], bars=dict(show=True, barWidth=0.8, align="center"), dict(data=d['mtr'], color=easesMatureC, label=_("Mature")),
color=easesYoungC, label=_("Young")),
dict(data=d['mtr'], bars=dict(show=True, barWidth=0.8, align="center"),
color=easesMatureC, label=_("Mature")),
], conf=dict( ], conf=dict(
xaxis=dict(ticks=ticks, min=0, max=15))) xaxis=dict(ticks=ticks, min=0, max=15)))
return txt return txt
@ -203,9 +212,19 @@ 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): def _graph(self, id, data, conf={}, width=600, height=200, type="bars"):
conf['legend']= {'container': "#%sLegend" % id}
if type == "bars":
conf['series'] = dict(
bars=dict(show=True, barWidth=0.8, align="center"))
elif type == "fill":
conf['series'] = dict(
lines=dict(show=True, fill=True))
return ( return (
"""<div id="%(id)s" style="width:%(w)s; height:%(h)s;"></div> """
<table>
<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>
<script> <script>
$(function () { $(function () {
$.plot($("#%(id)s"), %(data)s, %(conf)s); $.plot($("#%(id)s"), %(data)s, %(conf)s);