mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add edue to cards
The 'entry due' is the due time of a failed card before it enters the learning queue. When the card graduates or is removed, it has its old due time restored. We could pull this from the revlog, but it's cheaper to do it this way.
This commit is contained in:
parent
17ee7757de
commit
e49211c5b6
3 changed files with 26 additions and 11 deletions
|
@ -14,7 +14,7 @@ MAX_TIMER = 60
|
||||||
# Queue: 0=learning, 1=due, 2=new
|
# Queue: 0=learning, 1=due, 2=new
|
||||||
# -1=suspended, -2=user buried, -3=sched buried
|
# -1=suspended, -2=user buried, -3=sched buried
|
||||||
# Due is used differently for different queues.
|
# Due is used differently for different queues.
|
||||||
# - new queue: fact id
|
# - new queue: fact id or random int
|
||||||
# - rev queue: integer day
|
# - rev queue: integer day
|
||||||
# - lrn queue: integer timestamp
|
# - lrn queue: integer timestamp
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class Card(object):
|
||||||
self.lapses = 0
|
self.lapses = 0
|
||||||
self.grade = 0
|
self.grade = 0
|
||||||
self.cycles = 0
|
self.cycles = 0
|
||||||
|
self.edue = 0
|
||||||
self.data = ""
|
self.data = ""
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
@ -60,6 +61,7 @@ class Card(object):
|
||||||
self.lapses,
|
self.lapses,
|
||||||
self.grade,
|
self.grade,
|
||||||
self.cycles,
|
self.cycles,
|
||||||
|
self.edue,
|
||||||
self.data) = self.deck.db.first(
|
self.data) = self.deck.db.first(
|
||||||
"select * from cards where id = ?", self.id)
|
"select * from cards where id = ?", self.id)
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ class Card(object):
|
||||||
self.deck.db.execute(
|
self.deck.db.execute(
|
||||||
"""
|
"""
|
||||||
insert or replace into cards values
|
insert or replace into cards values
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
self.id,
|
self.id,
|
||||||
self.fid,
|
self.fid,
|
||||||
self.gid,
|
self.gid,
|
||||||
|
@ -85,6 +87,7 @@ insert or replace into cards values
|
||||||
self.lapses,
|
self.lapses,
|
||||||
self.grade,
|
self.grade,
|
||||||
self.cycles,
|
self.cycles,
|
||||||
|
self.edue,
|
||||||
self.data)
|
self.data)
|
||||||
|
|
||||||
def flushSched(self):
|
def flushSched(self):
|
||||||
|
@ -92,10 +95,10 @@ insert or replace into cards values
|
||||||
self.deck.db.execute(
|
self.deck.db.execute(
|
||||||
"""update cards set
|
"""update cards set
|
||||||
mod=?, type=?, queue=?, due=?, ivl=?, factor=?, reps=?,
|
mod=?, type=?, queue=?, due=?, ivl=?, factor=?, reps=?,
|
||||||
streak=?, lapses=?, grade=?, cycles=? where id = ?""",
|
streak=?, lapses=?, grade=?, cycles=?, edue=? where id = ?""",
|
||||||
self.mod, self.type, self.queue, self.due, self.ivl,
|
self.mod, self.type, self.queue, self.due, self.ivl,
|
||||||
self.factor, self.reps, self.streak, self.lapses,
|
self.factor, self.reps, self.streak, self.lapses,
|
||||||
self.grade, self.cycles, self.id)
|
self.grade, self.cycles, self.edue, self.id)
|
||||||
|
|
||||||
def q(self):
|
def q(self):
|
||||||
return self._getQA()['q']
|
return self._getQA()['q']
|
||||||
|
|
|
@ -204,8 +204,8 @@ limit %d""" % self.learnLimit, lim=self.dayCutoff)
|
||||||
card.queue = 1
|
card.queue = 1
|
||||||
card.type = 1
|
card.type = 1
|
||||||
if card.type == 1:
|
if card.type == 1:
|
||||||
# failed, nothing else to do
|
# failed; put back entry due
|
||||||
pass
|
card.due = card.edue
|
||||||
else:
|
else:
|
||||||
self.rescheduleNew(card, conf, early)
|
self.rescheduleNew(card, conf, early)
|
||||||
|
|
||||||
|
@ -230,6 +230,14 @@ limit %d""" % self.learnLimit, lim=self.dayCutoff)
|
||||||
self.delayForGrade(conf, max(0, card.grade-1)),
|
self.delayForGrade(conf, max(0, card.grade-1)),
|
||||||
leaving, card.timeTaken(), 0)
|
leaving, card.timeTaken(), 0)
|
||||||
|
|
||||||
|
def removeFailed(self):
|
||||||
|
"Remove failed cards from the learning queue."
|
||||||
|
self.deck.db.execute("""
|
||||||
|
update cards set
|
||||||
|
due = edue, queue = 1
|
||||||
|
where queue = 0 and type = 1
|
||||||
|
""")
|
||||||
|
|
||||||
# Reviews
|
# Reviews
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ create table if not exists cards (
|
||||||
lapses integer not null,
|
lapses integer not null,
|
||||||
grade integer not null,
|
grade integer not null,
|
||||||
cycles integer not null,
|
cycles integer not null,
|
||||||
|
edue integer not null,
|
||||||
data text not null
|
data text not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -247,7 +248,7 @@ def _upgradeSchema(db):
|
||||||
db.execute("""
|
db.execute("""
|
||||||
insert into cards select rowid, factId, cardModelId, 1, cast(created as int),
|
insert into cards select rowid, factId, cardModelId, 1, cast(created as int),
|
||||||
cast(modified as int), relativeDelay, type, due, cast(interval as int),
|
cast(modified as int), relativeDelay, type, due, cast(interval as int),
|
||||||
cast(factor*1000 as int), reps, successive, noCount, 0, 0, "" from cards2
|
cast(factor*1000 as int), reps, successive, noCount, 0, 0, 0, "" from cards2
|
||||||
order by created""")
|
order by created""")
|
||||||
db.execute("drop table cards2")
|
db.execute("drop table cards2")
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ from facts order by created""")
|
||||||
row.append(minimizeHTML("\x1f".join([x[1] for x in sorted(fields[oldid])])))
|
row.append(minimizeHTML("\x1f".join([x[1] for x in sorted(fields[oldid])])))
|
||||||
data.append(row)
|
data.append(row)
|
||||||
# use the new order to rewrite fact ids in cards table
|
# use the new order to rewrite fact ids in cards table
|
||||||
_insertWithIdChange(db, map, 1, "cards", 17)
|
_insertWithIdChange(db, map, 1, "cards", 18)
|
||||||
# and put the facts into the new table
|
# and put the facts into the new table
|
||||||
db.execute("drop table facts")
|
db.execute("drop table facts")
|
||||||
_addSchema(db, False)
|
_addSchema(db, False)
|
||||||
|
@ -494,12 +495,15 @@ def _postSchemaUpgrade(deck):
|
||||||
# rewrite due times for new cards
|
# rewrite due times for new cards
|
||||||
deck.db.execute("""
|
deck.db.execute("""
|
||||||
update cards set due = fid where type=2""")
|
update cards set due = fid where type=2""")
|
||||||
# convert due cards into day-based due
|
# and failed cards
|
||||||
|
deck.db.execute("update cards set edue = ? where type = 0",
|
||||||
|
deck.sched.today+1)
|
||||||
|
# and due cards
|
||||||
deck.db.execute("""
|
deck.db.execute("""
|
||||||
update cards set due = cast(
|
update cards set due = cast(
|
||||||
(case when due < :stamp then 0 else 1 end) +
|
(case when due < :stamp then 0 else 1 end) +
|
||||||
((due-:stamp)/86400) as int)+:today where type
|
((due-:stamp)/86400) as int)+:today where type = 1
|
||||||
between 0 and 1""", stamp=deck.sched.dayCutoff, today=deck.sched.today)
|
""", stamp=deck.sched.dayCutoff, today=deck.sched.today)
|
||||||
# update insertion id
|
# update insertion id
|
||||||
deck.conf['nextFid'] = deck.db.scalar("select max(id) from facts")+1
|
deck.conf['nextFid'] = deck.db.scalar("select max(id) from facts")+1
|
||||||
deck.conf['nextCid'] = deck.db.scalar("select max(id) from cards")+1
|
deck.conf['nextCid'] = deck.db.scalar("select max(id) from cards")+1
|
||||||
|
|
Loading…
Reference in a new issue