From 7d5d72adf817f8bd0d09f69117d81e2afcd6e2e4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 25 Mar 2011 12:52:36 +0900 Subject: [PATCH] add intervals, boxing in weeks for now --- anki/graphs.py | 44 +++++++++++++++++++++++++------------------- tests/test_stats.py | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/anki/graphs.py b/anki/graphs.py index 3be12e7d4..1f540aa45 100644 --- a/anki/graphs.py +++ b/anki/graphs.py @@ -72,19 +72,6 @@ class Graphs(object): graph.set_ylabel("Minutes") return fig - def ivlPeriod(self, days=30): - self._calcStats() - fig = Figure(figsize=(self.width, self.height), dpi=self.dpi) - ints = self.stats['days'] - self._addMissing(ints, 0, days) - ivls = self._unzip(ints.items(), limit=days) - graph = fig.add_subplot(111) - self._varGraph(graph, days, intervC, *ivls) - graph.set_xlim(xmin=0, xmax=days+1) - graph.set_xlabel("Card Interval") - graph.set_ylabel("Number of Cards") - return fig - def addedRecently(self, numdays=30, attr='crt'): self._calcStats() days = {} @@ -167,6 +154,7 @@ as type, ease, count() from revlog group by type, ease""") return self._stats = {} self._stats['due'] = self._dueCards() + self._stats['ivls'] = self._ivls() return days = {} @@ -219,17 +207,13 @@ from cards where queue = 1 and ivl > 21""" *(int(x)for x in dr[1].split("-")))).days, dr[4]/60.0), dayReps)) def _dueCards(self, days=7): - if self.selective: - extra = self.deck.sched._groupLimit("rev") - else: - extra = "" return self.deck.db.all(""" select due-:today, count(), -- all sum(case when ivl >= 21 then 1 else 0 end) -- mature from cards where queue = 2 and due < (:today+:days) %s -group by due order by due""" % extra, +group by due order by due""" % self._limit(), today=self.deck.sched.today, days=days) def _graph(self, id, data, conf={}, width=600, height=200): @@ -274,12 +258,34 @@ $(function () { for day in d: tot += day[1]+day[2] days.append((day[0], tot)) - txt = self._graph(id="due", data=[ + txt = self._graph(id="cum", data=[ dict(data=days, lines=dict(show=True, fill=True), color=dueCumulC, label=_("Cards")), ]) self.save(txt) + def _limit(self): + if self.selective: + return self.deck.sched._groupLimit("rev") + else: + return "" + + def _ivls(self): + return self.deck.db.all(""" +select ivl / 7, count() from cards +where queue = 2 %s +group by ivl / 7 +order by ivl / 7""" % self._limit()) + + def ivlGraph(self): + self._calcStats() + ivls = self._stats['ivls'] + txt = self._graph(id="ivl", data=[ + dict(data=ivls, bars=dict(show=True, barWidth=0.8), + color=intervC) + ]) + self.save(txt) + def _getDayReps(self): return self.deck.db.all(""" select diff --git a/tests/test_stats.py b/tests/test_stats.py index b2cef21dd..be405fc75 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -27,7 +27,7 @@ def test_graphs(): d = Deck(os.path.expanduser("~/test.anki")) g = d.graphs() g._calcStats() - g.cumDueGraph() + g.ivlGraph() return g.nextDue() g.workDone()