diff --git a/pylib/anki/consts.py b/pylib/anki/consts.py index d0eba1499..1d2b35910 100644 --- a/pylib/anki/consts.py +++ b/pylib/anki/consts.py @@ -21,12 +21,14 @@ QUEUE_TYPE_SUSPENDED = -1 QUEUE_TYPE_NEW = 0 QUEUE_TYPE_LRN = 1 QUEUE_TYPE_REV = 2 +QUEUE_TYPE_DAY_LEARN_RELEARN = 3 QUEUE_TYPE_PREVIEW = 4 # Card types CARD_TYPE_NEW = 0 CARD_TYPE_LRN = 1 CARD_TYPE_REV = 2 +CARD_TYPE_RELEARNING = 3 # removal types REM_CARD = 0 diff --git a/pylib/anki/find.py b/pylib/anki/find.py index 026307c70..847d4e05f 100644 --- a/pylib/anki/find.py +++ b/pylib/anki/find.py @@ -273,7 +273,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """ elif val == "new": n = CARD_TYPE_NEW else: - return f"queue in ({QUEUE_TYPE_LRN}, 3)" + return f"queue in ({QUEUE_TYPE_LRN}, {QUEUE_TYPE_DAY_LEARN_RELEARN})" return "type = %d" % n elif val == "suspended": return "c.queue = -1" @@ -281,7 +281,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """ return f"c.queue in ({QUEUE_TYPE_SIBLING_BURIED}, {QUEUE_TYPE_MANUALLY_BURIED})" elif val == "due": return f""" -(c.queue in ({QUEUE_TYPE_REV},3) and c.due <= %d) or +(c.queue in ({QUEUE_TYPE_REV},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and c.due <= %d) or (c.queue = {QUEUE_TYPE_LRN} and c.due <= %d)""" % ( self.col.sched.today, self.col.sched.dayCutoff, @@ -349,7 +349,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """ if prop == "due": val += self.col.sched.today # only valid for review/daily learning - q.append(f"(c.queue in ({QUEUE_TYPE_REV},3))") + q.append(f"(c.queue in ({QUEUE_TYPE_REV},{QUEUE_TYPE_DAY_LEARN_RELEARN}))") elif prop == "ease": prop = "factor" val = int(val * 1000) diff --git a/pylib/anki/importing/anki2.py b/pylib/anki/importing/anki2.py index e7f952614..77818e426 100644 --- a/pylib/anki/importing/anki2.py +++ b/pylib/anki/importing/anki2.py @@ -344,7 +344,7 @@ class Anki2Importer(Importer): card[4] = intTime() card[5] = usn # review cards have a due date relative to collection - if card[7] in (QUEUE_TYPE_REV, 3) or card[6] == CARD_TYPE_REV: + if card[7] in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN) or card[6] == CARD_TYPE_REV: card[8] -= aheadBy # odue needs updating too if card[14]: diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index f30dedbe6..0542d303d 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -84,7 +84,7 @@ class Scheduler: card.ivl = self._dynIvlBoost(card) card.odue = self.today + card.ivl self._updateStats(card, "new") - if card.queue in (QUEUE_TYPE_LRN, 3): + if card.queue in (QUEUE_TYPE_LRN, QUEUE_TYPE_DAY_LEARN_RELEARN): self._answerLrnCard(card, ease) if not wasNewQ: self._updateStats(card, "lrn") @@ -132,7 +132,7 @@ order by due""" return ret def countIdx(self, card): - if card.queue == 3: + if card.queue == QUEUE_TYPE_DAY_LEARN_RELEARN: return 1 return card.queue @@ -476,8 +476,8 @@ did in %s and queue = {QUEUE_TYPE_LRN} and due < ? limit %d)""" ) # day self.lrnCount += self.col.db.scalar( - """ -select count() from cards where did in %s and queue = 3 + f""" +select count() from cards where did in %s and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit %d""" % (self._deckLimit(), self.reportLimit), self.today, @@ -528,9 +528,9 @@ limit %d""" did = self._lrnDids[0] # fill the queue with the current did self._lrnDayQueue = self.col.db.list( - """ + f""" select id from cards where -did = ? and queue = 3 and due <= ? limit ?""", +did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", did, self.today, self.queueLimit, @@ -611,7 +611,7 @@ did = ? and queue = 3 and due <= ? limit ?""", # day learn queue ahead = ((card.due - self.dayCutoff) // 86400) + 1 card.due = self.today + ahead - card.queue = 3 + card.queue = QUEUE_TYPE_DAY_LEARN_RELEARN self._logLrn(card, ease, conf, leaving, type, lastLeft) def _delayForGrade(self, conf, left): @@ -739,14 +739,14 @@ did = ? and queue = 3 and due <= ? limit ?""", f""" update cards set due = odue, queue = {QUEUE_TYPE_REV}, mod = %d, usn = %d, odue = 0 -where queue in ({QUEUE_TYPE_LRN},3) and type = {CARD_TYPE_REV} +where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type = {CARD_TYPE_REV} %s """ % (intTime(), self.col.usn(), extra) ) # new cards in learning self.forgetCards( - self.col.db.list(f"select id from cards where queue in ({QUEUE_TYPE_LRN},3) %s" % extra) + self.col.db.list(f"select id from cards where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) %s" % extra) ) def _lrnForDeck(self, did): @@ -762,9 +762,9 @@ select sum(left/1000) from or 0 ) return cnt + self.col.db.scalar( - """ + f""" select count() from -(select 1 from cards where did = ? and queue = 3 +(select 1 from cards where did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?)""", did, self.today, @@ -913,7 +913,7 @@ select id from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? l # day learn queue ahead = ((card.due - self.dayCutoff) // 86400) + 1 card.due = self.today + ahead - card.queue = 3 + card.queue = QUEUE_TYPE_DAY_LEARN_RELEARN return delay def _nextLapseIvl(self, card, conf): @@ -1347,7 +1347,7 @@ To study outside of the normal schedule, click the Custom Study button below.""" def nextIvl(self, card, ease): "Return the next interval for CARD, in seconds." - if card.queue in (QUEUE_TYPE_NEW, QUEUE_TYPE_LRN, 3): + if card.queue in (QUEUE_TYPE_NEW, QUEUE_TYPE_LRN, QUEUE_TYPE_DAY_LEARN_RELEARN): return self._nextLrnIvl(card, ease) elif ease == BUTTON_ONE: # lapsed diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 725259bab..498644d20 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -22,10 +22,8 @@ from anki.rsbackend import SchedTimingToday from anki.utils import fmtTimeSpan, ids2str, intTime # card types: 0=new, 1=lrn, 2=rev, 3=relrn -CARD_TYPE_RELEARNING = 3 # queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn, # 4=preview, -1=suspended, -2=sibling buried, -3=manually buried -QUEUE_TYPE_DAY_LEARN_RELEARN = 3 # revlog types: 0=lrn, 1=rev, 2=relrn, 3=early review # positive revlog intervals are in days (rev), negative in seconds (lrn) diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index 5fad0dd30..e1cc18922 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -39,7 +39,7 @@ class CardStats: if c.odid or c.queue < QUEUE_TYPE_NEW: next = None else: - if c.queue in (QUEUE_TYPE_REV, 3): + if c.queue in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN): next = time.time() + ((c.due - self.col.sched.today) * 86400) else: next = c.due @@ -285,7 +285,7 @@ from revlog where id > ? """ self._line(i, _("Average"), self._avgDay(tot, num, _("reviews"))) tomorrow = self.col.db.scalar( f""" -select count() from cards where did in %s and queue in ({QUEUE_TYPE_REV},3) +select count() from cards where did in %s and queue in ({QUEUE_TYPE_REV},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and due = ?""" % self._limit(), self.col.sched.today + 1, @@ -306,7 +306,7 @@ select (due-:today)/:chunk as day, sum(case when ivl < 21 then 1 else 0 end), -- yng sum(case when ivl >= 21 then 1 else 0 end) -- mtr from cards -where did in %s and queue in ({QUEUE_TYPE_REV},3) +where did in %s and queue in ({QUEUE_TYPE_REV},{QUEUE_TYPE_DAY_LEARN_RELEARN}) %s group by day order by day""" % (self._limit(), lim), @@ -944,7 +944,7 @@ from cards where did in %s and queue = {QUEUE_TYPE_REV}""" f""" select sum(case when queue={QUEUE_TYPE_REV} and ivl >= 21 then 1 else 0 end), -- mtr -sum(case when queue in ({QUEUE_TYPE_LRN},3) or (queue={QUEUE_TYPE_REV} and ivl < 21) then 1 else 0 end), -- yng/lrn +sum(case when queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) or (queue={QUEUE_TYPE_REV} and ivl < 21) then 1 else 0 end), -- yng/lrn sum(case when queue={QUEUE_TYPE_NEW} then 1 else 0 end), -- new sum(case when queue<{QUEUE_TYPE_NEW} then 1 else 0 end) -- susp from cards where did in %s""" diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index 392e3ad1d..5613badf2 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -247,7 +247,7 @@ def test_learn_day(): # answering it will place it in queue 3 d.sched.answerCard(c, 2) assert c.due == d.sched.today + 1 - assert c.queue == 3 + assert c.queue == CARD_TYPE_RELEARNING assert not d.sched.getCard() # for testing, move it back a day c.due -= 1 @@ -281,7 +281,7 @@ def test_learn_day(): d.sched._cardConf(c)["lapse"]["delays"] = [1440] c = d.sched.getCard() d.sched.answerCard(c, 1) - assert c.queue == 3 + assert c.queue == CARD_TYPE_RELEARNING assert d.sched.counts() == (0, 0, 0) diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index 0503b0a98..cbee96c2a 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -212,7 +212,7 @@ def test_relearn(): c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.queue == QUEUE_TYPE_LRN - assert c.type == 3 + assert c.type == CARD_TYPE_RELEARNING assert c.ivl == 1 # immediately graduate it @@ -293,7 +293,7 @@ def test_learn_day(): # answering it will place it in queue 3 d.sched.answerCard(c, 3) assert c.due == d.sched.today + 1 - assert c.queue == 3 + assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN assert not d.sched.getCard() # for testing, move it back a day c.due -= 1 @@ -327,7 +327,7 @@ def test_learn_day(): d.sched._cardConf(c)["lapse"]["delays"] = [1440] c = d.sched.getCard() d.sched.answerCard(c, 1) - assert c.queue == 3 + assert c.queue == QUEUE_TYPE_DAY_LEARN_RELEARN assert d.sched.counts() == (0, 0, 0) @@ -683,12 +683,12 @@ def test_suspend(): assert c.due >= time.time() due = c.due assert c.queue == QUEUE_TYPE_LRN - assert c.type == 3 + assert c.type == CARD_TYPE_RELEARNING d.sched.suspendCards([c.id]) d.sched.unsuspendCards([c.id]) c.load() assert c.queue == QUEUE_TYPE_LRN - assert c.type == 3 + assert c.type == CARD_TYPE_RELEARNING assert c.due == due # should cope with cards in cram decks c.due = 1 diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 5ebd10bcf..d2e1bc951 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -337,7 +337,7 @@ class DataModel(QAbstractTableModel): date = c.due elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW: return str(c.due) - elif c.queue in (QUEUE_TYPE_REV, 3) or (c.type == CARD_TYPE_REV and c.queue < 0): + elif c.queue in (QUEUE_TYPE_REV, QUEUE_TYPE_DAY_LEARN_RELEARN) or (c.type == CARD_TYPE_REV and c.queue < 0): date = time.time() + ((c.due - self.col.sched.today) * 86400) else: return ""