mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
switch args in rated: search; make ease optional
This commit is contained in:
parent
3382af2877
commit
17095ae1fb
2 changed files with 16 additions and 11 deletions
18
anki/find.py
18
anki/find.py
|
@ -243,18 +243,22 @@ class Finder(object):
|
|||
self.col.sched.today, self.col.sched.dayCutoff)
|
||||
|
||||
def _findRated(self, val):
|
||||
# days(:optional_ease)
|
||||
r = val.split(":")
|
||||
if len(r) != 2 or r[0] not in ("1", "2", "3", "4"):
|
||||
return
|
||||
try:
|
||||
days = int(r[1])
|
||||
days = int(r[0])
|
||||
except ValueError:
|
||||
return
|
||||
# bound the search
|
||||
days = min(days, 31)
|
||||
lim = self.col.sched.dayCutoff - 86400*days
|
||||
return ("c.id in (select cid from revlog where ease=%s and id>%d)" %
|
||||
(r[0], (lim*1000)))
|
||||
# ease
|
||||
ease = ""
|
||||
if len(r) > 1:
|
||||
if r[1] not in ("1", "2", "3", "4"):
|
||||
return
|
||||
ease = "and ease=%s" % r[1]
|
||||
cutoff = (self.col.sched.dayCutoff - 86400*days)*1000
|
||||
return ("c.id in (select cid from revlog where id>%d %s)" %
|
||||
(cutoff, ease))
|
||||
|
||||
def _findProp(self, val):
|
||||
# extract
|
||||
|
|
|
@ -179,16 +179,17 @@ def test_findCards():
|
|||
assert len(deck.findCards("-prop:ease>2")) > 1
|
||||
# recently failed
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:2:1")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 0
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 2)
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:2:1")) == 1
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 1)
|
||||
assert len(deck.findCards("rated:1:1")) == 1
|
||||
assert len(deck.findCards("rated:2:1")) == 1
|
||||
assert len(deck.findCards("rated:2:0")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
assert len(deck.findCards("rated:1")) == 2
|
||||
assert len(deck.findCards("rated:0:2")) == 0
|
||||
assert len(deck.findCards("rated:2:2")) == 1
|
||||
# empty field
|
||||
assert len(deck.findCards("front:")) == 0
|
||||
|
|
Loading…
Reference in a new issue