seperated cards due graph into three layers: new, young and mature.

This commit is contained in:
Timo Paulssen 2008-12-03 21:26:43 +01:00
parent 1532868401
commit 3a1f6a9274

View file

@ -43,6 +43,9 @@ class DeckGraphs(object):
def calcStats (self): def calcStats (self):
if not self.stats: if not self.stats:
days = {} days = {}
daysNew = {}
daysYoung = {}
daysMature = {}
months = {} months = {}
next = {} next = {}
lowestInDay = 0 lowestInDay = 0
@ -50,20 +53,32 @@ class DeckGraphs(object):
now[3] = 23; now[4] = 59 now[3] = 23; now[4] = 59
self.endOfDay = time.mktime(now) + self.deck.utcOffset self.endOfDay = time.mktime(now) + self.deck.utcOffset
t = time.time() t = time.time()
all = self.deck.s.all(""" new = self.deck.s.all("""
select interval, combinedDue select interval, combinedDue
from cards where reps > 0 and priority != 0""") from cards where reps > 0 and priority != 0 and type = 2""")
for (interval, due) in all: young = self.deck.s.all("""
day=int(round(interval)) select interval, combinedDue
days[day] = days.get(day, 0) + 1 from cards where reps > 0 and priority != 0 and (type = 0 or (type = 1 and interval <= 21))""")
indays = int(round((due - self.endOfDay) mature = self.deck.s.all("""
/ 86400.0)) select interval, combinedDue
next[indays] = next.get(indays, 0) + 1 from cards where reps > 0 and priority != 0 and type = 1 and interval > 21""")
if indays < lowestInDay:
lowestInDay = indays for (src, dest) in [(new, daysNew), (young, daysYoung), (mature, daysMature)]:
for (interval, due) in src:
day=int(round(interval))
days[day] = days.get(day, 0) + 1
indays = int((due - self.endOfDay)
/ 86400.0)
next[indays] = next.get(indays, 0) + 1 # type-agnostic stats
dest[indays] = dest.get(indays, 0) + 1 # type-specific stats
if indays < lowestInDay:
lowestInDay = indays
self.stats = {} self.stats = {}
self.stats['next'] = next self.stats['next'] = next
self.stats['days'] = days self.stats['days'] = days
self.stats['daysByType'] = {'new': daysNew,
'young': daysYoung,
'mature': daysMature}
self.stats['months'] = months self.stats['months'] = months
self.stats['lowestInDay'] = lowestInDay self.stats['lowestInDay'] = lowestInDay
@ -71,10 +86,21 @@ from cards where reps > 0 and priority != 0""")
self.calcStats() self.calcStats()
fig = Figure(figsize=(self.width, self.height), dpi=self.dpi) fig = Figure(figsize=(self.width, self.height), dpi=self.dpi)
graph = fig.add_subplot(111) graph = fig.add_subplot(111)
dayslist = self.stats['next'] dayslists = [self.stats['next'], self.stats['daysByType']['young'], self.stats['daysByType']['new']]
self.addMissing(dayslist, self.stats['lowestInDay'], days)
(x, y) = self.unzip(dayslist.items()) for dayslist in dayslists:
self.filledGraph(graph, days, x, y, "#4444ff") self.addMissing(dayslist, self.stats['lowestInDay'], days)
for i in range(days):
dayslists[1][i] += dayslists[2][i]
argl = []
for dayslist in dayslists:
argl.extend(list(self.unzip(dayslist.items())))
self.filledGraph(graph, days, ["#7777ff", "#77ffff", "#ff7777"], *argl)
graph.set_ylabel(_("Cards")) graph.set_ylabel(_("Cards"))
graph.set_xlabel(_("Days")) graph.set_xlabel(_("Days"))
graph.set_xlim(xmin=self.stats['lowestInDay'], xmax=days) graph.set_xlim(xmin=self.stats['lowestInDay'], xmax=days)
@ -96,7 +122,7 @@ from cards where reps > 0 and priority != 0""")
break break
x = list(x); x.append(99999) x = list(x); x.append(99999)
y.append(count) y.append(count)
self.filledGraph(graph, days, x, y, "#aaaaff") self.filledGraph(graph, days, "#aaaaff", x, y)
graph.set_ylabel(_("Cards")) graph.set_ylabel(_("Cards"))
graph.set_xlabel(_("Days")) graph.set_xlabel(_("Days"))
graph.set_xlim(xmin=self.stats['lowestInDay'], xmax=days) graph.set_xlim(xmin=self.stats['lowestInDay'], xmax=days)
@ -110,7 +136,7 @@ from cards where reps > 0 and priority != 0""")
self.addMissing(ints, 0, days) self.addMissing(ints, 0, days)
intervals = self.unzip(ints.items()) intervals = self.unzip(ints.items())
graph = fig.add_subplot(111) graph = fig.add_subplot(111)
self.filledGraph(graph, days, intervals[0], intervals[1], "#aaffaa") self.filledGraph(graph, days, "#aaffaa", *intervals)
graph.set_ylabel(_("Cards")) graph.set_ylabel(_("Cards"))
graph.set_xlabel(_("Days")) graph.set_xlabel(_("Days"))
graph.set_xlim(xmin=0, xmax=days) graph.set_xlim(xmin=0, xmax=days)
@ -132,7 +158,7 @@ from cards where reps > 0 and priority != 0""")
colour = "#ffaaaa" colour = "#ffaaaa"
else: else:
colour = "#ffcccc" colour = "#ffcccc"
self.filledGraph(graph, numdays, intervals[0], intervals[1], colour) self.filledGraph(graph, numdays, colour, *intervals)
graph.set_ylabel(_("Cards")) graph.set_ylabel(_("Cards"))
graph.set_xlabel(_("Day")) graph.set_xlabel(_("Day"))
graph.set_xlim(xmin=-numdays, xmax=0) graph.set_xlim(xmin=-numdays, xmax=0)
@ -148,29 +174,32 @@ from cards where reps > 0 and priority != 0""")
new = zip(*tuples) new = zip(*tuples)
return new return new
def filledGraph(self, graph, days, x=(), y=(), c="b"): def filledGraph(self, graph, days, colours=["b"], *args):
x = list(x) if isinstance(colours, str):
y = list(y) colours = [colours]
lowest = 99999 thick = True
highest = -lowest for triplet in [(args[n], args[n + 1], colours[n / 2]) for n in range(0, len(args), 2)]:
for i in range(len(x)): x = list(triplet[0])
if x[i] < lowest: y = list(triplet[1])
lowest = x[i] c = triplet[2]
if x[i] > highest: lowest = 99999
highest = x[i] highest = -lowest
# ensure the filled area reaches the bottom for i in range(len(x)):
x.insert(0, lowest - 1) if x[i] < lowest:
y.insert(0, 0) lowest = x[i]
x.append(highest + 1) if x[i] > highest:
y.append(0) highest = x[i]
# plot # ensure the filled area reaches the bottom
graph.fill(x, y, c) x.insert(0, lowest - 1)
if days < 180: y.insert(0, 0)
graph.bar(x, y, width=0) x.append(highest + 1)
lw=3 y.append(0)
else: # plot
lw=1 graph.fill(x, y, c, lw = int(days < 180 and thick) * 2 + int(days >= 180 and thick))
graph.plot(x, y, "k", lw=lw) if days < 180:
graph.bar(x, y, width=0)
thick = False
graph.grid(True) graph.grid(True)
graph.set_ylim(ymin=0, ymax=max(2, graph.get_ylim()[1])) graph.set_ylim(ymin=0, ymax=max(2, graph.get_ylim()[1]))