mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
include total count in with rev+due
This commit is contained in:
parent
2a1355eb16
commit
495b058618
2 changed files with 27 additions and 27 deletions
|
@ -117,18 +117,12 @@ order by due""" % self._groupLimit("rev"),
|
|||
def groupCounts(self):
|
||||
"Returns [groupname, cards, due, new]"
|
||||
gids = {}
|
||||
for (gid, cnt) in self.deck.db.execute("""
|
||||
select gid, count() from cards
|
||||
where queue = 2 and due <= ?
|
||||
group by gid""", self.today):
|
||||
gids[gid] = [cnt, 0]
|
||||
# fixme: might want to add due in to use idx
|
||||
for (gid, cnt) in self.deck.db.execute(
|
||||
"select gid, count() from cards where queue = 0 group by gid"):
|
||||
if gid not in gids:
|
||||
gids[gid] = [0, cnt]
|
||||
else:
|
||||
gids[gid][1] = cnt
|
||||
for (gid, all, rev, new) in self.deck.db.execute("""
|
||||
select gid, count(),
|
||||
sum(case when queue = 2 and due <= ? then 1 else 0 end),
|
||||
sum(case when queue = 0 then 1 else 0 end)
|
||||
from cards group by gid""", self.today):
|
||||
gids[gid] = [all, rev, new]
|
||||
return [[name]+gids[gid] for (gid, name) in
|
||||
self.deck.db.execute(
|
||||
"select id, name from groups order by name")]
|
||||
|
@ -146,14 +140,16 @@ group by gid""", self.today):
|
|||
return grp[0][0]
|
||||
for (head, tail) in itertools.groupby(grps, key=key):
|
||||
tail = list(tail)
|
||||
all = 0
|
||||
rev = 0
|
||||
new = 0
|
||||
children = []
|
||||
for c in tail:
|
||||
if len(c[0]) == 1:
|
||||
# current node
|
||||
rev += c[1]
|
||||
new += c[2]
|
||||
all += c[1]
|
||||
rev += c[2]
|
||||
new += c[3]
|
||||
else:
|
||||
# set new string to tail
|
||||
c[0] = c[0][1]
|
||||
|
@ -161,9 +157,10 @@ group by gid""", self.today):
|
|||
children = self._groupChildren(children)
|
||||
# tally up children counts
|
||||
for ch in children:
|
||||
rev += ch[1]
|
||||
new += ch[2]
|
||||
tree.append((head, rev, new, children))
|
||||
all += ch[1]
|
||||
rev += ch[2]
|
||||
new += ch[3]
|
||||
tree.append((head, all, rev, new, children))
|
||||
return tuple(tree)
|
||||
|
||||
# Getting the next card
|
||||
|
|
|
@ -620,21 +620,24 @@ def test_groupCounts():
|
|||
assert d.sched.counts() == (3, 0, 1)
|
||||
assert len(d.groups()) == 4
|
||||
cnts = d.sched.groupCounts()
|
||||
assert cnts[0] == ["Default Group", 0, 1]
|
||||
assert cnts[1] == ["Default Group::1", 1, 0]
|
||||
assert cnts[2] == ["foo::bar", 0, 1]
|
||||
assert cnts[3] == ["foo::baz", 0, 1]
|
||||
assert cnts[0] == ["Default Group", 1, 0, 1]
|
||||
assert cnts[1] == ["Default Group::1", 1, 1, 0]
|
||||
assert cnts[2] == ["foo::bar", 1, 0, 1]
|
||||
assert cnts[3] == ["foo::baz", 1, 0, 1]
|
||||
tree = d.sched.groupCountTree()
|
||||
assert tree[0][0] == "Default Group"
|
||||
# sum of child and parent
|
||||
assert tree[0][1] == 1
|
||||
assert tree[0][1] == 2
|
||||
assert tree[0][2] == 1
|
||||
assert tree[0][3] == 1
|
||||
# child count is just review
|
||||
assert tree[0][3][0][0] == "1"
|
||||
assert tree[0][3][0][1] == 1
|
||||
assert tree[0][3][0][2] == 0
|
||||
assert tree[0][4][0][0] == "1"
|
||||
assert tree[0][4][0][1] == 1
|
||||
assert tree[0][4][0][2] == 1
|
||||
assert tree[0][4][0][3] == 0
|
||||
# event if parent group didn't exist, it should have been created with a
|
||||
# counts summary.
|
||||
assert tree[1][0] == "foo"
|
||||
assert tree[1][1] == 0
|
||||
assert tree[1][2] == 2
|
||||
assert tree[1][1] == 2
|
||||
assert tree[1][2] == 0
|
||||
assert tree[1][3] == 2
|
||||
|
|
Loading…
Reference in a new issue