mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
Add named constant for relearning cards
This commit is contained in:
parent
729330324e
commit
ce4fa1a5fb
1 changed files with 20 additions and 19 deletions
|
@ -20,6 +20,7 @@ from anki.lang import _
|
||||||
from anki.utils import fmtTimeSpan, ids2str, intTime
|
from anki.utils import fmtTimeSpan, ids2str, intTime
|
||||||
|
|
||||||
# card types: 0=new, 1=lrn, 2=rev, 3=relrn
|
# 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,
|
# queue types: 0=new, 1=(re)lrn, 2=rev, 3=day (re)lrn,
|
||||||
# 4=preview, -1=suspended, -2=sibling buried, -3=manually buried
|
# 4=preview, -1=suspended, -2=sibling buried, -3=manually buried
|
||||||
# revlog types: 0=lrn, 1=rev, 2=relrn, 3=early review
|
# revlog types: 0=lrn, 1=rev, 2=relrn, 3=early review
|
||||||
|
@ -599,7 +600,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
||||||
|
|
||||||
def _answerLrnCard(self, card: Card, ease: int) -> None:
|
def _answerLrnCard(self, card: Card, ease: int) -> None:
|
||||||
conf = self._lrnConf(card)
|
conf = self._lrnConf(card)
|
||||||
if card.type in (2, 3):
|
if card.type in (2, CARD_TYPE_RELEARNING):
|
||||||
type = 2
|
type = 2
|
||||||
else:
|
else:
|
||||||
type = 0
|
type = 0
|
||||||
|
@ -636,7 +637,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
||||||
card.left = self._startingLeft(card)
|
card.left = self._startingLeft(card)
|
||||||
|
|
||||||
# relearning card?
|
# relearning card?
|
||||||
if card.type == 3:
|
if card.type == CARD_TYPE_RELEARNING:
|
||||||
self._updateRevIvlOnFail(card, conf)
|
self._updateRevIvlOnFail(card, conf)
|
||||||
|
|
||||||
return self._rescheduleLrnCard(card, conf)
|
return self._rescheduleLrnCard(card, conf)
|
||||||
|
@ -707,13 +708,13 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
||||||
return avg
|
return avg
|
||||||
|
|
||||||
def _lrnConf(self, card: Card) -> Any:
|
def _lrnConf(self, card: Card) -> Any:
|
||||||
if card.type in (2, 3):
|
if card.type in (2, CARD_TYPE_RELEARNING):
|
||||||
return self._lapseConf(card)
|
return self._lapseConf(card)
|
||||||
else:
|
else:
|
||||||
return self._newConf(card)
|
return self._newConf(card)
|
||||||
|
|
||||||
def _rescheduleAsRev(self, card: Card, conf: Dict[str, Any], early: bool) -> None:
|
def _rescheduleAsRev(self, card: Card, conf: Dict[str, Any], early: bool) -> None:
|
||||||
lapse = card.type in (2, 3)
|
lapse = card.type in (2, CARD_TYPE_RELEARNING)
|
||||||
|
|
||||||
if lapse:
|
if lapse:
|
||||||
self._rescheduleGraduatingLapse(card, early)
|
self._rescheduleGraduatingLapse(card, early)
|
||||||
|
@ -732,7 +733,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
||||||
card.type = 2
|
card.type = 2
|
||||||
|
|
||||||
def _startingLeft(self, card: Card) -> int:
|
def _startingLeft(self, card: Card) -> int:
|
||||||
if card.type == 3:
|
if card.type == CARD_TYPE_RELEARNING:
|
||||||
conf = self._lapseConf(card)
|
conf = self._lapseConf(card)
|
||||||
else:
|
else:
|
||||||
conf = self._lrnConf(card)
|
conf = self._lrnConf(card)
|
||||||
|
@ -761,7 +762,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
||||||
def _graduatingIvl(
|
def _graduatingIvl(
|
||||||
self, card: Card, conf: Dict[str, Any], early: bool, fuzz: bool = True
|
self, card: Card, conf: Dict[str, Any], early: bool, fuzz: bool = True
|
||||||
) -> Any:
|
) -> Any:
|
||||||
if card.type in (2, 3):
|
if card.type in (2, CARD_TYPE_RELEARNING):
|
||||||
bonus = early and 1 or 0
|
bonus = early and 1 or 0
|
||||||
return card.ivl + bonus
|
return card.ivl + bonus
|
||||||
if not early:
|
if not early:
|
||||||
|
@ -965,7 +966,7 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
|
||||||
suspended = self._checkLeech(card, conf) and card.queue == -1
|
suspended = self._checkLeech(card, conf) and card.queue == -1
|
||||||
|
|
||||||
if conf["delays"] and not suspended:
|
if conf["delays"] and not suspended:
|
||||||
card.type = 3
|
card.type = CARD_TYPE_RELEARNING
|
||||||
delay = self._moveToFirstStep(card, conf)
|
delay = self._moveToFirstStep(card, conf)
|
||||||
else:
|
else:
|
||||||
# no relearning steps
|
# no relearning steps
|
||||||
|
@ -1236,7 +1237,7 @@ where id = ?
|
||||||
|
|
||||||
# learning and relearning cards may be seconds-based or day-based;
|
# learning and relearning cards may be seconds-based or day-based;
|
||||||
# other types map directly to queues
|
# other types map directly to queues
|
||||||
if card.type in (1, 3):
|
if card.type in (1, CARD_TYPE_RELEARNING):
|
||||||
if card.odue > 1000000000:
|
if card.odue > 1000000000:
|
||||||
card.queue = 1
|
card.queue = 1
|
||||||
else:
|
else:
|
||||||
|
@ -1558,8 +1559,8 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
||||||
|
|
||||||
# learning and relearning cards may be seconds-based or day-based;
|
# learning and relearning cards may be seconds-based or day-based;
|
||||||
# other types map directly to queues
|
# other types map directly to queues
|
||||||
_restoreQueueSnippet = """
|
_restoreQueueSnippet = f"""
|
||||||
queue = (case when type in (1,3) then
|
queue = (case when type in (1,{CARD_TYPE_RELEARNING}) then
|
||||||
(case when (case when odue then odue else due end) > 1000000000 then 1 else 3 end)
|
(case when (case when odue then odue else due end) > 1000000000 then 1 else 3 end)
|
||||||
else
|
else
|
||||||
type
|
type
|
||||||
|
@ -1819,13 +1820,13 @@ and due >= ? and queue = 0"""
|
||||||
|
|
||||||
def _emptyAllFiltered(self) -> None:
|
def _emptyAllFiltered(self) -> None:
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set did = odid, queue = (case
|
update cards set did = odid, queue = (case
|
||||||
when type = 1 then 0
|
when type = 1 then 0
|
||||||
when type = 3 then 2
|
when type = {CARD_TYPE_RELEARNING} then 2
|
||||||
else type end), type = (case
|
else type end), type = (case
|
||||||
when type = 1 then 0
|
when type = 1 then 0
|
||||||
when type = 3 then 2
|
when type = {CARD_TYPE_RELEARNING} then 2
|
||||||
else type end),
|
else type end),
|
||||||
due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
|
due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
|
@ -1835,19 +1836,19 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
|
||||||
# remove review cards from relearning
|
# remove review cards from relearning
|
||||||
if schedVer == 1:
|
if schedVer == 1:
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set
|
update cards set
|
||||||
due = odue, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
|
due = odue, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
|
||||||
where queue in (1,3) and type in (2, 3)
|
where queue in (1,3) and type in (2, {CARD_TYPE_RELEARNING})
|
||||||
"""
|
"""
|
||||||
% (intTime(), self.col.usn())
|
% (intTime(), self.col.usn())
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set
|
update cards set
|
||||||
due = %d+ivl, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
|
due = %d+ivl, queue = 2, type = 2, mod = %d, usn = %d, odue = 0
|
||||||
where queue in (1,3) and type in (2, 3)
|
where queue in (1,3) and type in (2, {CARD_TYPE_RELEARNING})
|
||||||
"""
|
"""
|
||||||
% (self.today, intTime(), self.col.usn())
|
% (self.today, intTime(), self.col.usn())
|
||||||
)
|
)
|
||||||
|
@ -1857,10 +1858,10 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
|
||||||
# v1 doesn't support buried/suspended (re)learning cards
|
# v1 doesn't support buried/suspended (re)learning cards
|
||||||
def _resetSuspendedLearning(self) -> None:
|
def _resetSuspendedLearning(self) -> None:
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set type = (case
|
update cards set type = (case
|
||||||
when type = 1 then 0
|
when type = 1 then 0
|
||||||
when type in (2, 3) then 2
|
when type in (2, {CARD_TYPE_RELEARNING}) then 2
|
||||||
else type end),
|
else type end),
|
||||||
due = (case when odue then odue else due end),
|
due = (case when odue then odue else due end),
|
||||||
odue = 0,
|
odue = 0,
|
||||||
|
|
Loading…
Reference in a new issue