remove the separate timeGraph()

This commit is contained in:
Damien Elmes 2011-03-26 14:57:08 +09:00
parent 40706f3493
commit 63efc4dbaa
2 changed files with 20 additions and 21 deletions

View file

@ -9,8 +9,8 @@ import anki.js
colYoung = "#7c7" colYoung = "#7c7"
colMature = "#070" colMature = "#070"
colCum = "rgba(0,0,0,0.9)" colCum = "rgba(0,0,0,0.9)"
colLearn = "#007" colLearn = "#00F"
colRelearn = "#700" colRelearn = "#c00"
colCram = "#ff0" colCram = "#ff0"
colIvl = "#077" colIvl = "#077"
easesNewC = "#80b3ff" easesNewC = "#80b3ff"
@ -28,10 +28,11 @@ class Graphs(object):
txt = (self.dueGraph(0, 30, _("Due/Day")) + txt = (self.dueGraph(0, 30, _("Due/Day")) +
self.dueGraph(0, 52, _("Due/Week"), chunk=7) + self.dueGraph(0, 52, _("Due/Week"), chunk=7) +
self.dueGraph(0, None, _("Due/Month"), chunk=30) + self.dueGraph(0, None, _("Due/Month"), chunk=30) +
self.repsGraph(30, _("Reviewed/Day")) + self.repsGraph(30, _("Reviewed/Day"), _("Time/Day")) +
self.repsGraph(52, _("Reviewed/Week"), chunk=7) + self.repsGraph(52, _("Reviewed/Week"), _("Time/Week"),
self.repsGraph(None, _("Reviewed/Month"), chunk=30) + chunk=7) +
self.timeGraph() + self.repsGraph(None, _("Reviewed/Month"), _("Time/Month"),
chunk=30) +
self.ivlGraph() + self.ivlGraph() +
self.easeGraph()) self.easeGraph())
return "<script>%s</script><center>%s</center>" % (anki.js.all, txt) return "<script>%s</script><center>%s</center>" % (anki.js.all, txt)
@ -80,8 +81,9 @@ group by day order by day""" % (self._limit(), lim),
# Reps and time spent # Reps and time spent
###################################################################### ######################################################################
def repsGraph(self, days, title, chunk=1): def repsGraph(self, days, reptitle, timetitle, chunk=1):
d = self._done(days, chunk) d = self._done(days, chunk)
# reps
lrn = [] lrn = []
yng = [] yng = []
mtr = [] mtr = []
@ -102,7 +104,8 @@ 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
txt = self._graph(id=hash(title), title=title, data=[ def plot(title):
return self._graph("g%d"%hash(title), title=title, data=[
dict(data=mtr, color=colMature, label=_("Mature")), dict(data=mtr, color=colMature, label=_("Mature")),
dict(data=yng, color=colYoung, label=_("Young")), dict(data=yng, color=colYoung, label=_("Young")),
dict(data=lapse, color=colRelearn, label=_("Relearning")), dict(data=lapse, color=colRelearn, label=_("Relearning")),
@ -111,28 +114,24 @@ group by day order by day""" % (self._limit(), lim),
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)
], conf=conf) ], conf=conf)
return txt txt = plot(reptitle)
# time
def timeGraph(self):
self._calcStats()
lrn = [] lrn = []
yng = [] yng = []
mtr = [] mtr = []
lapse = [] lapse = []
cram = [] cram = []
for row in self._stats['done']: tot = 0
totd = []
for row in d:
lrn.append((row[0], row[6])) lrn.append((row[0], row[6]))
yng.append((row[0], row[7])) yng.append((row[0], row[7]))
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", title=_("Time Spent"), data=[ tot += row[6]+row[7]+row[8]+row[9]+row[10]
dict(data=mtr, color=colMature, label=_("Mature")), totd.append((row[0], tot))
dict(data=yng, color=colYoung, label=_("Young")), txt += plot(timetitle)
dict(data=lapse, color=colRelearn, label=_("Relearning")),
dict(data=lrn, color=colLearn, label=_("Learning")),
dict(data=cram, color=colCram, label=_("Cramming")),
])
return txt return txt
def _done(self, num=7, chunk=1): def _done(self, num=7, chunk=1):

View file

@ -28,7 +28,7 @@ def test_graphs_empty():
def test_graphs(): def test_graphs():
from anki import Deck from anki import Deck
d = Deck(os.path.expanduser("~/rapid.anki")) d = Deck(os.path.expanduser("~/test.anki"))
g = d.graphs() g = d.graphs()
rep = g.report() rep = g.report()
open(os.path.expanduser("~/test.html"), "w").write(rep) open(os.path.expanduser("~/test.html"), "w").write(rep)