drop streak, make reps log all entries

reps should now be equal to the number of entries in the revlog, and only
exists so that we can order by review count in the browser efficiently

streak is no longer necessary as we have a learn queue now
This commit is contained in:
Damien Elmes 2011-04-19 09:38:18 +09:00
parent 946b54185e
commit 7d64036a07
6 changed files with 21 additions and 25 deletions

View file

@ -36,7 +36,6 @@ class Card(object):
self.ivl = 0 self.ivl = 0
self.factor = 0 self.factor = 0
self.reps = 0 self.reps = 0
self.streak = 0
self.lapses = 0 self.lapses = 0
self.grade = 0 self.grade = 0
self.cycles = 0 self.cycles = 0
@ -56,7 +55,6 @@ class Card(object):
self.ivl, self.ivl,
self.factor, self.factor,
self.reps, self.reps,
self.streak,
self.lapses, self.lapses,
self.grade, self.grade,
self.cycles, self.cycles,
@ -71,7 +69,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,
@ -84,7 +82,6 @@ insert or replace into cards values
self.ivl, self.ivl,
self.factor, self.factor,
self.reps, self.reps,
self.streak,
self.lapses, self.lapses,
self.grade, self.grade,
self.cycles, self.cycles,
@ -96,9 +93,9 @@ 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=?, edue=? where id = ?""", 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.lapses,
self.grade, self.cycles, self.edue, self.id) self.grade, self.cycles, self.edue, self.id)
def q(self, classes="q", reload=False): def q(self, classes="q", reload=False):

View file

@ -234,7 +234,7 @@ qconf=?, conf=?, data=?""",
# notice any new tags # notice any new tags
self.registerTags(fact.tags) self.registerTags(fact.tags)
# if random mode, determine insertion point # if random mode, determine insertion point
if self.qconf['newOrder'] == NEW_CARDS_RANDOM: if self.randomNew():
due = random.randrange(0, 1000000) due = random.randrange(0, 1000000)
else: else:
due = fact.id due = fact.id
@ -287,7 +287,7 @@ select id from facts where id not in (select distinct fid from cards)""")
"Generate cards for templates if cards not empty. Return cards." "Generate cards for templates if cards not empty. Return cards."
cards = [] cards = []
# if random mode, determine insertion point # if random mode, determine insertion point
if self.qconf['newOrder'] == NEW_CARDS_RANDOM: if self.randomNew():
# if this fact has existing new cards, use their due time # if this fact has existing new cards, use their due time
due = self.db.scalar( due = self.db.scalar(
"select due from cards where fid = ? and queue = 0", fact.id) "select due from cards where fid = ? and queue = 0", fact.id)
@ -335,6 +335,9 @@ select id from facts where id not in (select distinct fid from cards)""")
card.flush() card.flush()
return card return card
def randomNew(self):
return self.qconf['newOrder'] == NEW_CARDS_RANDOM
# Cards # Cards
########################################################################## ##########################################################################

View file

@ -11,6 +11,8 @@ from anki.lang import _, ngettext
from anki.consts import * from anki.consts import *
from anki.hooks import runHook from anki.hooks import runHook
# fixme: on upgrade cards are ordered but order defaults to random
# the standard Anki scheduler # the standard Anki scheduler
class Scheduler(object): class Scheduler(object):
name = "std" name = "std"
@ -37,8 +39,9 @@ class Scheduler(object):
self._resetNew() self._resetNew()
def answerCard(self, card, ease): def answerCard(self, card, ease):
self.deck.markReview(card)
assert ease >= 1 and ease <= 4 assert ease >= 1 and ease <= 4
self.deck.markReview(card)
card.reps += 1
if card.queue == 0: if card.queue == 0:
# put it in the learn queue # put it in the learn queue
card.queue = 1 card.queue = 1
@ -196,7 +199,7 @@ from cards group by gid""", self.today):
# New cards # New cards
########################################################################## ##########################################################################
# need to keep track of reps for timebox and new card introduction # FIXME: need to keep track of reps for timebox and new card introduction
def _resetNewCount(self): def _resetNewCount(self):
l = self.deck.qconf l = self.deck.qconf
@ -423,7 +426,6 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
########################################################################## ##########################################################################
def _answerRevCard(self, card, ease): def _answerRevCard(self, card, ease):
card.reps += 1
if ease == 1: if ease == 1:
self._rescheduleLapse(card) self._rescheduleLapse(card)
else: else:
@ -432,7 +434,6 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
def _rescheduleLapse(self, card): def _rescheduleLapse(self, card):
conf = self._cardConf(card)['lapse'] conf = self._cardConf(card)['lapse']
card.streak = 0
card.lapses += 1 card.lapses += 1
card.lastIvl = card.ivl card.lastIvl = card.ivl
card.ivl = self._nextLapseIvl(card, conf) card.ivl = self._nextLapseIvl(card, conf)
@ -452,7 +453,6 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
return int(card.ivl*conf['mult']) + 1 return int(card.ivl*conf['mult']) + 1
def _rescheduleRev(self, card, ease): def _rescheduleRev(self, card, ease):
card.streak += 1
# update interval # update interval
card.lastIvl = card.ivl card.lastIvl = card.ivl
self._updateRevIvl(card, ease) self._updateRevIvl(card, ease)
@ -747,10 +747,9 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
# - should remove all scheduling history so we don't show more new ca # - should remove all scheduling history so we don't show more new ca
def resetCards(self, ids=None): def resetCards(self, ids=None):
"Reset progress on cards in IDS." "Reset progress on cards in IDS."
print "position in resetCards()"
sql = """ sql = """
update cards set mod=:now, position=0, type=2, queue=2, lastInterval=0, update cards set mod=%d, due=fid, type=0, queue=0, ivl=0, factor=0, reps=0,
interval=0, due=created, factor=2.5, reps=0, successive=0, lapses=0, flags=0""" lapses=0, grade=0, cycles=0, edue=0, data=''"""
sql2 = "delete from revlog" sql2 = "delete from revlog"
if ids is None: if ids is None:
lim = "" lim = ""
@ -760,7 +759,7 @@ interval=0, due=created, factor=2.5, reps=0, successive=0, lapses=0, flags=0"""
sql2 += " where cardId in "+sids sql2 += " where cardId in "+sids
self.deck.db.execute(sql, now=time.time()) self.deck.db.execute(sql, now=time.time())
self.deck.db.execute(sql2) self.deck.db.execute(sql2)
if self.qconf['newOrder'] == NEW_CARDS_RANDOM: if self.deck.randomNew():
# we need to re-randomize now # we need to re-randomize now
self.randomizeNewCards(ids) self.randomizeNewCards(ids)

View file

@ -39,9 +39,9 @@ class CardStats(object):
self.addLine(_("Due"), next) self.addLine(_("Due"), next)
self.addLine(_("Interval"), fmt(c.ivl * 86400)) self.addLine(_("Interval"), fmt(c.ivl * 86400))
self.addLine(_("Ease"), "%d%%" % (c.factor/10.0)) self.addLine(_("Ease"), "%d%%" % (c.factor/10.0))
if c.reps: # if c.reps:
self.addLine(_("Reviews"), "%d/%d (s=%d)" % ( # self.addLine(_("Reviews"), "%d/%d (s=%d)" % (
c.reps-c.lapses, c.reps, c.streak)) # c.reps-c.lapses, c.reps, c.streak))
(cnt, total) = self.deck.db.first( (cnt, total) = self.deck.db.first(
"select count(), sum(taken)/1000 from revlog where cid = :id", id=c.id) "select count(), sum(taken)/1000 from revlog where cid = :id", id=c.id)
if cnt: if cnt:

View file

@ -84,7 +84,6 @@ create table if not exists cards (
ivl integer not null, ivl integer not null,
factor integer not null, factor integer not null,
reps integer not null, reps integer not null,
streak integer not null,
lapses integer not null, lapses integer not null,
grade integer not null, grade integer not null,
cycles integer not null, cycles integer not null,
@ -254,7 +253,7 @@ when 1 then 2
when 2 then 0 when 2 then 0
else type end), else type end),
due, cast(interval as int), due, cast(interval as int),
cast(factor*1000 as int), reps, successive, noCount, 0, 0, 0, "" from cards2 cast(factor*1000 as int), reps, noCount, 0, 0, 0, "" from cards2
order by created""") order by created""")
db.execute("drop table cards2") db.execute("drop table cards2")
@ -300,7 +299,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", 18) _insertWithIdChange(db, map, 1, "cards", 17)
# 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)

View file

@ -167,7 +167,6 @@ def test_reviews():
# factor should have been decremented # factor should have been decremented
assert c.factor == 2300 assert c.factor == 2300
# check counters # check counters
assert c.streak == 0
assert c.lapses == 2 assert c.lapses == 2
assert c.reps == 4 assert c.reps == 4
# try again with an ease of 2 instead # try again with an ease of 2 instead
@ -182,7 +181,6 @@ def test_reviews():
# factor should have been decremented # factor should have been decremented
assert c.factor == 2350 assert c.factor == 2350
# check counters # check counters
assert c.streak == 3
assert c.lapses == 1 assert c.lapses == 1
assert c.reps == 4 assert c.reps == 4
# ease 3 # ease 3