diff --git a/pylib/anki/cards.py b/pylib/anki/cards.py index 19845566a..145d2b275 100644 --- a/pylib/anki/cards.py +++ b/pylib/anki/cards.py @@ -88,7 +88,7 @@ class Card: self.mod = intTime() self.usn = self.col.usn() # bug check - if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): + if self.queue == QUEUE_TYPE_REV and self.odue and not self.col.decks.isDyn(self.did): hooks.card_odue_was_invalid() assert self.due < 4294967296 self.col.db.execute( @@ -120,7 +120,7 @@ insert or replace into cards values self.mod = intTime() self.usn = self.col.usn() # bug checks - if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): + if self.queue == QUEUE_TYPE_REV and self.odue and not self.col.decks.isDyn(self.did): hooks.card_odue_was_invalid() assert self.due < 4294967296 self.col.db.execute( diff --git a/pylib/anki/consts.py b/pylib/anki/consts.py index c512f091d..f49bcbf99 100644 --- a/pylib/anki/consts.py +++ b/pylib/anki/consts.py @@ -20,10 +20,12 @@ QUEUE_TYPE_SIBLING_BURIED = -2 QUEUE_TYPE_SUSPENDED = -1 QUEUE_TYPE_NEW = 0 QUEUE_TYPE_LRN = 1 +QUEUE_TYPE_REV = 2 # Card types CARD_TYPE_NEW = 0 CARD_TYPE_LRN = 1 +CARD_TYPE_REV = 2 # removal types REM_CARD = 0 diff --git a/pylib/anki/find.py b/pylib/anki/find.py index 4fbb209b2..026307c70 100644 --- a/pylib/anki/find.py +++ b/pylib/anki/find.py @@ -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 (2,3) and c.due <= %d) or +(c.queue in ({QUEUE_TYPE_REV},3) 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("(c.queue in (2,3))") + q.append(f"(c.queue in ({QUEUE_TYPE_REV},3))") elif prop == "ease": prop = "factor" val = int(val * 1000) diff --git a/pylib/anki/importing/anki2.py b/pylib/anki/importing/anki2.py index 35a56309e..e7f952614 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 (2, 3) or card[6] == 2: + if card[7] in (QUEUE_TYPE_REV, 3) 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 26e065635..f30dedbe6 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -78,7 +78,7 @@ class Scheduler: # init reps to graduation card.left = self._startingLeft(card) # dynamic? - if card.odid and card.type == 2: + if card.odid and card.type == CARD_TYPE_REV: if self._resched(card): # reviews get their ivl boosted on first sight card.ivl = self._dynIvlBoost(card) @@ -88,7 +88,7 @@ class Scheduler: self._answerLrnCard(card, ease) if not wasNewQ: self._updateStats(card, "lrn") - elif card.queue == 2: + elif card.queue == QUEUE_TYPE_REV: self._answerRevCard(card, ease) self._updateStats(card, "rev") else: @@ -112,9 +112,9 @@ class Scheduler: "Return counts over next DAYS. Includes today." daysd = dict( self.col.db.all( - """ + f""" select due, count() from cards -where did in %s and queue = 2 +where did in %s and queue = {QUEUE_TYPE_REV} and due between ? and ? group by due order by due""" @@ -139,13 +139,13 @@ order by due""" def answerButtons(self, card): if card.odue: # normal review in dyn deck? - if card.odid and card.queue == 2: + if card.odid and card.queue == QUEUE_TYPE_REV: return 4 conf = self._lrnConf(card) if card.type in (CARD_TYPE_NEW, CARD_TYPE_LRN) or len(conf["delays"]) > 1: return 3 return 2 - elif card.queue == 2: + elif card.queue == QUEUE_TYPE_REV: return 4 else: return 3 @@ -557,7 +557,7 @@ did = ? and queue = 3 and due <= ? limit ?""", conf = self._lrnConf(card) if card.odid and not card.wasNew: type = REVLOG_CRAM - elif card.type == 2: + elif card.type == CARD_TYPE_REV: type = REVLOG_RELRN else: type = REVLOG_LRN @@ -627,13 +627,13 @@ did = ? and queue = 3 and due <= ? limit ?""", return delay * 60 def _lrnConf(self, card): - if card.type == 2: + if card.type == CARD_TYPE_REV: return self._lapseConf(card) else: return self._newConf(card) def _rescheduleAsRev(self, card, conf, early): - lapse = card.type == 2 + lapse = card.type == CARD_TYPE_REV if lapse: if self._resched(card): card.due = max(self.today + 1, card.odue) @@ -642,8 +642,8 @@ did = ? and queue = 3 and due <= ? limit ?""", card.odue = 0 else: self._rescheduleNew(card, conf, early) - card.queue = 2 - card.type = 2 + card.queue = QUEUE_TYPE_REV + card.type = CARD_TYPE_REV # if we were dynamic, graduating means moving back to the old deck resched = self._resched(card) if card.odid: @@ -656,7 +656,7 @@ did = ? and queue = 3 and due <= ? limit ?""", card.due = self.col.nextID("pos") def _startingLeft(self, card): - if card.type == 2: + if card.type == CARD_TYPE_REV: conf = self._lapseConf(card) else: conf = self._lrnConf(card) @@ -678,7 +678,7 @@ did = ? and queue = 3 and due <= ? limit ?""", return ok + 1 def _graduatingIvl(self, card, conf, early, adj=True): - if card.type == 2: + if card.type == CARD_TYPE_REV: # lapsed card being relearnt if card.odid: if conf["resched"]: @@ -738,8 +738,8 @@ did = ? and queue = 3 and due <= ? limit ?""", self.col.db.execute( f""" update cards set -due = odue, queue = 2, mod = %d, usn = %d, odue = 0 -where queue in ({QUEUE_TYPE_LRN},3) and type = 2 +due = odue, queue = {QUEUE_TYPE_REV}, mod = %d, usn = %d, odue = 0 +where queue in ({QUEUE_TYPE_LRN},3) and type = {CARD_TYPE_REV} %s """ % (intTime(), self.col.usn(), extra) @@ -786,9 +786,9 @@ and due <= ? limit ?)""", def _revForDeck(self, did, lim): lim = min(lim, self.reportLimit) return self.col.db.scalar( - """ + f""" select count() from -(select 1 from cards where did = ? and queue = 2 +(select 1 from cards where did = ? and queue = {QUEUE_TYPE_REV} and due <= ? limit ?)""", did, self.today, @@ -798,9 +798,9 @@ and due <= ? limit ?)""", def _resetRevCount(self): def cntFn(did, lim): return self.col.db.scalar( - """ + f""" select count() from (select id from cards where -did = ? and queue = 2 and due <= ? limit %d)""" +did = ? and queue = {QUEUE_TYPE_REV} and due <= ? limit %d)""" % lim, did, self.today, @@ -824,9 +824,9 @@ did = ? and queue = 2 and due <= ? limit %d)""" if lim: # fill the queue with the current did self._revQueue = self.col.db.list( - """ + f""" select id from cards where -did = ? and queue = 2 and due <= ? limit ?""", +did = ? and queue = {QUEUE_TYPE_REV} and due <= ? limit ?""", did, self.today, lim, @@ -861,9 +861,9 @@ did = ? and queue = 2 and due <= ? limit ?""", def totalRevForCurrentDeck(self): return self.col.db.scalar( - """ + f""" select count() from cards where id in ( -select id from cards where did in %s and queue = 2 and due <= ? limit ?)""" +select id from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? limit ?)""" % ids2str(self.col.decks.active()), self.today, self.reportLimit, @@ -1088,7 +1088,7 @@ due = odue, odue = 0, odid = 0, usn = ? where %s""" t = "c.due" elif o == DYN_DUEPRIORITY: t = ( - "(case when queue=2 and due <= %d then (ivl / cast(%d-due+0.001 as real)) else 100000+due end)" + f"(case when queue={QUEUE_TYPE_REV} and due <= %d then (ivl / cast(%d-due+0.001 as real)) else 100000+due end)" % (self.today, self.today) ) else: @@ -1107,8 +1107,8 @@ due = odue, odue = 0, odid = 0, usn = ? where %s""" # due reviews stay in the review queue. careful: can't use # "odid or did", as sqlite converts to boolean queue = f""" -(case when type=2 and (case when odue then odue <= %d else due <= %d end) - then 2 else {QUEUE_TYPE_NEW} end)""" +(case when type={CARD_TYPE_REV} and (case when odue then odue <= %d else due <= %d end) + then {QUEUE_TYPE_REV} else {QUEUE_TYPE_NEW} end)""" queue %= (self.today, self.today) self.col.db.executemany( """ @@ -1121,7 +1121,7 @@ did = ?, queue = %s, due = ?, usn = ? where id = ?""" ) def _dynIvlBoost(self, card): - assert card.odid and card.type == 2 + assert card.odid and card.type == CARD_TYPE_REV assert card.factor elapsed = card.ivl - (card.odue - self.today) factor = ((card.factor / 1000) + 1.2) / 2 @@ -1311,7 +1311,7 @@ To study outside of the normal schedule, click the Custom Study button below.""" "True if there are any rev cards due." return self.col.db.scalar( ( - "select 1 from cards where did in %s and queue = 2 " + f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_REV} " "and due <= ? limit 1" ) % self._deckLimit(), @@ -1438,12 +1438,12 @@ update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in """ for cid, queue in self.col.db.execute( f""" select id, queue from cards where nid=? and id!=? -and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""", +and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""", card.nid, card.id, self.today, ): - if queue == 2: + if queue == QUEUE_TYPE_REV: if buryRev: toBury.append(cid) # if bury disabled, we still discard to give same-day spacing @@ -1503,8 +1503,8 @@ and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""", ) self.remFromDyn(ids) self.col.db.executemany( - """ -update cards set type=2,queue=2,ivl=:ivl,due=:due,odue=0, + f""" +update cards set type={CARD_TYPE_REV},queue={QUEUE_TYPE_REV},ivl=:ivl,due=:due,odue=0, usn=:usn,mod=:mod,factor=:fact where id=:id""", d, ) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 613e44d1c..bec433512 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -105,7 +105,7 @@ class Scheduler: if card.queue in (QUEUE_TYPE_LRN, QUEUE_TYPE_DAY_LEARN_RELEARN): self._answerLrnCard(card, ease) - elif card.queue == 2: + elif card.queue == QUEUE_TYPE_REV: self._answerRevCard(card, ease) # update daily limit self._updateStats(card, "rev") @@ -142,9 +142,9 @@ class Scheduler: "Return counts over next DAYS. Includes today." daysd = dict( self.col.db.all( - """ + f""" select due, count() from cards -where did in %s and queue = 2 +where did in %s and queue = {QUEUE_TYPE_REV} and due between ? and ? group by due order by due""" @@ -606,7 +606,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", def _answerLrnCard(self, card: Card, ease: int) -> None: conf = self._lrnConf(card) - if card.type in (2, CARD_TYPE_RELEARNING): + if card.type in (CARD_TYPE_REV, CARD_TYPE_RELEARNING): type = REVLOG_RELRN else: type = REVLOG_LRN @@ -714,13 +714,13 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", return avg def _lrnConf(self, card: Card) -> Any: - if card.type in (2, CARD_TYPE_RELEARNING): + if card.type in (CARD_TYPE_REV, CARD_TYPE_RELEARNING): return self._lapseConf(card) else: return self._newConf(card) def _rescheduleAsRev(self, card: Card, conf: Dict[str, Any], early: bool) -> None: - lapse = card.type in (2, CARD_TYPE_RELEARNING) + lapse = card.type in (CARD_TYPE_REV, CARD_TYPE_RELEARNING) if lapse: self._rescheduleGraduatingLapse(card, early) @@ -735,8 +735,8 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", if early: card.ivl += 1 card.due = self.today + card.ivl - card.queue = 2 - card.type = 2 + card.queue = QUEUE_TYPE_REV + card.type = CARD_TYPE_REV def _startingLeft(self, card: Card) -> int: if card.type == CARD_TYPE_RELEARNING: @@ -768,7 +768,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", def _graduatingIvl( self, card: Card, conf: Dict[str, Any], early: bool, fuzz: bool = True ) -> Any: - if card.type in (2, CARD_TYPE_RELEARNING): + if card.type in (CARD_TYPE_REV, CARD_TYPE_RELEARNING): bonus = early and 1 or 0 return card.ivl + bonus if not early: @@ -786,7 +786,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", card.ivl = self._graduatingIvl(card, conf, early) card.due = self.today + card.ivl card.factor = conf["initialFactor"] - card.type = card.queue = 2 + card.type = card.queue = QUEUE_TYPE_REV def _logLrn( self, @@ -883,9 +883,9 @@ and due <= ? limit ?)""", dids = [did] + self.col.decks.childDids(did, childMap) lim = min(lim, self.reportLimit) return self.col.db.scalar( - """ + f""" select count() from -(select 1 from cards where did in %s and queue = 2 +(select 1 from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? limit ?)""" % ids2str(dids), self.today, @@ -895,9 +895,9 @@ and due <= ? limit ?)""" def _resetRevCount(self) -> None: lim = self._currentRevLimit() self.revCount = self.col.db.scalar( - """ + f""" select count() from (select id from cards where -did in %s and queue = 2 and due <= ? limit ?)""" +did in %s and queue = {QUEUE_TYPE_REV} and due <= ? limit ?)""" % self._deckLimit(), self.today, lim, @@ -916,9 +916,9 @@ did in %s and queue = 2 and due <= ? limit ?)""" lim = min(self.queueLimit, self._currentRevLimit()) if lim: self._revQueue = self.col.db.list( - """ + f""" select id from cards where -did in %s and queue = 2 and due <= ? +did in %s and queue = {QUEUE_TYPE_REV} and due <= ? order by due, random() limit ?""" % self._deckLimit(), @@ -946,9 +946,9 @@ limit ?""" def totalRevForCurrentDeck(self) -> int: return self.col.db.scalar( - """ + f""" select count() from cards where id in ( -select id from cards where did in %s and queue = 2 and due <= ? limit ?)""" +select id from cards where did in %s and queue = {QUEUE_TYPE_REV} and due <= ? limit ?)""" % self._deckLimit(), self.today, self.reportLimit, @@ -1101,7 +1101,7 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)""" # next interval for card when answered early+correctly def _earlyReviewIvl(self, card: Card, ease: int) -> int: - assert card.odid and card.type == 2 + assert card.odid and card.type == CARD_TYPE_REV assert card.factor assert ease > 1 @@ -1213,7 +1213,7 @@ due = (case when odue>0 then odue else due end), odue = 0, odid = 0, usn = ? whe t = "n.id desc" elif o == DYN_DUEPRIORITY: t = ( - "(case when queue=2 and due <= %d then (ivl / cast(%d-due+0.001 as real)) else 100000+due end)" + f"(case when queue={QUEUE_TYPE_REV} and due <= %d then (ivl / cast(%d-due+0.001 as real)) else 100000+due end)" % (self.today, self.today) ) else: # DYN_DUE or unknown @@ -1231,7 +1231,7 @@ due = (case when odue>0 then odue else due end), odue = 0, odid = 0, usn = ? whe queue = "" if not deck["resched"]: - queue = ",queue=2" + queue = f",queue={QUEUE_TYPE_REV}" query = ( """ @@ -1509,7 +1509,7 @@ To study outside of the normal schedule, click the Custom Study button below.""" "True if there are any rev cards due." return self.col.db.scalar( ( - "select 1 from cards where did in %s and queue = 2 " + f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_REV} " "and due <= ? limit 1" ) % self._deckLimit(), @@ -1700,12 +1700,12 @@ update cards set queue=?,mod=?,usn=? where id in """ for cid, queue in self.col.db.execute( f""" select id, queue from cards where nid=? and id!=? -and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""", +and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""", card.nid, card.id, self.today, ): - if queue == 2: + if queue == QUEUE_TYPE_REV: if buryRev: toBury.append(cid) # if bury disabled, we still discard to give same-day spacing @@ -1760,8 +1760,8 @@ and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""", ) self.remFromDyn(ids) self.col.db.executemany( - """ -update cards set type=2,queue=2,ivl=:ivl,due=:due,odue=0, + f""" +update cards set type={CARD_TYPE_REV},queue={QUEUE_TYPE_REV},ivl=:ivl,due=:due,odue=0, usn=:usn,mod=:mod,factor=:fact where id=:id""", d, ) @@ -1875,10 +1875,10 @@ and due >= ? and queue = {QUEUE_TYPE_NEW}""" f""" update cards set did = odid, queue = (case when type = {CARD_TYPE_LRN} then {QUEUE_TYPE_NEW} -when type = {CARD_TYPE_RELEARNING} then 2 +when type = {CARD_TYPE_RELEARNING} then {QUEUE_TYPE_REV} else type end), type = (case when type = {CARD_TYPE_LRN} then {CARD_TYPE_NEW} -when type = {CARD_TYPE_RELEARNING} then 2 +when type = {CARD_TYPE_RELEARNING} then {CARD_TYPE_REV} else type end), due = odue, odue = 0, odid = 0, usn = ? where odid != 0""", self.col.usn(), @@ -1890,8 +1890,8 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""", self.col.db.execute( f""" update cards set - due = odue, queue = 2, type = 2, mod = %d, usn = %d, odue = 0 - where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING}) + due = odue, queue = {QUEUE_TYPE_REV}, type = {CARD_TYPE_REV}, mod = %d, usn = %d, odue = 0 + where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in ({CARD_TYPE_REV}, {CARD_TYPE_RELEARNING}) """ % (intTime(), self.col.usn()) ) @@ -1899,8 +1899,8 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""", self.col.db.execute( f""" update cards set - due = %d+ivl, queue = 2, type = 2, mod = %d, usn = %d, odue = 0 - where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING}) + due = %d+ivl, queue = {QUEUE_TYPE_REV}, type = {CARD_TYPE_REV}, mod = %d, usn = %d, odue = 0 + where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in ({CARD_TYPE_REV}, {CARD_TYPE_RELEARNING}) """ % (self.today, intTime(), self.col.usn()) ) @@ -1917,7 +1917,7 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""", f""" update cards set type = (case when type = {CARD_TYPE_LRN} then {CARD_TYPE_NEW} -when type in (2, {CARD_TYPE_RELEARNING}) then 2 +when type in ({CARD_TYPE_REV}, {CARD_TYPE_RELEARNING}) then {CARD_TYPE_REV} else type end), due = (case when odue then odue else due end), odue = 0, @@ -1936,7 +1936,7 @@ where queue < {QUEUE_TYPE_NEW}""" # adding 'hard' in v2 scheduler means old ease entries need shifting # up or down def _remapLearningAnswers(self, sql: str) -> None: - self.col.db.execute(f"update revlog set %s and type in ({CARD_TYPE_NEW},2)" % sql) + self.col.db.execute(f"update revlog set %s and type in ({CARD_TYPE_NEW},{CARD_TYPE_REV})" % sql) def moveToV1(self) -> None: self._emptyAllFiltered() diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index ed8c318eb..5fad0dd30 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -35,18 +35,18 @@ class CardStats: if first: self.addLine(_("First Review"), self.date(first / 1000)) self.addLine(_("Latest Review"), self.date(last / 1000)) - if c.type in (CARD_TYPE_LRN, 2): + if c.type in (CARD_TYPE_LRN, CARD_TYPE_REV): if c.odid or c.queue < QUEUE_TYPE_NEW: next = None else: - if c.queue in (2, 3): + if c.queue in (QUEUE_TYPE_REV, 3): next = time.time() + ((c.due - self.col.sched.today) * 86400) else: next = c.due next = self.date(next) if next: self.addLine(_("Due"), next) - if c.queue == 2: + if c.queue == QUEUE_TYPE_REV: self.addLine(_("Interval"), fmt(c.ivl * 86400)) self.addLine(_("Ease"), "%d%%" % (c.factor / 10.0)) self.addLine(_("Reviews"), "%d" % c.reps) @@ -284,8 +284,8 @@ from revlog where id > ? """ self._line(i, _("Total"), ngettext("%d review", "%d reviews", tot) % tot) self._line(i, _("Average"), self._avgDay(tot, num, _("reviews"))) tomorrow = self.col.db.scalar( - """ -select count() from cards where did in %s and queue in (2,3) + f""" +select count() from cards where did in %s and queue in ({QUEUE_TYPE_REV},3) and due = ?""" % self._limit(), self.col.sched.today + 1, @@ -301,12 +301,12 @@ and due = ?""" if end is not None: lim += " and day < %d" % end return self.col.db.all( - """ + f""" 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 (2,3) +where did in %s and queue in ({QUEUE_TYPE_REV},3) %s group by day order by day""" % (self._limit(), lim), @@ -644,9 +644,9 @@ group by day order by day)""" lim = "and grp <= %d" % end if end else "" data = [ self.col.db.all( - """ + f""" select ivl / :chunk as grp, count() from cards -where did in %s and queue = 2 %s +where did in %s and queue = {QUEUE_TYPE_REV} %s group by grp order by grp""" % (self._limit(), lim), @@ -657,8 +657,8 @@ order by grp""" data + list( self.col.db.first( - """ -select count(), avg(ivl), max(ivl) from cards where did in %s and queue = 2""" + f""" +select count(), avg(ivl), max(ivl) from cards where did in %s and queue = {QUEUE_TYPE_REV}""" % self._limit() ) ), @@ -678,7 +678,7 @@ select count(), avg(ivl), max(ivl) from cards where did in %s and queue = 2""" for (type, ease, cnt) in eases: if type == CARD_TYPE_LRN: ease += 5 - elif type == 2: + elif type == CARD_TYPE_REV: ease += 10 n = types[type] d[n].append((ease, cnt)) @@ -930,12 +930,12 @@ when you answer "good" on a review.""" def _factors(self) -> Any: return self.col.db.first( - """ + f""" select min(factor) / 10.0, avg(factor) / 10.0, max(factor) / 10.0 -from cards where did in %s and queue = 2""" +from cards where did in %s and queue = {QUEUE_TYPE_REV}""" % self._limit() ) @@ -943,8 +943,8 @@ from cards where did in %s and queue = 2""" return self.col.db.first( f""" select -sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr -sum(case when queue in ({QUEUE_TYPE_LRN},3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn +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={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_find.py b/pylib/tests/test_find.py index e7dc215de..98ccc20a4 100644 --- a/pylib/tests/test_find.py +++ b/pylib/tests/test_find.py @@ -1,6 +1,7 @@ # coding: utf-8 import pytest +from anki.consts import * from anki.find import Finder from tests.shared import getEmptyCol @@ -91,13 +92,13 @@ def test_findCards(): assert len(deck.findCards('"goats are"')) == 1 # card states c = f.cards()[0] - c.queue = c.type = 2 + c.queue = c.type = CARD_TYPE_REV assert deck.findCards("is:review") == [] c.flush() assert deck.findCards("is:review") == [c.id] assert deck.findCards("is:due") == [] c.due = 0 - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.flush() assert deck.findCards("is:due") == [c.id] assert len(deck.findCards("-is:due")) == 4 diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index 7b75a710e..392e3ad1d 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -166,8 +166,8 @@ def test_learn(): assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN d.sched.answerCard(c, 2) - assert c.queue == 2 - assert c.type == 2 + assert c.queue == QUEUE_TYPE_REV + assert c.type == CARD_TYPE_REV # should be due tomorrow, with an interval of 1 assert c.due == d.sched.today + 1 assert c.ivl == 1 @@ -175,27 +175,27 @@ def test_learn(): c.type = 0 c.queue = 1 d.sched.answerCard(c, 3) - assert c.type == 2 - assert c.queue == 2 + assert c.type == CARD_TYPE_REV + assert c.queue == QUEUE_TYPE_REV assert checkRevIvl(d, c, 4) # revlog should have been updated each time assert d.db.scalar("select count() from revlog where type = 0") == 5 # now failed card handling - c.type = 2 + c.type = CARD_TYPE_REV c.queue = 1 c.odue = 123 d.sched.answerCard(c, 3) assert c.due == 123 - assert c.type == 2 - assert c.queue == 2 + assert c.type == CARD_TYPE_REV + assert c.queue == QUEUE_TYPE_REV # we should be able to remove manually, too - c.type = 2 + c.type = CARD_TYPE_REV c.queue = 1 c.odue = 321 c.flush() d.sched.removeLrn() c.load() - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV assert c.due == 321 @@ -271,7 +271,7 @@ def test_learn_day(): # the last pass should graduate it into a review card assert ni(c, 2) == 86400 d.sched.answerCard(c, 2) - assert c.queue == c.type == 2 + assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV # if the lapse step is tomorrow, failing it should handle the counts # correctly c.due = 0 @@ -294,8 +294,8 @@ def test_reviews(): d.addNote(f) # set the card up as a review card, due 8 days ago c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today - 8 c.factor = STARTING_FACTOR c.reps = 3 @@ -333,7 +333,7 @@ def test_reviews(): c = copy.copy(cardcopy) c.flush() d.sched.answerCard(c, 2) - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV # the new interval should be (100 + 8/4) * 1.2 = 122 assert checkRevIvl(d, c, 122) assert c.due == d.sched.today + c.ivl @@ -388,8 +388,8 @@ def test_button_spacing(): d.addNote(f) # 1 day ivl review card due now c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today c.reps = 1 c.ivl = 1 @@ -412,7 +412,7 @@ def test_overdue_lapse(): d.addNote(f) # simulate a review that was lapsed and is now due for its normal review c = f.cards()[0] - c.type = 2 + c.type = CARD_TYPE_REV c.queue = 1 c.due = -1 c.odue = -1 @@ -492,7 +492,7 @@ def test_nextIvl(): assert ni(c, 3) == 4 * 86400 # lapsed cards ################################################## - c.type = 2 + c.type = CARD_TYPE_REV c.ivl = 100 c.factor = STARTING_FACTOR assert ni(c, 1) == 60 @@ -500,7 +500,7 @@ def test_nextIvl(): assert ni(c, 3) == 100 * 86400 # review cards ################################################## - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.ivl = 100 c.factor = STARTING_FACTOR # failing it should put it at 60s @@ -551,20 +551,20 @@ def test_suspend(): # should cope with rev cards being relearnt c.due = 0 c.ivl = 100 - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.flush() d.reset() c = d.sched.getCard() d.sched.answerCard(c, 1) assert c.due >= time.time() assert c.queue == QUEUE_TYPE_LRN - assert c.type == 2 + assert c.type == CARD_TYPE_REV d.sched.suspendCards([c.id]) d.sched.unsuspendCards([c.id]) c.load() - assert c.queue == 2 - assert c.type == 2 + assert c.queue == QUEUE_TYPE_REV + assert c.type == CARD_TYPE_REV assert c.due == 1 # should cope with cards in cram decks c.due = 1 @@ -587,7 +587,8 @@ def test_cram(): d.addNote(f) c = f.cards()[0] c.ivl = 100 - c.type = c.queue = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV # due in 25 days, so it's been waiting 75 days c.due = d.sched.today + 25 c.mod = 1 @@ -634,7 +635,7 @@ def test_cram(): d.sched.answerCard(c, 2) assert c.ivl == 138 assert c.due == 138 - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV # and it will have moved back to the previous deck assert c.did == 1 # cram the deck again @@ -734,7 +735,8 @@ def test_cram_resched(): assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW # undue reviews should also be unaffected c.ivl = 100 - c.type = c.queue = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV c.due = d.sched.today + 25 c.factor = STARTING_FACTOR c.flush() @@ -911,8 +913,8 @@ def test_repCounts(): f["Front"] = "three" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today c.flush() d.reset() @@ -929,8 +931,8 @@ def test_timing(): f["Front"] = "num" + str(i) d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # fail the first one @@ -941,7 +943,7 @@ def test_timing(): d.sched.answerCard(c, 1) # the next card should be another review c = d.sched.getCard() - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV # but if we wait for a second, the failed card should come back orig_time = time.time @@ -982,7 +984,7 @@ def test_deckDue(): d.addNote(f) # make it a review card c = f.cards()[0] - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # add one more with a new deck @@ -1100,8 +1102,8 @@ def test_forget(): f["Front"] = "one" d.addNote(f) c = f.cards()[0] - c.queue = 2 - c.type = 2 + c.queue = QUEUE_TYPE_REV + c.type = CARD_TYPE_REV c.ivl = 100 c.due = 0 c.flush() @@ -1122,7 +1124,7 @@ def test_resched(): c.load() assert c.due == d.sched.today assert c.ivl == 1 - assert c.queue == c.type == 2 + assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV d.sched.reschedCards([c.id], 1, 1) c.load() assert c.due == d.sched.today + 1 @@ -1136,8 +1138,8 @@ def test_norelearn(): f["Front"] = "one" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = 0 c.factor = STARTING_FACTOR c.reps = 3 @@ -1158,8 +1160,8 @@ def test_failmult(): f["Back"] = "two" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.ivl = 100 c.due = d.sched.today - c.ivl c.factor = STARTING_FACTOR diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index db76ad460..0503b0a98 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -179,8 +179,8 @@ def test_learn(): assert c.queue == QUEUE_TYPE_LRN assert c.type == CARD_TYPE_LRN d.sched.answerCard(c, 3) - assert c.queue == 2 - assert c.type == 2 + assert c.queue == QUEUE_TYPE_REV + assert c.type == CARD_TYPE_REV # should be due tomorrow, with an interval of 1 assert c.due == d.sched.today + 1 assert c.ivl == 1 @@ -188,8 +188,8 @@ def test_learn(): c.type = 0 c.queue = 1 d.sched.answerCard(c, 4) - assert c.type == 2 - assert c.queue == 2 + assert c.type == CARD_TYPE_REV + assert c.queue == QUEUE_TYPE_REV assert checkRevIvl(d, c, 4) # revlog should have been updated each time assert d.db.scalar("select count() from revlog where type = 0") == 5 @@ -203,7 +203,8 @@ def test_relearn(): c = f.cards()[0] c.ivl = 100 c.due = d.sched.today - c.type = c.queue = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV c.flush() # fail the card @@ -216,7 +217,7 @@ def test_relearn(): # immediately graduate it d.sched.answerCard(c, 4) - assert c.queue == c.type == 2 + assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV assert c.ivl == 2 assert c.due == d.sched.today + c.ivl @@ -229,7 +230,8 @@ def test_relearn_no_steps(): c = f.cards()[0] c.ivl = 100 c.due = d.sched.today - c.type = c.queue = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV c.flush() conf = d.decks.confForDid(1) @@ -240,7 +242,7 @@ def test_relearn_no_steps(): d.reset() c = d.sched.getCard() d.sched.answerCard(c, 1) - assert c.type == c.queue == 2 + assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV def test_learn_collapsed(): @@ -315,7 +317,7 @@ def test_learn_day(): # the last pass should graduate it into a review card assert ni(c, 3) == 86400 d.sched.answerCard(c, 3) - assert c.queue == c.type == 2 + assert c.queue == CARD_TYPE_REV and c.type == QUEUE_TYPE_REV # if the lapse step is tomorrow, failing it should handle the counts # correctly c.due = 0 @@ -338,8 +340,8 @@ def test_reviews(): d.addNote(f) # set the card up as a review card, due 8 days ago c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today - 8 c.factor = STARTING_FACTOR c.reps = 3 @@ -355,7 +357,7 @@ def test_reviews(): c.flush() d.reset() d.sched.answerCard(c, 2) - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV # the new interval should be (100) * 1.2 = 120 assert checkRevIvl(d, c, 120) assert c.due == d.sched.today + c.ivl @@ -432,7 +434,8 @@ def test_review_limits(): # make them reviews c = f.cards()[0] - c.queue = c.type = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV c.due = 0 c.flush() @@ -474,8 +477,8 @@ def test_button_spacing(): d.addNote(f) # 1 day ivl review card due now c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today c.reps = 1 c.ivl = 1 @@ -503,7 +506,7 @@ def test_overdue_lapse(): d.addNote(f) # simulate a review that was lapsed and is now due for its normal review c = f.cards()[0] - c.type = 2 + c.type = CARD_TYPE_REV c.queue = 1 c.due = -1 c.odue = -1 @@ -586,7 +589,7 @@ def test_nextIvl(): assert ni(c, 4) == 4 * 86400 # lapsed cards ################################################## - c.type = 2 + c.type = CARD_TYPE_REV c.ivl = 100 c.factor = STARTING_FACTOR assert ni(c, 1) == 60 @@ -594,7 +597,7 @@ def test_nextIvl(): assert ni(c, 4) == 101 * 86400 # review cards ################################################## - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.ivl = 100 c.factor = STARTING_FACTOR # failing it should put it at 60s @@ -671,8 +674,8 @@ def test_suspend(): # should cope with rev cards being relearnt c.due = 0 c.ivl = 100 - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.flush() d.reset() c = d.sched.getCard() @@ -709,7 +712,8 @@ def test_filt_reviewing_early_normal(): d.addNote(f) c = f.cards()[0] c.ivl = 100 - c.type = c.queue = 2 + c.queue = CARD_TYPE_REV + c.type = QUEUE_TYPE_REV # due in 25 days, so it's been waiting 75 days c.due = d.sched.today + 25 c.mod = 1 @@ -740,7 +744,7 @@ def test_filt_reviewing_early_normal(): assert c.due == d.sched.today + c.ivl assert not c.odue # should not be in learning - assert c.queue == 2 + assert c.queue == QUEUE_TYPE_REV # should be logged as a cram rep assert d.db.scalar("select type from revlog order by id desc limit 1") == 3 @@ -943,8 +947,8 @@ def test_repCounts(): f["Front"] = "three" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = d.sched.today c.flush() d.reset() @@ -961,8 +965,8 @@ def test_timing(): f["Front"] = "num" + str(i) d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # fail the first one @@ -971,7 +975,7 @@ def test_timing(): d.sched.answerCard(c, 1) # the next card should be another review c2 = d.sched.getCard() - assert c2.queue == 2 + assert c2.queue == QUEUE_TYPE_REV # if the failed card becomes due, it should show first c.due = time.time() - 1 c.flush() @@ -1008,7 +1012,7 @@ def test_deckDue(): d.addNote(f) # make it a review card c = f.cards()[0] - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.due = 0 c.flush() # add one more with a new deck @@ -1126,8 +1130,8 @@ def test_forget(): f["Front"] = "one" d.addNote(f) c = f.cards()[0] - c.queue = 2 - c.type = 2 + c.queue = QUEUE_TYPE_REV + c.type = CARD_TYPE_REV c.ivl = 100 c.due = 0 c.flush() @@ -1148,7 +1152,7 @@ def test_resched(): c.load() assert c.due == d.sched.today assert c.ivl == 1 - assert c.queue == c.type == 2 + assert c.queue == QUEUE_TYPE_REV and c.type == CARD_TYPE_REV d.sched.reschedCards([c.id], 1, 1) c.load() assert c.due == d.sched.today + 1 @@ -1162,8 +1166,8 @@ def test_norelearn(): f["Front"] = "one" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.due = 0 c.factor = STARTING_FACTOR c.reps = 3 @@ -1184,8 +1188,8 @@ def test_failmult(): f["Back"] = "two" d.addNote(f) c = f.cards()[0] - c.type = 2 - c.queue = 2 + c.type = CARD_TYPE_REV + c.queue = QUEUE_TYPE_REV c.ivl = 100 c.due = d.sched.today - c.ivl c.factor = STARTING_FACTOR @@ -1269,7 +1273,7 @@ def test_negativeDueFilter(): d.addNote(f) c = f.cards()[0] c.due = -5 - c.queue = 2 + c.queue = QUEUE_TYPE_REV c.ivl = 5 c.flush() diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 57af170eb..5ebd10bcf 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 (2, 3) or (c.type == 2 and c.queue < 0): + elif c.queue in (QUEUE_TYPE_REV, 3) or (c.type == CARD_TYPE_REV and c.queue < 0): date = time.time() + ((c.due - self.col.sched.today) * 86400) else: return ""