QUEUE_TYPE_NEW and CARD_TYPE_NEW
This commit is contained in:
parent
cd86fee03f
commit
a1cc0787d2
@ -48,8 +48,8 @@ class Card:
|
|||||||
self.id = timestampID(col.db, "cards")
|
self.id = timestampID(col.db, "cards")
|
||||||
self.did = 1
|
self.did = 1
|
||||||
self.crt = intTime()
|
self.crt = intTime()
|
||||||
self.type = 0
|
self.type = CARD_TYPE_NEW
|
||||||
self.queue = 0
|
self.queue = QUEUE_TYPE_NEW
|
||||||
self.ivl = 0
|
self.ivl = 0
|
||||||
self.factor = 0
|
self.factor = 0
|
||||||
self.reps = 0
|
self.reps = 0
|
||||||
|
@ -14,7 +14,11 @@ NEW_CARDS_FIRST = 2
|
|||||||
NEW_CARDS_RANDOM = 0
|
NEW_CARDS_RANDOM = 0
|
||||||
NEW_CARDS_DUE = 1
|
NEW_CARDS_DUE = 1
|
||||||
|
|
||||||
# Card and queue types
|
# Queue types
|
||||||
|
QUEUE_TYPE_NEW = 0
|
||||||
|
|
||||||
|
# Card types
|
||||||
|
CARD_TYPE_NEW = 0
|
||||||
|
|
||||||
# removal types
|
# removal types
|
||||||
REM_CARD = 0
|
REM_CARD = 0
|
||||||
|
@ -240,7 +240,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """
|
|||||||
elif type == "cardDue":
|
elif type == "cardDue":
|
||||||
sort = "c.type, c.due"
|
sort = "c.type, c.due"
|
||||||
elif type == "cardEase":
|
elif type == "cardEase":
|
||||||
sort = "c.type == 0, c.factor"
|
sort = f"c.type == {CARD_TYPE_NEW}, c.factor"
|
||||||
elif type == "cardLapses":
|
elif type == "cardLapses":
|
||||||
sort = "c.lapses"
|
sort = "c.lapses"
|
||||||
elif type == "cardIvl":
|
elif type == "cardIvl":
|
||||||
@ -271,7 +271,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """
|
|||||||
if val == "review":
|
if val == "review":
|
||||||
n = 2
|
n = 2
|
||||||
elif val == "new":
|
elif val == "new":
|
||||||
n = 0
|
n = CARD_TYPE_NEW
|
||||||
else:
|
else:
|
||||||
return "queue in (1, 3)"
|
return "queue in (1, 3)"
|
||||||
return "type = %d" % n
|
return "type = %d" % n
|
||||||
|
@ -6,6 +6,7 @@ import unicodedata
|
|||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from anki.collection import _Collection
|
from anki.collection import _Collection
|
||||||
|
from anki.consts import *
|
||||||
from anki.importing.base import Importer
|
from anki.importing.base import Importer
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.storage import Collection
|
from anki.storage import Collection
|
||||||
@ -357,12 +358,12 @@ class Anki2Importer(Importer):
|
|||||||
card[14] = 0
|
card[14] = 0
|
||||||
# queue
|
# queue
|
||||||
if card[6] == 1: # type
|
if card[6] == 1: # type
|
||||||
card[7] = 0
|
card[7] = QUEUE_TYPE_NEW
|
||||||
else:
|
else:
|
||||||
card[7] = card[6]
|
card[7] = card[6]
|
||||||
# type
|
# type
|
||||||
if card[6] == 1:
|
if card[6] == 1:
|
||||||
card[6] = 0
|
card[6] = CARD_TYPE_NEW
|
||||||
cards.append(card)
|
cards.append(card)
|
||||||
# we need to import revlog, rewriting card ids and bumping usn
|
# we need to import revlog, rewriting card ids and bumping usn
|
||||||
for rev in self.src.db.execute("select * from revlog where cid = ?", scid):
|
for rev in self.src.db.execute("select * from revlog where cid = ?", scid):
|
||||||
|
@ -67,13 +67,13 @@ class Scheduler:
|
|||||||
self._burySiblings(card)
|
self._burySiblings(card)
|
||||||
card.reps += 1
|
card.reps += 1
|
||||||
# former is for logging new cards, latter also covers filt. decks
|
# former is for logging new cards, latter also covers filt. decks
|
||||||
card.wasNew = card.type == 0
|
card.wasNew = card.type == CARD_TYPE_NEW
|
||||||
wasNewQ = card.queue == 0
|
wasNewQ = card.queue == QUEUE_TYPE_NEW
|
||||||
if wasNewQ:
|
if wasNewQ:
|
||||||
# came from the new queue, move to learning
|
# came from the new queue, move to learning
|
||||||
card.queue = 1
|
card.queue = 1
|
||||||
# if it was a new card, it's now a learning card
|
# if it was a new card, it's now a learning card
|
||||||
if card.type == 0:
|
if card.type == CARD_TYPE_NEW:
|
||||||
card.type = 1
|
card.type = 1
|
||||||
# init reps to graduation
|
# init reps to graduation
|
||||||
card.left = self._startingLeft(card)
|
card.left = self._startingLeft(card)
|
||||||
@ -142,7 +142,7 @@ order by due"""
|
|||||||
if card.odid and card.queue == 2:
|
if card.odid and card.queue == 2:
|
||||||
return 4
|
return 4
|
||||||
conf = self._lrnConf(card)
|
conf = self._lrnConf(card)
|
||||||
if card.type in (0, 1) or len(conf["delays"]) > 1:
|
if card.type in (CARD_TYPE_NEW, 1) or len(conf["delays"]) > 1:
|
||||||
return 3
|
return 3
|
||||||
return 2
|
return 2
|
||||||
elif card.queue == 2:
|
elif card.queue == 2:
|
||||||
@ -348,9 +348,9 @@ order by due"""
|
|||||||
|
|
||||||
def _resetNewCount(self):
|
def _resetNewCount(self):
|
||||||
cntFn = lambda did, lim: self.col.db.scalar(
|
cntFn = lambda did, lim: self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from (select 1 from cards where
|
select count() from (select 1 from cards where
|
||||||
did = ? and queue = 0 limit ?)""",
|
did = ? and queue = {QUEUE_TYPE_NEW} limit ?)""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -373,8 +373,8 @@ did = ? and queue = 0 limit ?)""",
|
|||||||
if lim:
|
if lim:
|
||||||
# fill the queue with the current did
|
# fill the queue with the current did
|
||||||
self._newQueue = self.col.db.list(
|
self._newQueue = self.col.db.list(
|
||||||
"""
|
f"""
|
||||||
select id from cards where did = ? and queue = 0 order by due,ord limit ?""",
|
select id from cards where did = ? and queue = {QUEUE_TYPE_NEW} order by due,ord limit ?""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -436,9 +436,9 @@ did = ? and queue = 0 limit ?)""",
|
|||||||
return 0
|
return 0
|
||||||
lim = min(lim, self.reportLimit)
|
lim = min(lim, self.reportLimit)
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from
|
select count() from
|
||||||
(select 1 from cards where did = ? and queue = 0 limit ?)""",
|
(select 1 from cards where did = ? and queue = {QUEUE_TYPE_NEW} limit ?)""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -452,9 +452,9 @@ select count() from
|
|||||||
|
|
||||||
def totalNewForCurrentDeck(self):
|
def totalNewForCurrentDeck(self):
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from cards where id in (
|
select count() from cards where id in (
|
||||||
select id from cards where did in %s and queue = 0 limit ?)"""
|
select id from cards where did in %s and queue = {QUEUE_TYPE_NEW} limit ?)"""
|
||||||
% ids2str(self.col.decks.active()),
|
% ids2str(self.col.decks.active()),
|
||||||
self.reportLimit,
|
self.reportLimit,
|
||||||
)
|
)
|
||||||
@ -652,7 +652,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
|
|||||||
card.odid = 0
|
card.odid = 0
|
||||||
# if rescheduling is off, it needs to be set back to a new card
|
# if rescheduling is off, it needs to be set back to a new card
|
||||||
if not resched and not lapse:
|
if not resched and not lapse:
|
||||||
card.queue = card.type = 0
|
card.queue = card.type = CARD_TYPE_NEW
|
||||||
card.due = self.col.nextID("pos")
|
card.due = self.col.nextID("pos")
|
||||||
|
|
||||||
def _startingLeft(self, card):
|
def _startingLeft(self, card):
|
||||||
@ -1058,9 +1058,9 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
|
|||||||
self.col.log(self.col.db.list("select id from cards where %s" % lim))
|
self.col.log(self.col.db.list("select id from cards where %s" % lim))
|
||||||
# move out of cram queue
|
# move out of cram queue
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set did = odid, queue = (case when type = 1 then 0
|
update cards set did = odid, queue = (case when type = 1 then {QUEUE_TYPE_NEW}
|
||||||
else type end), type = (case when type = 1 then 0 else type end),
|
else type end), type = (case when type = 1 then {CARD_TYPE_NEW} else type end),
|
||||||
due = odue, odue = 0, odid = 0, usn = ? where %s"""
|
due = odue, odue = 0, odid = 0, usn = ? where %s"""
|
||||||
% lim,
|
% lim,
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
@ -1106,9 +1106,9 @@ due = odue, odue = 0, odid = 0, usn = ? where %s"""
|
|||||||
data.append((did, -100000 + c, u, id))
|
data.append((did, -100000 + c, u, id))
|
||||||
# due reviews stay in the review queue. careful: can't use
|
# due reviews stay in the review queue. careful: can't use
|
||||||
# "odid or did", as sqlite converts to boolean
|
# "odid or did", as sqlite converts to boolean
|
||||||
queue = """
|
queue = f"""
|
||||||
(case when type=2 and (case when odue then odue <= %d else due <= %d end)
|
(case when type=2 and (case when odue then odue <= %d else due <= %d end)
|
||||||
then 2 else 0 end)"""
|
then 2 else {QUEUE_TYPE_NEW} end)"""
|
||||||
queue %= (self.today, self.today)
|
queue %= (self.today, self.today)
|
||||||
self.col.db.executemany(
|
self.col.db.executemany(
|
||||||
"""
|
"""
|
||||||
@ -1321,7 +1321,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
|||||||
def newDue(self):
|
def newDue(self):
|
||||||
"True if there are any new cards due."
|
"True if there are any new cards due."
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
("select 1 from cards where did in %s and queue = 0 " "limit 1")
|
(f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} " "limit 1")
|
||||||
% self._deckLimit()
|
% self._deckLimit()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1347,7 +1347,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
|||||||
|
|
||||||
def nextIvl(self, card, ease):
|
def nextIvl(self, card, ease):
|
||||||
"Return the next interval for CARD, in seconds."
|
"Return the next interval for CARD, in seconds."
|
||||||
if card.queue in (0, 1, 3):
|
if card.queue in (QUEUE_TYPE_NEW, 1, 3):
|
||||||
return self._nextLrnIvl(card, ease)
|
return self._nextLrnIvl(card, ease)
|
||||||
elif ease == BUTTON_ONE:
|
elif ease == BUTTON_ONE:
|
||||||
# lapsed
|
# lapsed
|
||||||
@ -1436,9 +1436,9 @@ update cards set queue=-2,mod=?,usn=? where id in """
|
|||||||
buryRev = rconf.get("bury", True)
|
buryRev = rconf.get("bury", True)
|
||||||
# loop through and remove from queues
|
# loop through and remove from queues
|
||||||
for cid, queue in self.col.db.execute(
|
for cid, queue in self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
select id, queue from cards where nid=? and id!=?
|
select id, queue from cards where nid=? and id!=?
|
||||||
and (queue=0 or (queue=2 and due<=?))""",
|
and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""",
|
||||||
card.nid,
|
card.nid,
|
||||||
card.id,
|
card.id,
|
||||||
self.today,
|
self.today,
|
||||||
@ -1475,11 +1475,11 @@ and (queue=0 or (queue=2 and due<=?))""",
|
|||||||
"Put cards at the end of the new queue."
|
"Put cards at the end of the new queue."
|
||||||
self.remFromDyn(ids)
|
self.remFromDyn(ids)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set type=0,queue=0,ivl=0,due=0,odue=0,factor=?"
|
f"update cards set type={CARD_TYPE_NEW},queue={QUEUE_TYPE_NEW},ivl=0,due=0,odue=0,factor=?"
|
||||||
" where id in " + ids2str(ids),
|
" where id in " + ids2str(ids),
|
||||||
STARTING_FACTOR,
|
STARTING_FACTOR,
|
||||||
)
|
)
|
||||||
pmax = self.col.db.scalar("select max(due) from cards where type=0") or 0
|
pmax = self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}") or 0
|
||||||
# takes care of mod + usn
|
# takes care of mod + usn
|
||||||
self.sortCards(ids, start=pmax + 1)
|
self.sortCards(ids, start=pmax + 1)
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
@ -1515,11 +1515,11 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
|||||||
sids = ids2str(ids)
|
sids = ids2str(ids)
|
||||||
# we want to avoid resetting due number of existing new cards on export
|
# we want to avoid resetting due number of existing new cards on export
|
||||||
nonNew = self.col.db.list(
|
nonNew = self.col.db.list(
|
||||||
"select id from cards where id in %s and (queue != 0 or type != 0)" % sids
|
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})" % sids
|
||||||
)
|
)
|
||||||
# reset all cards
|
# reset all cards
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set reps=0,lapses=0,odid=0,odue=0,queue=0"
|
f"update cards set reps=0,lapses=0,odid=0,odue=0,queue={QUEUE_TYPE_NEW}"
|
||||||
" where id in %s" % sids
|
" where id in %s" % sids
|
||||||
)
|
)
|
||||||
# and forget any non-new cards, changing their due numbers
|
# and forget any non-new cards, changing their due numbers
|
||||||
@ -1553,16 +1553,16 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
|||||||
# shift?
|
# shift?
|
||||||
if shift:
|
if shift:
|
||||||
low = self.col.db.scalar(
|
low = self.col.db.scalar(
|
||||||
"select min(due) from cards where due >= ? and type = 0 "
|
f"select min(due) from cards where due >= ? and type = {CARD_TYPE_NEW} "
|
||||||
"and id not in %s" % scids,
|
"and id not in %s" % scids,
|
||||||
start,
|
start,
|
||||||
)
|
)
|
||||||
if low is not None:
|
if low is not None:
|
||||||
shiftby = high - low + 1
|
shiftby = high - low + 1
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set mod=?, usn=?, due=due+? where id not in %s
|
update cards set mod=?, usn=?, due=due+? where id not in %s
|
||||||
and due >= ? and queue = 0"""
|
and due >= ? and queue = {QUEUE_TYPE_NEW}"""
|
||||||
% scids,
|
% scids,
|
||||||
now,
|
now,
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
@ -1572,7 +1572,7 @@ and due >= ? and queue = 0"""
|
|||||||
# reorder cards
|
# reorder cards
|
||||||
d = []
|
d = []
|
||||||
for id, nid in self.col.db.execute(
|
for id, nid in self.col.db.execute(
|
||||||
"select id, nid from cards where type = 0 and id in " + scids
|
f"select id, nid from cards where type = {CARD_TYPE_NEW} and id in " + scids
|
||||||
):
|
):
|
||||||
d.append(dict(now=now, due=due[nid], usn=self.col.usn(), cid=id))
|
d.append(dict(now=now, due=due[nid], usn=self.col.usn(), cid=id))
|
||||||
self.col.db.executemany(
|
self.col.db.executemany(
|
||||||
|
@ -95,7 +95,7 @@ class Scheduler:
|
|||||||
|
|
||||||
card.reps += 1
|
card.reps += 1
|
||||||
|
|
||||||
if card.queue == 0:
|
if card.queue == QUEUE_TYPE_NEW:
|
||||||
# came from the new queue, move to learning
|
# came from the new queue, move to learning
|
||||||
card.queue = 1
|
card.queue = 1
|
||||||
card.type = 1
|
card.type = 1
|
||||||
@ -369,9 +369,9 @@ order by due"""
|
|||||||
|
|
||||||
def _resetNewCount(self) -> None:
|
def _resetNewCount(self) -> None:
|
||||||
cntFn = lambda did, lim: self.col.db.scalar(
|
cntFn = lambda did, lim: self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from (select 1 from cards where
|
select count() from (select 1 from cards where
|
||||||
did = ? and queue = 0 limit ?)""",
|
did = ? and queue = {QUEUE_TYPE_NEW} limit ?)""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -394,8 +394,8 @@ did = ? and queue = 0 limit ?)""",
|
|||||||
if lim:
|
if lim:
|
||||||
# fill the queue with the current did
|
# fill the queue with the current did
|
||||||
self._newQueue = self.col.db.list(
|
self._newQueue = self.col.db.list(
|
||||||
"""
|
f"""
|
||||||
select id from cards where did = ? and queue = 0 order by due,ord limit ?""",
|
select id from cards where did = ? and queue = {QUEUE_TYPE_NEW} order by due,ord limit ?""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -463,9 +463,9 @@ did = ? and queue = 0 limit ?)""",
|
|||||||
return 0
|
return 0
|
||||||
lim = min(lim, self.reportLimit)
|
lim = min(lim, self.reportLimit)
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from
|
select count() from
|
||||||
(select 1 from cards where did = ? and queue = 0 limit ?)""",
|
(select 1 from cards where did = ? and queue = {QUEUE_TYPE_NEW} limit ?)""",
|
||||||
did,
|
did,
|
||||||
lim,
|
lim,
|
||||||
)
|
)
|
||||||
@ -479,9 +479,9 @@ select count() from
|
|||||||
|
|
||||||
def totalNewForCurrentDeck(self) -> Any:
|
def totalNewForCurrentDeck(self) -> Any:
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
"""
|
f"""
|
||||||
select count() from cards where id in (
|
select count() from cards where id in (
|
||||||
select id from cards where did in %s and queue = 0 limit ?)"""
|
select id from cards where did in %s and queue = {QUEUE_TYPE_NEW} limit ?)"""
|
||||||
% self._deckLimit(),
|
% self._deckLimit(),
|
||||||
self.reportLimit,
|
self.reportLimit,
|
||||||
)
|
)
|
||||||
@ -1520,7 +1520,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
|||||||
def newDue(self) -> Any:
|
def newDue(self) -> Any:
|
||||||
"True if there are any new cards due."
|
"True if there are any new cards due."
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
("select 1 from cards where did in %s and queue = 0 " "limit 1")
|
(f"select 1 from cards where did in %s and queue = {QUEUE_TYPE_NEW} " "limit 1")
|
||||||
% self._deckLimit()
|
% self._deckLimit()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1563,7 +1563,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
# (re)learning?
|
# (re)learning?
|
||||||
if card.queue in (0, 1, QUEUE_TYPE_DAY_LEARN_RELEARN):
|
if card.queue in (QUEUE_TYPE_NEW, 1, QUEUE_TYPE_DAY_LEARN_RELEARN):
|
||||||
return self._nextLrnIvl(card, ease)
|
return self._nextLrnIvl(card, ease)
|
||||||
elif ease == BUTTON_ONE:
|
elif ease == BUTTON_ONE:
|
||||||
# lapse
|
# lapse
|
||||||
@ -1581,7 +1581,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
|
|||||||
|
|
||||||
# this isn't easily extracted from the learn code
|
# this isn't easily extracted from the learn code
|
||||||
def _nextLrnIvl(self, card: Card, ease: int) -> Any:
|
def _nextLrnIvl(self, card: Card, ease: int) -> Any:
|
||||||
if card.queue == 0:
|
if card.queue == QUEUE_TYPE_NEW:
|
||||||
card.left = self._startingLeft(card)
|
card.left = self._startingLeft(card)
|
||||||
conf = self._lrnConf(card)
|
conf = self._lrnConf(card)
|
||||||
if ease == BUTTON_ONE:
|
if ease == BUTTON_ONE:
|
||||||
@ -1647,7 +1647,7 @@ update cards set queue=?,mod=?,usn=? where id in """
|
|||||||
def buryNote(self, nid) -> None:
|
def buryNote(self, nid) -> None:
|
||||||
"Bury all cards for note until next session."
|
"Bury all cards for note until next session."
|
||||||
cids = self.col.db.list(
|
cids = self.col.db.list(
|
||||||
"select id from cards where nid = ? and queue >= 0", nid
|
f"select id from cards where nid = ? and queue >= {QUEUE_TYPE_NEW}", nid
|
||||||
)
|
)
|
||||||
self.buryCards(cids)
|
self.buryCards(cids)
|
||||||
|
|
||||||
@ -1699,9 +1699,9 @@ update cards set queue=?,mod=?,usn=? where id in """
|
|||||||
buryRev = rconf.get("bury", True)
|
buryRev = rconf.get("bury", True)
|
||||||
# loop through and remove from queues
|
# loop through and remove from queues
|
||||||
for cid, queue in self.col.db.execute(
|
for cid, queue in self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
select id, queue from cards where nid=? and id!=?
|
select id, queue from cards where nid=? and id!=?
|
||||||
and (queue=0 or (queue=2 and due<=?))""",
|
and (queue={QUEUE_TYPE_NEW} or (queue=2 and due<=?))""",
|
||||||
card.nid,
|
card.nid,
|
||||||
card.id,
|
card.id,
|
||||||
self.today,
|
self.today,
|
||||||
@ -1733,11 +1733,11 @@ and (queue=0 or (queue=2 and due<=?))""",
|
|||||||
"Put cards at the end of the new queue."
|
"Put cards at the end of the new queue."
|
||||||
self.remFromDyn(ids)
|
self.remFromDyn(ids)
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set type=0,queue=0,ivl=0,due=0,odue=0,factor=?"
|
f"update cards set type={CARD_TYPE_NEW},queue={QUEUE_TYPE_NEW},ivl=0,due=0,odue=0,factor=?"
|
||||||
" where id in " + ids2str(ids),
|
" where id in " + ids2str(ids),
|
||||||
STARTING_FACTOR,
|
STARTING_FACTOR,
|
||||||
)
|
)
|
||||||
pmax = self.col.db.scalar("select max(due) from cards where type=0") or 0
|
pmax = self.col.db.scalar(f"select max(due) from cards where type={CARD_TYPE_NEW}") or 0
|
||||||
# takes care of mod + usn
|
# takes care of mod + usn
|
||||||
self.sortCards(ids, start=pmax + 1)
|
self.sortCards(ids, start=pmax + 1)
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
@ -1773,11 +1773,11 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
|||||||
sids = ids2str(ids)
|
sids = ids2str(ids)
|
||||||
# we want to avoid resetting due number of existing new cards on export
|
# we want to avoid resetting due number of existing new cards on export
|
||||||
nonNew = self.col.db.list(
|
nonNew = self.col.db.list(
|
||||||
"select id from cards where id in %s and (queue != 0 or type != 0)" % sids
|
f"select id from cards where id in %s and (queue != {QUEUE_TYPE_NEW} or type != {CARD_TYPE_NEW})" % sids
|
||||||
)
|
)
|
||||||
# reset all cards
|
# reset all cards
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"update cards set reps=0,lapses=0,odid=0,odue=0,queue=0"
|
f"update cards set reps=0,lapses=0,odid=0,odue=0,queue={QUEUE_TYPE_NEW}"
|
||||||
" where id in %s" % sids
|
" where id in %s" % sids
|
||||||
)
|
)
|
||||||
# and forget any non-new cards, changing their due numbers
|
# and forget any non-new cards, changing their due numbers
|
||||||
@ -1818,16 +1818,16 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
|
|||||||
# shift?
|
# shift?
|
||||||
if shift:
|
if shift:
|
||||||
low = self.col.db.scalar(
|
low = self.col.db.scalar(
|
||||||
"select min(due) from cards where due >= ? and type = 0 "
|
f"select min(due) from cards where due >= ? and type = {CARD_TYPE_NEW} "
|
||||||
"and id not in %s" % scids,
|
"and id not in %s" % scids,
|
||||||
start,
|
start,
|
||||||
)
|
)
|
||||||
if low is not None:
|
if low is not None:
|
||||||
shiftby = high - low + 1
|
shiftby = high - low + 1
|
||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
"""
|
f"""
|
||||||
update cards set mod=?, usn=?, due=due+? where id not in %s
|
update cards set mod=?, usn=?, due=due+? where id not in %s
|
||||||
and due >= ? and queue = 0"""
|
and due >= ? and queue = {QUEUE_TYPE_NEW}"""
|
||||||
% scids,
|
% scids,
|
||||||
now,
|
now,
|
||||||
self.col.usn(),
|
self.col.usn(),
|
||||||
@ -1837,7 +1837,7 @@ and due >= ? and queue = 0"""
|
|||||||
# reorder cards
|
# reorder cards
|
||||||
d = []
|
d = []
|
||||||
for id, nid in self.col.db.execute(
|
for id, nid in self.col.db.execute(
|
||||||
"select id, nid from cards where type = 0 and id in " + scids
|
f"select id, nid from cards where type = {CARD_TYPE_NEW} and id in " + scids
|
||||||
):
|
):
|
||||||
d.append(dict(now=now, due=due[nid], usn=self.col.usn(), cid=id))
|
d.append(dict(now=now, due=due[nid], usn=self.col.usn(), cid=id))
|
||||||
self.col.db.executemany(
|
self.col.db.executemany(
|
||||||
@ -1875,10 +1875,10 @@ and due >= ? and queue = 0"""
|
|||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
f"""
|
f"""
|
||||||
update cards set did = odid, queue = (case
|
update cards set did = odid, queue = (case
|
||||||
when type = 1 then 0
|
when type = 1 then {QUEUE_TYPE_NEW}
|
||||||
when type = {CARD_TYPE_RELEARNING} 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 {CARD_TYPE_NEW}
|
||||||
when type = {CARD_TYPE_RELEARNING} 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""",
|
||||||
@ -1917,13 +1917,13 @@ due = odue, odue = 0, odid = 0, usn = ? where odid != 0""",
|
|||||||
self.col.db.execute(
|
self.col.db.execute(
|
||||||
f"""
|
f"""
|
||||||
update cards set type = (case
|
update cards set type = (case
|
||||||
when type = 1 then 0
|
when type = 1 then {CARD_TYPE_NEW}
|
||||||
when type in (2, {CARD_TYPE_RELEARNING}) 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,
|
||||||
mod = %d, usn = %d
|
mod = %d, usn = %d
|
||||||
where queue < 0"""
|
where queue < {QUEUE_TYPE_NEW}"""
|
||||||
% (intTime(), self.col.usn())
|
% (intTime(), self.col.usn())
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1937,7 +1937,7 @@ where queue < 0"""
|
|||||||
# adding 'hard' in v2 scheduler means old ease entries need shifting
|
# adding 'hard' in v2 scheduler means old ease entries need shifting
|
||||||
# up or down
|
# up or down
|
||||||
def _remapLearningAnswers(self, sql: str) -> None:
|
def _remapLearningAnswers(self, sql: str) -> None:
|
||||||
self.col.db.execute("update revlog set %s and type in (0,2)" % sql)
|
self.col.db.execute(f"update revlog set %s and type in ({CARD_TYPE_NEW},2)" % sql)
|
||||||
|
|
||||||
def moveToV1(self) -> None:
|
def moveToV1(self) -> None:
|
||||||
self._emptyAllFiltered()
|
self._emptyAllFiltered()
|
||||||
|
@ -36,7 +36,7 @@ class CardStats:
|
|||||||
self.addLine(_("First Review"), self.date(first / 1000))
|
self.addLine(_("First Review"), self.date(first / 1000))
|
||||||
self.addLine(_("Latest Review"), self.date(last / 1000))
|
self.addLine(_("Latest Review"), self.date(last / 1000))
|
||||||
if c.type in (1, 2):
|
if c.type in (1, 2):
|
||||||
if c.odid or c.queue < 0:
|
if c.odid or c.queue < QUEUE_TYPE_NEW:
|
||||||
next = None
|
next = None
|
||||||
else:
|
else:
|
||||||
if c.queue in (2, 3):
|
if c.queue in (2, 3):
|
||||||
@ -57,7 +57,7 @@ class CardStats:
|
|||||||
if cnt:
|
if cnt:
|
||||||
self.addLine(_("Average Time"), self.time(total / float(cnt)))
|
self.addLine(_("Average Time"), self.time(total / float(cnt)))
|
||||||
self.addLine(_("Total Time"), self.time(total))
|
self.addLine(_("Total Time"), self.time(total))
|
||||||
elif c.queue == 0:
|
elif c.queue == QUEUE_TYPE_NEW:
|
||||||
self.addLine(_("Position"), c.due)
|
self.addLine(_("Position"), c.due)
|
||||||
self.addLine(_("Card Type"), c.template()["name"])
|
self.addLine(_("Card Type"), c.template()["name"])
|
||||||
self.addLine(_("Note Type"), c.model()["name"])
|
self.addLine(_("Note Type"), c.model()["name"])
|
||||||
@ -941,12 +941,12 @@ from cards where did in %s and queue = 2"""
|
|||||||
|
|
||||||
def _cards(self) -> Any:
|
def _cards(self) -> Any:
|
||||||
return self.col.db.first(
|
return self.col.db.first(
|
||||||
"""
|
f"""
|
||||||
select
|
select
|
||||||
sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr
|
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 (1,3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn
|
||||||
sum(case when queue=0 then 1 else 0 end), -- new
|
sum(case when queue={QUEUE_TYPE_NEW} then 1 else 0 end), -- new
|
||||||
sum(case when queue<0 then 1 else 0 end) -- susp
|
sum(case when queue<{QUEUE_TYPE_NEW} then 1 else 0 end) -- susp
|
||||||
from cards where did in %s"""
|
from cards where did in %s"""
|
||||||
% self._limit()
|
% self._limit()
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,7 @@ import copy
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
from anki.consts import STARTING_FACTOR
|
from anki.consts import *
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
from tests.shared import getEmptyCol as getEmptyColOrig
|
from tests.shared import getEmptyCol as getEmptyColOrig
|
||||||
|
|
||||||
@ -46,8 +46,8 @@ def test_new():
|
|||||||
# fetch it
|
# fetch it
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
assert c
|
assert c
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.type == 0
|
assert c.type == CARD_TYPE_NEW
|
||||||
# if we answer it, it should become a learn card
|
# if we answer it, it should become a learn card
|
||||||
t = intTime()
|
t = intTime()
|
||||||
d.sched.answerCard(c, 1)
|
d.sched.answerCard(c, 1)
|
||||||
@ -707,7 +707,7 @@ def test_cram_rem():
|
|||||||
# if we terminate cramming prematurely it should be set back to new
|
# if we terminate cramming prematurely it should be set back to new
|
||||||
d.sched.emptyDyn(did)
|
d.sched.emptyDyn(did)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.type == c.queue == 0
|
assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.due == oldDue
|
assert c.due == oldDue
|
||||||
|
|
||||||
|
|
||||||
@ -731,7 +731,7 @@ def test_cram_resched():
|
|||||||
assert ni(c, 3) == 0
|
assert ni(c, 3) == 0
|
||||||
assert d.sched.nextIvlStr(c, 3) == "(end)"
|
assert d.sched.nextIvlStr(c, 3) == "(end)"
|
||||||
d.sched.answerCard(c, 3)
|
d.sched.answerCard(c, 3)
|
||||||
assert c.queue == c.type == 0
|
assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW
|
||||||
# undue reviews should also be unaffected
|
# undue reviews should also be unaffected
|
||||||
c.ivl = 100
|
c.ivl = 100
|
||||||
c.type = c.queue = 2
|
c.type = c.queue = 2
|
||||||
|
@ -4,7 +4,7 @@ import copy
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
from anki.consts import STARTING_FACTOR
|
from anki.consts import *
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
from tests.shared import getEmptyCol as getEmptyColOrig
|
from tests.shared import getEmptyCol as getEmptyColOrig
|
||||||
|
|
||||||
@ -57,8 +57,8 @@ def test_new():
|
|||||||
# fetch it
|
# fetch it
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
assert c
|
assert c
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.type == 0
|
assert c.type == CARD_TYPE_NEW
|
||||||
# if we answer it, it should become a learn card
|
# if we answer it, it should become a learn card
|
||||||
t = intTime()
|
t = intTime()
|
||||||
d.sched.answerCard(c, 1)
|
d.sched.answerCard(c, 1)
|
||||||
@ -634,7 +634,7 @@ def test_bury():
|
|||||||
|
|
||||||
d.sched.unburyCardsForDeck(type="manual") # pylint: disable=unexpected-keyword-arg
|
d.sched.unburyCardsForDeck(type="manual") # pylint: disable=unexpected-keyword-arg
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
c2.load()
|
c2.load()
|
||||||
assert c2.queue == -2
|
assert c2.queue == -2
|
||||||
|
|
||||||
@ -642,7 +642,7 @@ def test_bury():
|
|||||||
type="siblings"
|
type="siblings"
|
||||||
)
|
)
|
||||||
c2.load()
|
c2.load()
|
||||||
assert c2.queue == 0
|
assert c2.queue == QUEUE_TYPE_NEW
|
||||||
|
|
||||||
d.sched.buryCards([c.id, c2.id])
|
d.sched.buryCards([c.id, c2.id])
|
||||||
d.sched.unburyCardsForDeck(type="all") # pylint: disable=unexpected-keyword-arg
|
d.sched.unburyCardsForDeck(type="all") # pylint: disable=unexpected-keyword-arg
|
||||||
@ -833,9 +833,9 @@ def test_preview():
|
|||||||
|
|
||||||
# passing it will remove it
|
# passing it will remove it
|
||||||
d.sched.answerCard(c2, 2)
|
d.sched.answerCard(c2, 2)
|
||||||
assert c2.queue == 0
|
assert c2.queue == QUEUE_TYPE_NEW
|
||||||
assert c2.reps == 0
|
assert c2.reps == 0
|
||||||
assert c2.type == 0
|
assert c2.type == CARD_TYPE_NEW
|
||||||
|
|
||||||
# the other card should appear again
|
# the other card should appear again
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
@ -844,9 +844,9 @@ def test_preview():
|
|||||||
# emptying the filtered deck should restore card
|
# emptying the filtered deck should restore card
|
||||||
d.sched.emptyDyn(did)
|
d.sched.emptyDyn(did)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.reps == 0
|
assert c.reps == 0
|
||||||
assert c.type == 0
|
assert c.type == CARD_TYPE_NEW
|
||||||
|
|
||||||
|
|
||||||
def test_ordcycle():
|
def test_ordcycle():
|
||||||
@ -1217,8 +1217,8 @@ def test_moveVersions():
|
|||||||
# the move to v2 should reset it to new
|
# the move to v2 should reset it to new
|
||||||
col.changeSchedulerVer(2)
|
col.changeSchedulerVer(2)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.type == 0
|
assert c.type == CARD_TYPE_NEW
|
||||||
|
|
||||||
# fail it again, and manually bury it
|
# fail it again, and manually bury it
|
||||||
col.reset()
|
col.reset()
|
||||||
@ -1238,7 +1238,7 @@ def test_moveVersions():
|
|||||||
# and it should be new again when unburied
|
# and it should be new again when unburied
|
||||||
col.sched.unburyCards()
|
col.sched.unburyCards()
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == c.type == 0
|
assert c.type == CARD_TYPE_NEW and c.queue == QUEUE_TYPE_NEW
|
||||||
|
|
||||||
# make sure relearning cards transition correctly to v1
|
# make sure relearning cards transition correctly to v1
|
||||||
col.changeSchedulerVer(2)
|
col.changeSchedulerVer(2)
|
||||||
|
@ -55,7 +55,7 @@ def test_review():
|
|||||||
# answer
|
# answer
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
c = d.sched.getCard()
|
c = d.sched.getCard()
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
d.sched.answerCard(c, 3)
|
d.sched.answerCard(c, 3)
|
||||||
assert c.left == 1001
|
assert c.left == 1001
|
||||||
assert d.sched.counts() == (0, 1, 0)
|
assert d.sched.counts() == (0, 1, 0)
|
||||||
@ -66,7 +66,7 @@ def test_review():
|
|||||||
d.reset()
|
d.reset()
|
||||||
assert d.sched.counts() == (1, 0, 0)
|
assert d.sched.counts() == (1, 0, 0)
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == 0
|
assert c.queue == QUEUE_TYPE_NEW
|
||||||
assert c.left != 1001
|
assert c.left != 1001
|
||||||
assert not d.undoName()
|
assert not d.undoName()
|
||||||
# we should be able to undo multiple answers too
|
# we should be able to undo multiple answers too
|
||||||
|
@ -335,7 +335,7 @@ class DataModel(QAbstractTableModel):
|
|||||||
return _("(filtered)")
|
return _("(filtered)")
|
||||||
elif c.queue == 1:
|
elif c.queue == 1:
|
||||||
date = c.due
|
date = c.due
|
||||||
elif c.queue == 0 or c.type == 0:
|
elif c.queue == QUEUE_TYPE_NEW or c.type == CARD_TYPE_NEW:
|
||||||
return str(c.due)
|
return str(c.due)
|
||||||
elif c.queue in (2, 3) or (c.type == 2 and c.queue < 0):
|
elif c.queue in (2, 3) or (c.type == 2 and c.queue < 0):
|
||||||
date = time.time() + ((c.due - self.col.sched.today) * 86400)
|
date = time.time() + ((c.due - self.col.sched.today) * 86400)
|
||||||
@ -1428,7 +1428,7 @@ border: 1px solid #000; padding: 3px; '>%s</div>"""
|
|||||||
import anki.stats as st
|
import anki.stats as st
|
||||||
|
|
||||||
fmt = "<span style='color:%s'>%s</span>"
|
fmt = "<span style='color:%s'>%s</span>"
|
||||||
if type == 0:
|
if type == CARD_TYPE_NEW:
|
||||||
tstr = fmt % (st.colLearn, tstr)
|
tstr = fmt % (st.colLearn, tstr)
|
||||||
elif type == 1:
|
elif type == 1:
|
||||||
tstr = fmt % (st.colMature, tstr)
|
tstr = fmt % (st.colMature, tstr)
|
||||||
@ -1936,7 +1936,7 @@ update cards set usn=?, mod=?, did=? where id in """
|
|||||||
def _reposition(self):
|
def _reposition(self):
|
||||||
cids = self.selectedCards()
|
cids = self.selectedCards()
|
||||||
cids2 = self.col.db.list(
|
cids2 = self.col.db.list(
|
||||||
"select id from cards where type = 0 and id in " + ids2str(cids)
|
f"select id from cards where type = {CARD_TYPE_NEW} and id in " + ids2str(cids)
|
||||||
)
|
)
|
||||||
if not cids2:
|
if not cids2:
|
||||||
return showInfo(_("Only new cards can be repositioned."))
|
return showInfo(_("Only new cards can be repositioned."))
|
||||||
@ -1945,7 +1945,7 @@ update cards set usn=?, mod=?, did=? where id in """
|
|||||||
frm = aqt.forms.reposition.Ui_Dialog()
|
frm = aqt.forms.reposition.Ui_Dialog()
|
||||||
frm.setupUi(d)
|
frm.setupUi(d)
|
||||||
(pmin, pmax) = self.col.db.first(
|
(pmin, pmax) = self.col.db.first(
|
||||||
"select min(due), max(due) from cards where type=0 and odid=0"
|
f"select min(due), max(due) from cards where type={CARD_TYPE_NEW} and odid=0"
|
||||||
)
|
)
|
||||||
pmin = pmin or 0
|
pmin = pmin or 0
|
||||||
pmax = pmax or 0
|
pmax = pmax or 0
|
||||||
|
Loading…
Reference in New Issue
Block a user