mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -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)
|
self.col.sched.today, self.col.sched.dayCutoff)
|
||||||
|
|
||||||
def _findRated(self, val):
|
def _findRated(self, val):
|
||||||
|
# days(:optional_ease)
|
||||||
r = val.split(":")
|
r = val.split(":")
|
||||||
if len(r) != 2 or r[0] not in ("1", "2", "3", "4"):
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
days = int(r[1])
|
days = int(r[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
# bound the search
|
|
||||||
days = min(days, 31)
|
days = min(days, 31)
|
||||||
lim = self.col.sched.dayCutoff - 86400*days
|
# ease
|
||||||
return ("c.id in (select cid from revlog where ease=%s and id>%d)" %
|
ease = ""
|
||||||
(r[0], (lim*1000)))
|
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):
|
def _findProp(self, val):
|
||||||
# extract
|
# extract
|
||||||
|
|
|
@ -179,16 +179,17 @@ def test_findCards():
|
||||||
assert len(deck.findCards("-prop:ease>2")) > 1
|
assert len(deck.findCards("-prop:ease>2")) > 1
|
||||||
# recently failed
|
# recently failed
|
||||||
assert len(deck.findCards("rated:1:1")) == 0
|
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()
|
c = deck.sched.getCard()
|
||||||
deck.sched.answerCard(c, 2)
|
deck.sched.answerCard(c, 2)
|
||||||
assert len(deck.findCards("rated:1:1")) == 0
|
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()
|
c = deck.sched.getCard()
|
||||||
deck.sched.answerCard(c, 1)
|
deck.sched.answerCard(c, 1)
|
||||||
assert len(deck.findCards("rated:1:1")) == 1
|
assert len(deck.findCards("rated:1:1")) == 1
|
||||||
assert len(deck.findCards("rated:2:1")) == 1
|
assert len(deck.findCards("rated:1:2")) == 1
|
||||||
assert len(deck.findCards("rated:2:0")) == 0
|
assert len(deck.findCards("rated:1")) == 2
|
||||||
|
assert len(deck.findCards("rated:0:2")) == 0
|
||||||
assert len(deck.findCards("rated:2:2")) == 1
|
assert len(deck.findCards("rated:2:2")) == 1
|
||||||
# empty field
|
# empty field
|
||||||
assert len(deck.findCards("front:")) == 0
|
assert len(deck.findCards("front:")) == 0
|
||||||
|
|
Loading…
Reference in a new issue