include the gid in the tree so we can tell which groups are real

This commit is contained in:
Damien Elmes 2011-03-29 10:04:53 +09:00
parent fc96e12a0a
commit 73625e5751
2 changed files with 27 additions and 22 deletions

View file

@ -123,7 +123,7 @@ sum(case when queue = 2 and due <= ? then 1 else 0 end),
sum(case when queue = 0 then 1 else 0 end) sum(case when queue = 0 then 1 else 0 end)
from cards group by gid""", self.today): from cards group by gid""", self.today):
gids[gid] = [all, rev, new] gids[gid] = [all, rev, new]
return [[name]+gids[gid] for (gid, name) in return [[name, gid]+gids[gid] for (gid, name) in
self.deck.db.execute( self.deck.db.execute(
"select id, name from groups order by name")] "select id, name from groups order by name")]
@ -140,6 +140,7 @@ from cards group by gid""", self.today):
return grp[0][0] return grp[0][0]
for (head, tail) in itertools.groupby(grps, key=key): for (head, tail) in itertools.groupby(grps, key=key):
tail = list(tail) tail = list(tail)
gid = None
all = 0 all = 0
rev = 0 rev = 0
new = 0 new = 0
@ -147,9 +148,10 @@ from cards group by gid""", self.today):
for c in tail: for c in tail:
if len(c[0]) == 1: if len(c[0]) == 1:
# current node # current node
all += c[1] gid = c[1]
rev += c[2] all += c[2]
new += c[3] rev += c[3]
new += c[4]
else: else:
# set new string to tail # set new string to tail
c[0] = c[0][1] c[0] = c[0][1]
@ -157,10 +159,10 @@ from cards group by gid""", self.today):
children = self._groupChildren(children) children = self._groupChildren(children)
# tally up children counts # tally up children counts
for ch in children: for ch in children:
all += ch[1] all += ch[2]
rev += ch[2] rev += ch[3]
new += ch[3] new += ch[4]
tree.append((head, all, rev, new, children)) tree.append((head, gid, all, rev, new, children))
return tuple(tree) return tuple(tree)
# Getting the next card # Getting the next card

View file

@ -621,24 +621,27 @@ def test_groupCounts():
assert d.sched.counts() == (3, 0, 1) assert d.sched.counts() == (3, 0, 1)
assert len(d.groups()) == 4 assert len(d.groups()) == 4
cnts = d.sched.groupCounts() cnts = d.sched.groupCounts()
assert cnts[0] == ["Default Group", 1, 0, 1] assert cnts[0] == ["Default Group", 1, 1, 0, 1]
assert cnts[1] == ["Default Group::1", 1, 1, 0] assert cnts[1] == ["Default Group::1", 2, 1, 1, 0]
assert cnts[2] == ["foo::bar", 1, 0, 1] assert cnts[2] == ["foo::bar", 3, 1, 0, 1]
assert cnts[3] == ["foo::baz", 1, 0, 1] assert cnts[3] == ["foo::baz", 4, 1, 0, 1]
tree = d.sched.groupCountTree() tree = d.sched.groupCountTree()
assert tree[0][0] == "Default Group" assert tree[0][0] == "Default Group"
# sum of child and parent # sum of child and parent
assert tree[0][1] == 2 assert tree[0][1] == 1
assert tree[0][2] == 1 assert tree[0][2] == 2
assert tree[0][3] == 1 assert tree[0][3] == 1
assert tree[0][4] == 1
# child count is just review # child count is just review
assert tree[0][4][0][0] == "1" assert tree[0][5][0][0] == "1"
assert tree[0][4][0][1] == 1 assert tree[0][5][0][1] == 2
assert tree[0][4][0][2] == 1 assert tree[0][5][0][2] == 1
assert tree[0][4][0][3] == 0 assert tree[0][5][0][3] == 1
assert tree[0][5][0][4] == 0
# event if parent group didn't exist, it should have been created with a # event if parent group didn't exist, it should have been created with a
# counts summary. # counts summary, with an empty gid
assert tree[1][0] == "foo" assert tree[1][0] == "foo"
assert tree[1][1] == 2 assert tree[1][1] == None
assert tree[1][2] == 0 assert tree[1][2] == 2
assert tree[1][3] == 2 assert tree[1][3] == 0
assert tree[1][4] == 2