average time graph

probably won't use this, but saving the code
This commit is contained in:
Damien Elmes 2011-03-26 16:42:28 +09:00
parent 63efc4dbaa
commit f03745a1a3

View file

@ -13,6 +13,7 @@ colLearn = "#00F"
colRelearn = "#c00" colRelearn = "#c00"
colCram = "#ff0" colCram = "#ff0"
colIvl = "#077" colIvl = "#077"
colTime = "#770"
easesNewC = "#80b3ff" easesNewC = "#80b3ff"
easesYoungC = "#5555ff" easesYoungC = "#5555ff"
easesMatureC = "#0f5aff" easesMatureC = "#0f5aff"
@ -83,56 +84,64 @@ group by day order by day""" % (self._limit(), lim),
def repsGraph(self, days, reptitle, timetitle, chunk=1): def repsGraph(self, days, reptitle, timetitle, chunk=1):
d = self._done(days, chunk) d = self._done(days, chunk)
# reps
lrn = []
yng = []
mtr = []
lapse = []
cram = []
tot = 0
totd = []
for row in d:
lrn.append((row[0], row[1]))
yng.append((row[0], row[2]))
mtr.append((row[0], row[3]))
lapse.append((row[0], row[4]))
cram.append((row[0], row[5]))
tot += row[1]+row[2]+row[3]+row[4]+row[5]
totd.append((row[0], tot))
conf = dict( conf = dict(
xaxis=dict(tickDecimals=0), xaxis=dict(tickDecimals=0),
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
def plot(title): def plot(title, data):
return self._graph("g%d"%hash(title), title=title, data=[ return self._graph("g%d"%hash(title), title=title,
dict(data=mtr, color=colMature, label=_("Mature")), data=data, conf=conf)
dict(data=yng, color=colYoung, label=_("Young")), # reps
dict(data=lapse, color=colRelearn, label=_("Relearning")), (repdata, repsum) = self._splitRepData(d, (
dict(data=lrn, color=colLearn, label=_("Learning")), (3, colMature, _("Mature")),
dict(data=cram, color=colCram, label=_("Cramming")), (2, colYoung, _("Young")),
dict(data=totd, color=colCum, label=_("Cumulative"), yaxis=2, (4, colRelearn, _("Relearn")),
bars={'show': False}, lines=dict(show=True), stack=False) (1, colLearn, _("Learn")),
], conf=conf) (5, colCram, _("Cram"))))
txt = plot(reptitle) txt = plot(reptitle, repdata)
# time # time
lrn = [] (timdata, timsum) = self._splitRepData(d, (
yng = [] (8, colMature, _("Mature")),
mtr = [] (7, colYoung, _("Young")),
lapse = [] (9, colRelearn, _("Relearn")),
cram = [] (6, colLearn, _("Learn")),
(10, colCram, _("Cram"))))
txt += plot(timetitle, timdata)
# work out average time
avgdata = [
(period, reps and (timsum[c][1]*3600 / reps) or 0)
for c, (period, reps) in enumerate(repsum)
]
del conf['yaxes']
txt += self._graph("gr%d"%hash(reptitle), title="avg"+reptitle,
data=[dict(
data=avgdata, color=colTime, label=_("Avg Time"))],
conf=conf)
return txt
def _splitRepData(self, data, spec):
sep = {}
tot = 0 tot = 0
totd = [] totd = []
for row in d: sum = []
lrn.append((row[0], row[6])) for row in data:
yng.append((row[0], row[7])) rowtot = 0
mtr.append((row[0], row[8])) for (n, col, lab) in spec:
lapse.append((row[0], row[9])) if n not in sep:
cram.append((row[0], row[10])) sep[n] = []
tot += row[6]+row[7]+row[8]+row[9]+row[10] sep[n].append((row[0], row[n]))
tot += row[n]
rowtot += row[n]
totd.append((row[0], tot)) totd.append((row[0], tot))
txt += plot(timetitle) sum.append((row[0], rowtot))
return txt ret = []
for (n, col, lab) in spec:
ret.append(dict(data=sep[n], color=col, label=lab))
ret.append(dict(
data=totd, color=colCum, label=_("Cumulative"), yaxis=2,
bars={'show': False}, lines=dict(show=True), stack=False))
return (ret, sum)
def _done(self, num=7, chunk=1): def _done(self, num=7, chunk=1):
# without selective for now # without selective for now