mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
revlog updates
- use negative numbers to denote second intervals - record the rev ivl when leaving lrn queue - improve revlog upgrade - don't truncate precision when recording time taken
This commit is contained in:
parent
497c25daa4
commit
0df95eafc0
5 changed files with 32 additions and 20 deletions
|
@ -143,4 +143,4 @@ lapses=?, grade=?, cycles=?, edue=? where id = ?""",
|
||||||
|
|
||||||
def timeTaken(self):
|
def timeTaken(self):
|
||||||
"Time taken to answer card, in integer MS."
|
"Time taken to answer card, in integer MS."
|
||||||
return int(time.time() - self.timerStarted)*1000
|
return int((time.time() - self.timerStarted)*1000)
|
||||||
|
|
|
@ -13,6 +13,10 @@ from anki.hooks import runHook
|
||||||
|
|
||||||
# fixme: on upgrade cards are ordered but order defaults to random
|
# fixme: on upgrade cards are ordered but order defaults to random
|
||||||
|
|
||||||
|
# revlog:
|
||||||
|
# types: 0=lrn, 1=rev, 2=relrn, 3=cram, 4=resched
|
||||||
|
# positive intervals are in days (rev), negative intervals in seconds (lrn)
|
||||||
|
|
||||||
# the standard Anki scheduler
|
# the standard Anki scheduler
|
||||||
class Scheduler(object):
|
class Scheduler(object):
|
||||||
name = "std"
|
name = "std"
|
||||||
|
@ -359,15 +363,14 @@ limit %d""" % (self._groupLimit(), self.reportLimit), lim=self.dayCutoff)
|
||||||
def _logLrn(self, card, ease, conf, leaving, type):
|
def _logLrn(self, card, ease, conf, leaving, type):
|
||||||
# limit time taken to global setting
|
# limit time taken to global setting
|
||||||
taken = min(card.timeTaken(), self._cardConf(card)['maxTaken']*1000)
|
taken = min(card.timeTaken(), self._cardConf(card)['maxTaken']*1000)
|
||||||
|
lastIvl = -(self._delayForGrade(conf, max(0, card.grade-1)))
|
||||||
|
ivl = card.ivl if leaving else -(self._delayForGrade(conf, card.grade))
|
||||||
def log():
|
def log():
|
||||||
self.deck.db.execute(
|
self.deck.db.execute(
|
||||||
"insert into revlog values (?,?,?,?,?,?,?,?,?)",
|
"insert into revlog values (?,?,?,?,?,?,?,?,?)",
|
||||||
int(time.time()*1000), card.id, ease, card.cycles,
|
int(time.time()*1000), card.id, ease, card.cycles,
|
||||||
# interval
|
ivl, lastIvl,
|
||||||
self._delayForGrade(conf, card.grade),
|
card.factor, taken, type)
|
||||||
# last interval
|
|
||||||
self._delayForGrade(conf, max(0, card.grade-1)),
|
|
||||||
leaving, taken, type)
|
|
||||||
try:
|
try:
|
||||||
log()
|
log()
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -64,14 +64,13 @@ class CardStats(object):
|
||||||
|
|
||||||
def date(self, tm):
|
def date(self, tm):
|
||||||
return time.strftime("%Y-%m-%d", time.localtime(tm))
|
return time.strftime("%Y-%m-%d", time.localtime(tm))
|
||||||
s = anki.utils.fmtTimeSpan(time.time() - tm)
|
|
||||||
return _("%s ago") % s
|
|
||||||
|
|
||||||
def time(self, tm):
|
def time(self, tm):
|
||||||
str = ""
|
str = ""
|
||||||
if tm >= 60:
|
if tm >= 60:
|
||||||
str = fmtTimeSpan((tm/60)*60, short=True, point=-1, unit=1)
|
str = fmtTimeSpan((tm/60)*60, short=True, point=-1, unit=1)
|
||||||
str += fmtTimeSpan(tm%60, short=True)
|
if tm%60 != 0 or not str:
|
||||||
|
str += fmtTimeSpan(tm%60, point=2 if not str else -1, short=True)
|
||||||
return str
|
return str
|
||||||
|
|
||||||
# Deck stats
|
# Deck stats
|
||||||
|
|
|
@ -329,7 +329,7 @@ select
|
||||||
cast(time*1000 as int), cardId, ease, reps,
|
cast(time*1000 as int), cardId, ease, reps,
|
||||||
cast(nextInterval as int), cast(lastInterval as int),
|
cast(nextInterval as int), cast(lastInterval as int),
|
||||||
cast(nextFactor*1000 as int), cast(min(thinkingTime, 60)*1000 as int),
|
cast(nextFactor*1000 as int), cast(min(thinkingTime, 60)*1000 as int),
|
||||||
1 from reviewHistory"""):
|
yesCount from reviewHistory"""):
|
||||||
row = list(row)
|
row = list(row)
|
||||||
# new card ids
|
# new card ids
|
||||||
try:
|
try:
|
||||||
|
@ -339,15 +339,25 @@ cast(nextFactor*1000 as int), cast(min(thinkingTime, 60)*1000 as int),
|
||||||
continue
|
continue
|
||||||
# no ease 0 anymore
|
# no ease 0 anymore
|
||||||
row[2] = row[2] or 1
|
row[2] = row[2] or 1
|
||||||
if row[3] == 1:
|
# determine type, overwriting yesCount
|
||||||
# initial rep; set type=lrn
|
reps = row[3]
|
||||||
row[8] = 0
|
newInt = row[4]
|
||||||
elif row[2] == 1 and row[5] >= 3:
|
oldInt = row[5]
|
||||||
# lapsed card
|
yesCnt = row[8]
|
||||||
|
# yesCnt included the current answer
|
||||||
|
if row[2] > 1:
|
||||||
|
yesCnt -= 1
|
||||||
|
if oldInt < 1:
|
||||||
|
# new or failed
|
||||||
|
if yesCnt:
|
||||||
|
# type=relrn
|
||||||
|
row[8] = 2
|
||||||
|
else:
|
||||||
|
# type=lrn
|
||||||
|
row[8] = 0
|
||||||
|
else:
|
||||||
|
# type=rev
|
||||||
row[8] = 1
|
row[8] = 1
|
||||||
elif row[4] < 3:
|
|
||||||
# low interval; set type=relrn
|
|
||||||
row[8] = 2
|
|
||||||
r.append(row)
|
r.append(row)
|
||||||
db.executemany(
|
db.executemany(
|
||||||
"insert or ignore into revlog values (?,?,?,?,?,?,?,?,?)", r)
|
"insert or ignore into revlog values (?,?,?,?,?,?,?,?,?)", r)
|
||||||
|
|
|
@ -81,8 +81,8 @@ def test_learn():
|
||||||
log = d.db.first("select * from revlog order by time desc")
|
log = d.db.first("select * from revlog order by time desc")
|
||||||
assert log[2] == 2
|
assert log[2] == 2
|
||||||
assert log[3] == 2
|
assert log[3] == 2
|
||||||
assert log[4] == 180
|
assert log[4] == -180
|
||||||
assert log[5] == 30
|
assert log[5] == -30
|
||||||
# pass again
|
# pass again
|
||||||
d.sched.answerCard(c, 2)
|
d.sched.answerCard(c, 2)
|
||||||
# it should by due in 10 minutes
|
# it should by due in 10 minutes
|
||||||
|
|
Loading…
Reference in a new issue