remove unused deckDueList() and associated tree code

The progress bar add-ons appear to be the only active users of it;
they can switch their old code from iterating over the list to
simply locating the selected deck in deckDueTree(), as its counts should
summarize all the child decks.
This commit is contained in:
Damien Elmes 2020-05-15 18:37:12 +10:00
parent e44b3bf93c
commit 769bf04f75
6 changed files with 4 additions and 176 deletions

View file

@ -3,18 +3,15 @@
from __future__ import annotations from __future__ import annotations
import itertools
import random import random
import time import time
from heapq import * from heapq import *
from operator import itemgetter
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
import anki import anki
from anki import hooks from anki import hooks
from anki.cards import Card from anki.cards import Card
from anki.consts import * from anki.consts import *
from anki.decks import DeckManager
from anki.schedv2 import Scheduler as V2 from anki.schedv2 import Scheduler as V2
from anki.utils import ids2str, intTime from anki.utils import ids2str, intTime
@ -141,77 +138,6 @@ class Scheduler(V2):
self.col.usn(), self.col.usn(),
) )
# Deck list
##########################################################################
def deckDueList(self) -> List[List[Any]]:
"Returns [deckname, did, rev, lrn, new]"
self._checkDay()
self.col.decks.checkIntegrity()
decks = self.col.decks.all()
decks.sort(key=itemgetter("name"))
lims: Dict[str, List[int]] = {}
data = []
for deck in decks:
p = DeckManager.immediate_parent(deck["name"])
# new
nlim = self._deckNewLimitSingle(deck)
if p is not None:
nlim = min(nlim, lims[p][0])
new = self._newForDeck(deck["id"], nlim)
# learning
lrn = self._lrnForDeck(deck["id"])
# reviews
rlim = self._deckRevLimitSingle(deck)
if p:
rlim = min(rlim, lims[p][1])
rev = self._revForDeck(deck["id"], rlim)
# save to list
data.append([deck["name"], deck["id"], rev, lrn, new])
# add deck as a parent
lims[deck["name"]] = [nlim, rlim]
return data
def _groupChildrenMain(self, grps: List[List[Any]]) -> Any:
tree = []
# group and recurse
def key(grp):
return grp[0][0]
for (head, tail) in itertools.groupby(grps, key=key):
tail = list(tail) # type: ignore
did = None
rev = 0
new = 0
lrn = 0
children = []
for c in tail:
if len(c[0]) == 1:
# current node
did = c[1]
rev += c[2]
lrn += c[3]
new += c[4]
else:
# set new string to tail
c[0] = c[0][1:]
children.append(c)
children = self._groupChildrenMain(children)
# tally up children counts
for ch in children:
rev += ch[2]
lrn += ch[3]
new += ch[4]
# limit the counts to the deck's limits
conf = self.col.decks.confForDid(did)
deck = self.col.decks.get(did)
if not conf["dyn"]:
rev = max(0, min(rev, conf["rev"]["perDay"] - deck["revToday"][1]))
new = max(0, min(new, self._deckNewLimitSingle(deck)))
tree.append((head, did, rev, lrn, new, children))
return tuple(tree)
# Getting the next card # Getting the next card
########################################################################## ##########################################################################

View file

@ -3,11 +3,9 @@
from __future__ import annotations from __future__ import annotations
import itertools
import random import random
import time import time
from heapq import * from heapq import *
from operator import itemgetter
# from anki.collection import _Collection # from anki.collection import _Collection
from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Union from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Union
@ -16,7 +14,6 @@ import anki # pylint: disable=unused-import
from anki import hooks from anki import hooks
from anki.cards import Card from anki.cards import Card
from anki.consts import * from anki.consts import *
from anki.decks import DeckManager
from anki.lang import _ from anki.lang import _
from anki.rsbackend import FormatTimeSpanContext, SchedTimingToday from anki.rsbackend import FormatTimeSpanContext, SchedTimingToday
from anki.utils import ids2str, intTime from anki.utils import ids2str, intTime
@ -231,87 +228,10 @@ order by due"""
# Deck list # Deck list
########################################################################## ##########################################################################
def deckDueList(self) -> List[List[Any]]:
"Returns [deckname, did, rev, lrn, new]"
self._checkDay()
self.col.decks.checkIntegrity()
decks = self.col.decks.all()
decks.sort(key=itemgetter("name"))
lims: Dict[str, List[int]] = {}
data = []
childMap = self.col.decks.childMap()
for deck in decks:
p = DeckManager.immediate_parent(deck["name"])
# new
nlim = self._deckNewLimitSingle(deck)
if p is not None:
nlim = min(nlim, lims[p][0])
new = self._newForDeck(deck["id"], nlim)
# learning
lrn = self._lrnForDeck(deck["id"])
# reviews
if p:
plim = lims[p][1]
else:
plim = None
rlim = self._deckRevLimitSingle(deck, parentLimit=plim)
rev = self._revForDeck(deck["id"], rlim, childMap)
# save to list
data.append([deck["name"], deck["id"], rev, lrn, new])
# add deck as a parent
lims[deck["name"]] = [nlim, rlim]
return data
def deckDueTree(self) -> Any: def deckDueTree(self) -> Any:
"List of (base name, did, rev, lrn, new, children)"
return self.col.backend.legacy_deck_tree() return self.col.backend.legacy_deck_tree()
def _groupChildren(self, grps: List[List[Any]]) -> Any:
# first, split the group names into components
for g in grps:
g[0] = DeckManager.path(g[0])
# and sort based on those components
grps.sort(key=itemgetter(0))
# then run main function
return self._groupChildrenMain(grps)
def _groupChildrenMain(self, grps: List[List[Any]]) -> Any:
tree = []
# group and recurse
def key(grp):
return grp[0][0]
for (head, tail) in itertools.groupby(grps, key=key):
tail = list(tail) # type: ignore
did = None
rev = 0
new = 0
lrn = 0
children: Any = []
for c in tail:
if len(c[0]) == 1:
# current node
did = c[1]
rev += c[2]
lrn += c[3]
new += c[4]
else:
# set new string to tail
c[0] = c[0][1:]
children.append(c)
children = self._groupChildrenMain(children)
# tally up children counts
for ch in children:
lrn += ch[3]
new += ch[4]
# limit the counts to the deck's limits
conf = self.col.decks.confForDid(did)
deck = self.col.decks.get(did)
if not conf["dyn"]:
new = max(0, min(new, self._deckNewLimitSingle(deck)))
tree.append((head, did, rev, lrn, new, children))
return tuple(tree)
# Getting the next card # Getting the next card
########################################################################## ##########################################################################

View file

@ -216,8 +216,6 @@ class Syncer:
if found: if found:
self.col.models.save() self.col.models.save()
self.col.sched.reset() self.col.sched.reset()
# check for missing parent decks
self.col.sched.deckDueList()
# return summary of deck # return summary of deck
return [ return [
list(self.col.sched.counts()), list(self.col.sched.counts()),

View file

@ -40,8 +40,6 @@ def test_basic():
n = deck.newNote() n = deck.newNote()
n["Front"] = "abc" n["Front"] = "abc"
deck.addNote(n) deck.addNote(n)
# this will error if child and parent case don't match
deck.sched.deckDueList()
def test_remove(): def test_remove():

View file

@ -620,7 +620,7 @@ def test_cram():
d.sched.rebuildDyn(did) d.sched.rebuildDyn(did)
d.reset() d.reset()
# should appear as new in the deck list # should appear as new in the deck list
assert sorted(d.sched.deckDueList())[0][4] == 1 assert sorted(d.sched.deckDueTree())[0][4] == 1
# and should appear in the counts # and should appear in the counts
assert d.sched.counts() == (1, 0, 0) assert d.sched.counts() == (1, 0, 0)
# grab it and check estimates # grab it and check estimates
@ -674,7 +674,7 @@ def test_cram():
assert d.sched.nextIvl(c, 3) == 86400 assert d.sched.nextIvl(c, 3) == 86400
# delete the deck, returning the card mid-study # delete the deck, returning the card mid-study
d.decks.rem(d.decks.selected()) d.decks.rem(d.decks.selected())
assert len(d.sched.deckDueList()) == 1 assert len(d.sched.deckDueTree()) == 1
c.load() c.load()
assert c.ivl == 1 assert c.ivl == 1
assert c.due == d.sched.today + 1 assert c.due == d.sched.today + 1
@ -1020,12 +1020,6 @@ def test_deckDue():
d.addNote(f) d.addNote(f)
d.reset() d.reset()
assert len(d.decks.all_names_and_ids()) == 5 assert len(d.decks.all_names_and_ids()) == 5
cnts = d.sched.deckDueList()
assert cnts[0] == ["Default", 1, 0, 0, 1]
assert cnts[1] == ["Default::1", default1, 1, 0, 0]
assert cnts[2] == ["foo", d.decks.id("foo"), 0, 0, 0]
assert cnts[3] == ["foo::bar", foobar, 0, 0, 1]
assert cnts[4] == ["foo::baz", foobaz, 0, 0, 1]
tree = d.sched.deckDueTree() tree = d.sched.deckDueTree()
assert tree[0][0] == "Default" assert tree[0][0] == "Default"
# sum of child and parent # sum of child and parent
@ -1040,7 +1034,6 @@ def test_deckDue():
# code should not fail if a card has an invalid deck # code should not fail if a card has an invalid deck
c.did = 12345 c.did = 12345
c.flush() c.flush()
d.sched.deckDueList()
d.sched.deckDueTree() d.sched.deckDueTree()

View file

@ -721,7 +721,7 @@ def test_filt_reviewing_early_normal():
d.sched.rebuildDyn(did) d.sched.rebuildDyn(did)
d.reset() d.reset()
# should appear as normal in the deck list # should appear as normal in the deck list
assert sorted(d.sched.deckDueList())[0][2] == 1 assert sorted(d.sched.deckDueTree())[0][2] == 1
# and should appear in the counts # and should appear in the counts
assert d.sched.counts() == (0, 0, 1) assert d.sched.counts() == (0, 0, 1)
# grab it and check estimates # grab it and check estimates
@ -1023,12 +1023,6 @@ def test_deckDue():
d.addNote(f) d.addNote(f)
d.reset() d.reset()
assert len(d.decks.all_names_and_ids()) == 5 assert len(d.decks.all_names_and_ids()) == 5
cnts = d.sched.deckDueList()
assert cnts[0] == ["Default", 1, 1, 0, 1]
assert cnts[1] == ["Default::1", default1, 1, 0, 0]
assert cnts[2] == ["foo", d.decks.id("foo"), 0, 0, 0]
assert cnts[3] == ["foo::bar", foobar, 0, 0, 1]
assert cnts[4] == ["foo::baz", foobaz, 0, 0, 1]
tree = d.sched.deckDueTree() tree = d.sched.deckDueTree()
assert tree[0][0] == "Default" assert tree[0][0] == "Default"
# sum of child and parent # sum of child and parent
@ -1043,7 +1037,6 @@ def test_deckDue():
# code should not fail if a card has an invalid deck # code should not fail if a card has an invalid deck
c.did = 12345 c.did = 12345
c.flush() c.flush()
d.sched.deckDueList()
d.sched.deckDueTree() d.sched.deckDueTree()