mirror of
https://github.com/ankitects/anki.git
synced 2025-11-21 12:07:13 -05:00
counts by group
This commit is contained in:
parent
2d00163323
commit
728715ff84
2 changed files with 48 additions and 0 deletions
|
|
@ -111,6 +111,28 @@ order by due""" % self._groupLimit("rev"),
|
||||||
self._resetRevCount()
|
self._resetRevCount()
|
||||||
self._resetNewCount()
|
self._resetNewCount()
|
||||||
|
|
||||||
|
# Group counts
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
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
|
||||||
|
return [[name]+gids[gid] for (gid, name) in
|
||||||
|
self.deck.db.execute(
|
||||||
|
"select id, name from groups order by name")]
|
||||||
|
|
||||||
# Getting the next card
|
# Getting the next card
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -589,3 +589,29 @@ def test_collapse():
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
d.sched.answerCard(c, 3)
|
d.sched.answerCard(c, 3)
|
||||||
assert not d.sched.getCard()
|
assert not d.sched.getCard()
|
||||||
|
|
||||||
|
def test_groupCounts():
|
||||||
|
d = getEmptyDeck()
|
||||||
|
# add two facts
|
||||||
|
f = d.newFact()
|
||||||
|
f['Front'] = u"one"
|
||||||
|
d.addFact(f)
|
||||||
|
f = d.newFact()
|
||||||
|
f['Front'] = u"two"
|
||||||
|
d.addFact(f)
|
||||||
|
# make one a review card
|
||||||
|
c = f.cards()[0]
|
||||||
|
c.queue = 2
|
||||||
|
c.due = 0
|
||||||
|
c.flush()
|
||||||
|
# add one more with a new group
|
||||||
|
f = d.newFact()
|
||||||
|
f['Front'] = u"two"
|
||||||
|
f.gid = d.groupId("new")
|
||||||
|
d.addFact(f)
|
||||||
|
d.reset()
|
||||||
|
assert d.sched.counts() == (2, 0, 1)
|
||||||
|
assert len(d.groups()) == 2
|
||||||
|
cnts = d.sched.groupCounts()
|
||||||
|
assert cnts[0] == ["Default Group", 1, 1]
|
||||||
|
assert cnts[1] == ["new", 0, 1]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue