bundle js libs; include them in report(); fix some graph ids

This commit is contained in:
Damien Elmes 2011-03-25 18:37:18 +09:00
parent 6ec2500eb8
commit 9c1e0befc6
3 changed files with 23 additions and 19 deletions

View file

@ -4,6 +4,7 @@
import os, sys, time, datetime, simplejson import os, sys, time, datetime, simplejson
from anki.lang import _ from anki.lang import _
import anki.js
#colours for graphs #colours for graphs
dueYoungC = "#ffb380" dueYoungC = "#ffb380"
@ -28,6 +29,15 @@ class Graphs(object):
self._stats = None self._stats = None
self.selective = selective self.selective = selective
def report(self):
txt = (self.dueGraph() +
self.repsGraph() +
self.timeGraph() +
self.cumDueGraph() +
self.ivlGraph() +
self.easeGraph())
return "<script>%s</script>%s" % (anki.js.all, txt)
# Due and cumulative due # Due and cumulative due
###################################################################### ######################################################################
@ -83,7 +93,7 @@ group by due order by due""" % self._limit(),
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]))
txt = self._graph(id="due", data=[ txt = self._graph(id="reps", data=[
dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"),
color=reviewNewC, label=_("Learning")), color=reviewNewC, label=_("Learning")),
dict(data=yng, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=yng, bars=dict(show=True, barWidth=0.8, align="center"),
@ -100,13 +110,12 @@ group by due order by due""" % self._limit(),
for row in self._stats['done']: for row in self._stats['done']:
lrn.append((row[0], row[4])) lrn.append((row[0], row[4]))
rev.append((row[0], row[5])) rev.append((row[0], row[5]))
txt = self._graph(id="due", data=[ txt = self._graph(id="time", data=[
dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=lrn, bars=dict(show=True, barWidth=0.8, align="center"),
color=lrnTimeC, label=_("Learning")), color=lrnTimeC, label=_("Learning")),
dict(data=rev, bars=dict(show=True, barWidth=0.8, align="center"), dict(data=rev, bars=dict(show=True, barWidth=0.8, align="center"),
color=revTimeC, label=_("Reviews")), color=revTimeC, label=_("Reviews")),
]) ])
self.save(txt)
return txt return txt
def _done(self): def _done(self):
@ -212,13 +221,6 @@ $(function () {
else: else:
return "" return ""
def save(self, txt):
open(os.path.expanduser("~/test.html"), "w").write("""
<html><head>
<script src="jquery.min.js"></script>
<script src="jquery.flot.min.js"></script>
</head><body>%s</body></html>"""%txt)
def _addMissing(self, dic, min, max): def _addMissing(self, dic, min, max):
for i in range(min, max+1): for i in range(min, max+1):
if not i in dic: if not i in dic:

5
anki/js.py Normal file

File diff suppressed because one or more lines are too long

View file

@ -22,17 +22,14 @@ def test_stats():
# deck stats # deck stats
assert d.deckStats() assert d.deckStats()
def test_graphs_empty():
d = getEmptyDeck()
assert d.graphs().report()
def test_graphs(): def test_graphs():
from anki import Deck from anki import Deck
d = Deck(os.path.expanduser("~/test.anki")) d = Deck(os.path.expanduser("~/test.anki"))
g = d.graphs() g = d.graphs()
assert g.dueGraph() rep = g.report()
assert g.cumDueGraph() open(os.path.expanduser("~/test.html"), "w").write(rep)
assert g.ivlGraph()
assert g.easeGraph()
assert g.repsGraph()
assert g.timeGraph()
return return
g.workDone()
g.timeSpent()
g.addedRecently()