CARD_TYPE_LRN and QUEUE_TYPE_LRN

This commit is contained in:
Arthur Milchior 2020-02-02 01:28:04 -08:00
parent a1cc0787d2
commit 69436643fe
10 changed files with 73 additions and 71 deletions

View File

@ -16,9 +16,11 @@ NEW_CARDS_DUE = 1
# Queue types
QUEUE_TYPE_NEW = 0
QUEUE_TYPE_LRN = 1
# Card types
CARD_TYPE_NEW = 0
CARD_TYPE_LRN = 1
# removal types
REM_CARD = 0

View File

@ -273,16 +273,16 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """
elif val == "new":
n = CARD_TYPE_NEW
else:
return "queue in (1, 3)"
return f"queue in ({QUEUE_TYPE_LRN}, 3)"
return "type = %d" % n
elif val == "suspended":
return "c.queue = -1"
elif val == "buried":
return "c.queue in (-2, -3)"
elif val == "due":
return """
return f"""
(c.queue in (2,3) and c.due <= %d) or
(c.queue = 1 and c.due <= %d)""" % (
(c.queue = {QUEUE_TYPE_LRN} and c.due <= %d)""" % (
self.col.sched.today,
self.col.sched.dayCutoff,
)

View File

@ -357,12 +357,12 @@ class Anki2Importer(Importer):
card[8] = card[14]
card[14] = 0
# queue
if card[6] == 1: # type
if card[6] == CARD_TYPE_LRN: # type
card[7] = QUEUE_TYPE_NEW
else:
card[7] = card[6]
# type
if card[6] == 1:
if card[6] == CARD_TYPE_LRN:
card[6] = CARD_TYPE_NEW
cards.append(card)
# we need to import revlog, rewriting card ids and bumping usn

View File

@ -71,10 +71,10 @@ class Scheduler:
wasNewQ = card.queue == QUEUE_TYPE_NEW
if wasNewQ:
# came from the new queue, move to learning
card.queue = 1
card.queue = QUEUE_TYPE_LRN
# if it was a new card, it's now a learning card
if card.type == CARD_TYPE_NEW:
card.type = 1
card.type = CARD_TYPE_LRN
# init reps to graduation
card.left = self._startingLeft(card)
# dynamic?
@ -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 (1, 3):
if card.queue in (QUEUE_TYPE_LRN, 3):
self._answerLrnCard(card, ease)
if not wasNewQ:
self._updateStats(card, "lrn")
@ -142,7 +142,7 @@ order by due"""
if card.odid and card.queue == 2:
return 4
conf = self._lrnConf(card)
if card.type in (CARD_TYPE_NEW, 1) or len(conf["delays"]) > 1:
if card.type in (CARD_TYPE_NEW, CARD_TYPE_LRN) or len(conf["delays"]) > 1:
return 3
return 2
elif card.queue == 2:
@ -466,9 +466,9 @@ select id from cards where did in %s and queue = {QUEUE_TYPE_NEW} limit ?)"""
# sub-day
self.lrnCount = (
self.col.db.scalar(
"""
f"""
select sum(left/1000) from (select left from cards where
did in %s and queue = 1 and due < ? limit %d)"""
did in %s and queue = {QUEUE_TYPE_LRN} and due < ? limit %d)"""
% (self._deckLimit(), self.reportLimit),
self.dayCutoff,
)
@ -496,9 +496,9 @@ and due <= ? limit %d"""
if self._lrnQueue:
return True
self._lrnQueue = self.col.db.all(
"""
f"""
select due, id from cards where
did in %s and queue = 1 and due < :lim
did in %s and queue = {QUEUE_TYPE_LRN} and due < :lim
limit %d"""
% (self._deckLimit(), self.reportLimit),
lim=self.dayCutoff,
@ -601,7 +601,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
# if the queue is not empty and there's nothing else to do, make
# sure we don't put it at the head of the queue and end up showing
# it twice in a row
card.queue = 1
card.queue = QUEUE_TYPE_LRN
if self._lrnQueue and not self.revCount and not self.newCount:
smallestDue = self._lrnQueue[0][0]
card.due = max(card.due, smallestDue + 1)
@ -736,25 +736,25 @@ did = ? and queue = 3 and due <= ? limit ?""",
extra = " and did in " + ids2str(self.col.decks.allIds())
# review cards in relearning
self.col.db.execute(
"""
f"""
update cards set
due = odue, queue = 2, mod = %d, usn = %d, odue = 0
where queue in (1,3) and type = 2
where queue in ({QUEUE_TYPE_LRN},3) and type = 2
%s
"""
% (intTime(), self.col.usn(), extra)
)
# new cards in learning
self.forgetCards(
self.col.db.list("select id from cards where queue in (1,3) %s" % extra)
self.col.db.list(f"select id from cards where queue in ({QUEUE_TYPE_LRN},3) %s" % extra)
)
def _lrnForDeck(self, did):
cnt = (
self.col.db.scalar(
"""
f"""
select sum(left/1000) from
(select left from cards where did = ? and queue = 1 and due < ? limit ?)""",
(select left from cards where did = ? and queue = {QUEUE_TYPE_LRN} and due < ? limit ?)""",
did,
intTime() + self.col.conf["collapseTime"],
self.reportLimit,
@ -907,7 +907,7 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
# queue 1
if card.due < self.dayCutoff:
self.lrnCount += card.left // 1000
card.queue = 1
card.queue = QUEUE_TYPE_LRN
heappush(self._lrnQueue, (card.due, card.id))
else:
# day learn queue
@ -1059,8 +1059,8 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
# move out of cram queue
self.col.db.execute(
f"""
update cards set did = odid, queue = (case when type = 1 then {QUEUE_TYPE_NEW}
else type end), type = (case when type = 1 then {CARD_TYPE_NEW} else type end),
update cards set did = odid, queue = (case when type = {CARD_TYPE_LRN} then {QUEUE_TYPE_NEW}
else type end), type = (case when type = {CARD_TYPE_LRN} then {CARD_TYPE_NEW} else type end),
due = odue, odue = 0, odid = 0, usn = ? where %s"""
% lim,
self.col.usn(),
@ -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, 1, 3):
if card.queue in (QUEUE_TYPE_NEW, QUEUE_TYPE_LRN, 3):
return self._nextLrnIvl(card, ease)
elif ease == BUTTON_ONE:
# lapsed

View File

@ -97,14 +97,14 @@ class Scheduler:
if card.queue == QUEUE_TYPE_NEW:
# came from the new queue, move to learning
card.queue = 1
card.type = 1
card.queue = QUEUE_TYPE_LRN
card.type = CARD_TYPE_LRN
# init reps to graduation
card.left = self._startingLeft(card)
# update daily limit
self._updateStats(card, "new")
if card.queue in (1, QUEUE_TYPE_DAY_LEARN_RELEARN):
if card.queue in (QUEUE_TYPE_LRN, QUEUE_TYPE_DAY_LEARN_RELEARN):
self._answerLrnCard(card, ease)
elif card.queue == 2:
self._answerRevCard(card, ease)
@ -505,8 +505,8 @@ select id from cards where did in %s and queue = {QUEUE_TYPE_NEW} limit ?)"""
# sub-day
self.lrnCount = (
self.col.db.scalar(
"""
select count() from cards where did in %s and queue = 1
f"""
select count() from cards where did in %s and queue = {QUEUE_TYPE_LRN}
and due < ?"""
% (self._deckLimit()),
self._lrnCutoff,
@ -546,7 +546,7 @@ select count() from cards where did in %s and queue = {QUEUE_TYPE_PREVIEW}
self._lrnQueue = self.col.db.all(
f"""
select due, id from cards where
did in %s and queue in (1,{QUEUE_TYPE_PREVIEW}) and due < :lim
did in %s and queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_PREVIEW}) and due < :lim
limit %d"""
% (self._deckLimit(), self.reportLimit),
lim=cutoff,
@ -674,7 +674,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""",
maxExtra = min(300, int(delay * 0.25))
fuzz = random.randrange(0, maxExtra)
card.due = min(self.dayCutoff - 1, card.due + fuzz)
card.queue = 1
card.queue = QUEUE_TYPE_LRN
if card.due < (intTime() + self.col.conf["collapseTime"]):
self.lrnCount += 1
# if the queue is not empty and there's nothing else to do, make
@ -831,9 +831,9 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""",
def _lrnForDeck(self, did: int) -> Any:
cnt = (
self.col.db.scalar(
"""
f"""
select count() from
(select null from cards where did = ? and queue = 1 and due < ? limit ?)""",
(select null from cards where did = ? and queue = {QUEUE_TYPE_LRN} and due < ? limit ?)""",
did,
intTime() + self.col.conf["collapseTime"],
self.reportLimit,
@ -1261,9 +1261,9 @@ where id = ?
# learning and relearning cards may be seconds-based or day-based;
# other types map directly to queues
if card.type in (1, CARD_TYPE_RELEARNING):
if card.type in (CARD_TYPE_LRN, CARD_TYPE_RELEARNING):
if card.odue > 1000000000:
card.queue = 1
card.queue = QUEUE_TYPE_LRN
else:
card.queue = QUEUE_TYPE_DAY_LEARN_RELEARN
else:
@ -1563,7 +1563,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
return 0
# (re)learning?
if card.queue in (QUEUE_TYPE_NEW, 1, QUEUE_TYPE_DAY_LEARN_RELEARN):
if card.queue in (QUEUE_TYPE_NEW, QUEUE_TYPE_LRN, QUEUE_TYPE_DAY_LEARN_RELEARN):
return self._nextLrnIvl(card, ease)
elif ease == BUTTON_ONE:
# lapse
@ -1605,7 +1605,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
# learning and relearning cards may be seconds-based or day-based;
# other types map directly to queues
_restoreQueueSnippet = f"""
queue = (case when type in (1,{CARD_TYPE_RELEARNING}) then
queue = (case when type in ({CARD_TYPE_LRN},{CARD_TYPE_RELEARNING}) then
(case when (case when odue then odue else due end) > 1000000000 then 1 else
{QUEUE_TYPE_DAY_LEARN_RELEARN} end)
else
@ -1875,10 +1875,10 @@ and due >= ? and queue = {QUEUE_TYPE_NEW}"""
self.col.db.execute(
f"""
update cards set did = odid, queue = (case
when type = 1 then {QUEUE_TYPE_NEW}
when type = {CARD_TYPE_LRN} then {QUEUE_TYPE_NEW}
when type = {CARD_TYPE_RELEARNING} then 2
else type end), type = (case
when type = 1 then {CARD_TYPE_NEW}
when type = {CARD_TYPE_LRN} then {CARD_TYPE_NEW}
when type = {CARD_TYPE_RELEARNING} then 2
else type end),
due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
@ -1892,7 +1892,7 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
f"""
update cards set
due = odue, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
where queue in (1,{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING})
where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING})
"""
% (intTime(), self.col.usn())
)
@ -1901,14 +1901,14 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
f"""
update cards set
due = %d+ivl, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
where queue in (1,{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING})
where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN}) and type in (2, {CARD_TYPE_RELEARNING})
"""
% (self.today, intTime(), self.col.usn())
)
# remove new cards from learning
self.forgetCards(
self.col.db.list(
f"select id from cards where queue in (1,{QUEUE_TYPE_DAY_LEARN_RELEARN})"
f"select id from cards where queue in ({QUEUE_TYPE_LRN},{QUEUE_TYPE_DAY_LEARN_RELEARN})"
)
)
@ -1917,7 +1917,7 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
self.col.db.execute(
f"""
update cards set type = (case
when type = 1 then {CARD_TYPE_NEW}
when type = {CARD_TYPE_LRN} then {CARD_TYPE_NEW}
when type in (2, {CARD_TYPE_RELEARNING}) then 2
else type end),
due = (case when odue then odue else due end),

View File

@ -35,7 +35,7 @@ class CardStats:
if first:
self.addLine(_("First Review"), self.date(first / 1000))
self.addLine(_("Latest Review"), self.date(last / 1000))
if c.type in (1, 2):
if c.type in (CARD_TYPE_LRN, 2):
if c.odid or c.queue < QUEUE_TYPE_NEW:
next = None
else:
@ -676,7 +676,7 @@ select count(), avg(ivl), max(ivl) from cards where did in %s and queue = 2"""
types = ("lrn", "yng", "mtr")
eases = self._eases()
for (type, ease, cnt) in eases:
if type == 1:
if type == CARD_TYPE_LRN:
ease += 5
elif type == 2:
ease += 10
@ -944,7 +944,7 @@ from cards where did in %s and queue = 2"""
f"""
select
sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr
sum(case when queue in (1,3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn
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_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"""

View File

@ -51,8 +51,8 @@ def test_new():
# if we answer it, it should become a learn card
t = intTime()
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.type == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == CARD_TYPE_LRN
assert c.due >= t
# disabled for now, as the learn fudging makes this randomly fail
@ -163,8 +163,8 @@ def test_learn():
assert c.left % 1000 == 1
assert c.left // 1000 == 1
# the next pass should graduate the card
assert c.queue == 1
assert c.type == 1
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
@ -259,7 +259,7 @@ def test_learn_day():
assert ni(c, 2) == 86400 * 2
# if we fail it, it should be back in the correct queue
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
d.undo()
d.reset()
c = d.sched.getCard()
@ -311,7 +311,7 @@ def test_reviews():
d.reset()
d.sched._cardConf(c)["lapse"]["delays"] = [2, 20]
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
# it should be due tomorrow, with an interval of 1
assert c.odue == d.sched.today + 1
assert c.ivl == 1
@ -558,7 +558,7 @@ def test_suspend():
c = d.sched.getCard()
d.sched.answerCard(c, 1)
assert c.due >= time.time()
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == 2
d.sched.suspendCards([c.id])
d.sched.unsuspendCards([c.id])
@ -622,7 +622,7 @@ def test_cram():
# int(75*1.85) = 138
assert c.ivl == 138
assert c.odue == 138
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
# should be logged as a cram rep
assert d.db.scalar("select type from revlog order by id desc limit 1") == 3
# check ivls again
@ -702,7 +702,7 @@ def test_cram_rem():
c = d.sched.getCard()
d.sched.answerCard(c, 2)
# answering the card will put it in the learning queue
assert c.type == c.queue == 1
assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN
assert c.due != oldDue
# if we terminate cramming prematurely it should be set back to new
d.sched.emptyDyn(did)
@ -950,7 +950,7 @@ def test_timing():
time.time = adjusted_time
c = d.sched.getCard()
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
time.time = orig_time

View File

@ -62,8 +62,8 @@ def test_new():
# if we answer it, it should become a learn card
t = intTime()
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.type == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == CARD_TYPE_LRN
assert c.due >= t
# disabled for now, as the learn fudging makes this randomly fail
@ -176,8 +176,8 @@ def test_learn():
assert c.left % 1000 == 1
assert c.left // 1000 == 1
# the next pass should graduate the card
assert c.queue == 1
assert c.type == 1
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
@ -210,7 +210,7 @@ def test_relearn():
d.reset()
c = d.sched.getCard()
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == 3
assert c.ivl == 1
@ -303,7 +303,7 @@ def test_learn_day():
assert ni(c, 3) == 86400 * 2
# if we fail it, it should be back in the correct queue
d.sched.answerCard(c, 1)
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
d.undo()
d.reset()
c = d.sched.getCard()
@ -679,12 +679,12 @@ def test_suspend():
d.sched.answerCard(c, 1)
assert c.due >= time.time()
due = c.due
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == 3
d.sched.suspendCards([c.id])
d.sched.unsuspendCards([c.id])
c.load()
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
assert c.type == 3
assert c.due == due
# should cope with cards in cram decks
@ -771,11 +771,11 @@ def test_filt_keep_lrn_state():
d.sched.answerCard(c, 1)
assert c.type == c.queue == 1
assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN
assert c.left == 3003
d.sched.answerCard(c, 3)
assert c.type == c.queue == 1
assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN
# create a dynamic deck and refresh it
did = d.decks.newDyn("Cram")
@ -784,7 +784,7 @@ def test_filt_keep_lrn_state():
# card should still be in learning state
c.load()
assert c.type == c.queue == 1
assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN
assert c.left == 2002
# should be able to advance learning steps
@ -795,7 +795,7 @@ def test_filt_keep_lrn_state():
# emptying the deck preserves learning state
d.sched.emptyDyn(did)
c.load()
assert c.type == c.queue == 1
assert c.type == CARD_TYPE_LRN and c.queue == QUEUE_TYPE_LRN
assert c.left == 1001
assert c.due - intTime() > 60 * 60
@ -977,7 +977,7 @@ def test_timing():
c.flush()
d.reset()
c = d.sched.getCard()
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
def test_collapse():

View File

@ -59,7 +59,7 @@ def test_review():
d.sched.answerCard(c, 3)
assert c.left == 1001
assert d.sched.counts() == (0, 1, 0)
assert c.queue == 1
assert c.queue == QUEUE_TYPE_LRN
# undo
assert d.undoName()
d.undo()

View File

@ -333,7 +333,7 @@ class DataModel(QAbstractTableModel):
def nextDue(self, c, index):
if c.odid:
return _("(filtered)")
elif c.queue == 1:
elif c.queue == QUEUE_TYPE_LRN:
date = c.due
elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW:
return str(c.due)
@ -1430,7 +1430,7 @@ border: 1px solid #000; padding: 3px; '>%s</div>"""
fmt = "<span style='color:%s'>%s</span>"
if type == CARD_TYPE_NEW:
tstr = fmt % (st.colLearn, tstr)
elif type == 1:
elif type == CARD_TYPE_LRN:
tstr = fmt % (st.colMature, tstr)
elif type == 2:
tstr = fmt % (st.colRelearn, tstr)