mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
be consistent with .db references
This commit is contained in:
parent
884405d2a6
commit
58fa7ff714
2 changed files with 91 additions and 85 deletions
|
@ -66,7 +66,7 @@ class CramScheduler(Scheduler):
|
||||||
maxlim = "and due <= %d" % (self.today+1+self.max)
|
maxlim = "and due <= %d" % (self.today+1+self.max)
|
||||||
else:
|
else:
|
||||||
maxlim = ""
|
maxlim = ""
|
||||||
self.newQueue = self.db.list("""
|
self.newQueue = self.deck.db.list("""
|
||||||
select id from cards where queue = 2 and due >= %d
|
select id from cards where queue = 2 and due >= %d
|
||||||
%s
|
%s
|
||||||
%s order by %s limit %d""" % (self.today+1+self.min,
|
%s order by %s limit %d""" % (self.today+1+self.min,
|
||||||
|
|
174
anki/sched.py
174
anki/sched.py
|
@ -16,7 +16,6 @@ class Scheduler(object):
|
||||||
name = "std"
|
name = "std"
|
||||||
def __init__(self, deck):
|
def __init__(self, deck):
|
||||||
self.deck = deck
|
self.deck = deck
|
||||||
self.db = deck.db
|
|
||||||
self.queueLimit = 200
|
self.queueLimit = 200
|
||||||
self.reportLimit = 1000
|
self.reportLimit = 1000
|
||||||
self._updateCutoff()
|
self._updateCutoff()
|
||||||
|
@ -58,7 +57,7 @@ class Scheduler(object):
|
||||||
|
|
||||||
def dueForecast(self, days=7):
|
def dueForecast(self, days=7):
|
||||||
"Return counts over next DAYS. Includes today."
|
"Return counts over next DAYS. Includes today."
|
||||||
daysd = dict(self.db.all("""
|
daysd = dict(self.deck.db.all("""
|
||||||
select due, count() from cards
|
select due, count() from cards
|
||||||
where queue = 2 %s
|
where queue = 2 %s
|
||||||
and due between ? and ?
|
and due between ? and ?
|
||||||
|
@ -85,7 +84,7 @@ order by due""" % self._groupLimit(),
|
||||||
|
|
||||||
def onClose(self):
|
def onClose(self):
|
||||||
"Unbury and remove temporary suspends on close."
|
"Unbury and remove temporary suspends on close."
|
||||||
self.db.execute(
|
self.deck.db.execute(
|
||||||
"update cards set queue = type where queue between -3 and -2")
|
"update cards set queue = type where queue between -3 and -2")
|
||||||
|
|
||||||
# Counts
|
# Counts
|
||||||
|
@ -208,13 +207,13 @@ from cards group by gid""", self.today):
|
||||||
if lim <= 0:
|
if lim <= 0:
|
||||||
self.newCount = 0
|
self.newCount = 0
|
||||||
else:
|
else:
|
||||||
self.newCount = self.db.scalar("""
|
self.newCount = self.deck.db.scalar("""
|
||||||
select count() from (select id from cards where
|
select count() from (select id from cards where
|
||||||
queue = 0 %s limit %d)""" % (self._groupLimit(), lim))
|
queue = 0 %s limit %d)""" % (self._groupLimit(), lim))
|
||||||
|
|
||||||
def _resetNew(self):
|
def _resetNew(self):
|
||||||
lim = min(self.queueLimit, self.newCount)
|
lim = min(self.queueLimit, self.newCount)
|
||||||
self.newQueue = self.db.all("""
|
self.newQueue = self.deck.db.all("""
|
||||||
select id, due from cards where
|
select id, due from cards where
|
||||||
queue = 0 %s order by due limit %d""" % (self._groupLimit(),
|
queue = 0 %s order by due limit %d""" % (self._groupLimit(),
|
||||||
lim))
|
lim))
|
||||||
|
@ -262,14 +261,14 @@ queue = 0 %s order by due limit %d""" % (self._groupLimit(),
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _resetLrnCount(self):
|
def _resetLrnCount(self):
|
||||||
self.lrnCount = self.db.scalar("""
|
self.lrnCount = self.deck.db.scalar("""
|
||||||
select count() from (select id from cards where
|
select count() from (select id from cards where
|
||||||
queue = 1 %s and due < ? limit %d)""" % (
|
queue = 1 %s and due < ? limit %d)""" % (
|
||||||
self._groupLimit(), self.reportLimit),
|
self._groupLimit(), self.reportLimit),
|
||||||
intTime() + self.deck.qconf['collapseTime'])
|
intTime() + self.deck.qconf['collapseTime'])
|
||||||
|
|
||||||
def _resetLrn(self):
|
def _resetLrn(self):
|
||||||
self.lrnQueue = self.db.all("""
|
self.lrnQueue = self.deck.db.all("""
|
||||||
select due, id from cards where
|
select due, id from cards where
|
||||||
queue = 1 %s and due < :lim order by due
|
queue = 1 %s and due < :lim order by due
|
||||||
limit %d""" % (self._groupLimit(), self.reportLimit), lim=self.dayCutoff)
|
limit %d""" % (self._groupLimit(), self.reportLimit), lim=self.dayCutoff)
|
||||||
|
@ -385,14 +384,14 @@ where queue = 1 and type = 2
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _resetRevCount(self):
|
def _resetRevCount(self):
|
||||||
self.revCount = self.db.scalar("""
|
self.revCount = self.deck.db.scalar("""
|
||||||
select count() from (select id from cards where
|
select count() from (select id from cards where
|
||||||
queue = 2 %s and due <= :lim limit %d)""" % (
|
queue = 2 %s and due <= :lim limit %d)""" % (
|
||||||
self._groupLimit(), self.reportLimit),
|
self._groupLimit(), self.reportLimit),
|
||||||
lim=self.today)
|
lim=self.today)
|
||||||
|
|
||||||
def _resetRev(self):
|
def _resetRev(self):
|
||||||
self.revQueue = self.db.list("""
|
self.revQueue = self.deck.db.list("""
|
||||||
select id from cards where
|
select id from cards where
|
||||||
queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
self._groupLimit(), self._revOrder(), self.queueLimit),
|
self._groupLimit(), self._revOrder(), self.queueLimit),
|
||||||
|
@ -507,7 +506,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
idealDue = self.today + idealIvl
|
idealDue = self.today + idealIvl
|
||||||
conf = self._cardConf(card)['rev']
|
conf = self._cardConf(card)['rev']
|
||||||
# find sibling positions
|
# find sibling positions
|
||||||
dues = self.db.list(
|
dues = self.deck.db.list(
|
||||||
"select due from cards where fid = ? and queue = 2"
|
"select due from cards where fid = ? and queue = 2"
|
||||||
" and id != ?", card.fid, card.id)
|
" and id != ?", card.fid, card.id)
|
||||||
if not dues or idealDue not in dues:
|
if not dues or idealDue not in dues:
|
||||||
|
@ -559,7 +558,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
|
|
||||||
def _resetConf(self):
|
def _resetConf(self):
|
||||||
"Update group conf cache."
|
"Update group conf cache."
|
||||||
self.groupConfs = dict(self.db.all("select id, gcid from groups"))
|
self.groupConfs = dict(self.deck.db.all("select id, gcid from groups"))
|
||||||
self.confCache = {}
|
self.confCache = {}
|
||||||
|
|
||||||
def _cardConf(self, card):
|
def _cardConf(self, card):
|
||||||
|
@ -628,13 +627,13 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
|
|
||||||
def lrnTomorrow(self):
|
def lrnTomorrow(self):
|
||||||
"Number of cards in the learning queue due tomorrow."
|
"Number of cards in the learning queue due tomorrow."
|
||||||
return self.db.scalar(
|
return self.deck.db.scalar(
|
||||||
"select count() from cards where queue = 1 and due < ?",
|
"select count() from cards where queue = 1 and due < ?",
|
||||||
self.dayCutoff+86400)
|
self.dayCutoff+86400)
|
||||||
|
|
||||||
def revTomorrow(self):
|
def revTomorrow(self):
|
||||||
"Number of reviews due tomorrow."
|
"Number of reviews due tomorrow."
|
||||||
return self.db.scalar(
|
return self.deck.db.scalar(
|
||||||
"select count() from cards where queue = 2 and due = ?"+
|
"select count() from cards where queue = 2 and due = ?"+
|
||||||
self._groupLimit(),
|
self._groupLimit(),
|
||||||
self.today+1)
|
self.today+1)
|
||||||
|
@ -642,7 +641,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
def newTomorrow(self):
|
def newTomorrow(self):
|
||||||
"Number of new cards tomorrow."
|
"Number of new cards tomorrow."
|
||||||
lim = self.deck.qconf['newPerDay']
|
lim = self.deck.qconf['newPerDay']
|
||||||
return self.db.scalar(
|
return self.deck.db.scalar(
|
||||||
"select count() from (select id from cards where "
|
"select count() from (select id from cards where "
|
||||||
"queue = 0 %s limit %d)" % (self._groupLimit(), lim))
|
"queue = 0 %s limit %d)" % (self._groupLimit(), lim))
|
||||||
|
|
||||||
|
@ -689,13 +688,13 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
|
|
||||||
def suspendCards(self, ids):
|
def suspendCards(self, ids):
|
||||||
"Suspend cards."
|
"Suspend cards."
|
||||||
self.db.execute(
|
self.deck.db.execute(
|
||||||
"update cards set queue = -1, mod = ? where id in "+
|
"update cards set queue = -1, mod = ? where id in "+
|
||||||
ids2str(ids), intTime())
|
ids2str(ids), intTime())
|
||||||
|
|
||||||
def unsuspendCards(self, ids):
|
def unsuspendCards(self, ids):
|
||||||
"Unsuspend cards."
|
"Unsuspend cards."
|
||||||
self.db.execute(
|
self.deck.db.execute(
|
||||||
"update cards set queue = type, mod = ? "
|
"update cards set queue = type, mod = ? "
|
||||||
"where queue = -1 and id in "+ ids2str(ids),
|
"where queue = -1 and id in "+ ids2str(ids),
|
||||||
intTime())
|
intTime())
|
||||||
|
@ -703,7 +702,7 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
def buryFact(self, fid):
|
def buryFact(self, fid):
|
||||||
"Bury all cards for fact until next session."
|
"Bury all cards for fact until next session."
|
||||||
self.deck.setDirty()
|
self.deck.setDirty()
|
||||||
self.db.execute("update cards set queue = -2 where fid = ?", fid)
|
self.deck.db.execute("update cards set queue = -2 where fid = ?", fid)
|
||||||
|
|
||||||
# Counts
|
# Counts
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -737,75 +736,82 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
|
||||||
else:
|
else:
|
||||||
rows = None
|
rows = None
|
||||||
if not (rows and cols == [r[2] for r in rows]):
|
if not (rows and cols == [r[2] for r in rows]):
|
||||||
self.db.execute("drop index if exists ix_cards_multi")
|
self.deck.db.execute("drop index if exists ix_cards_multi")
|
||||||
self.db.execute("create index ix_cards_multi on cards (%s)" %
|
self.deck.db.execute("create index ix_cards_multi on cards (%s)" %
|
||||||
", ".join(cols))
|
", ".join(cols))
|
||||||
self.db.execute("analyze")
|
self.deck.db.execute("analyze")
|
||||||
|
|
||||||
# def resetCards(self, ids=None):
|
# Resetting
|
||||||
# "Reset progress on cards in IDS."
|
##########################################################################
|
||||||
# print "position in resetCards()"
|
|
||||||
# sql = """
|
|
||||||
# update cards set mod=:now, position=0, type=2, queue=2, lastInterval=0,
|
|
||||||
# interval=0, due=created, factor=2.5, reps=0, successive=0, lapses=0, flags=0"""
|
|
||||||
# sql2 = "delete from revlog"
|
|
||||||
# if ids is None:
|
|
||||||
# lim = ""
|
|
||||||
# else:
|
|
||||||
# sids = ids2str(ids)
|
|
||||||
# sql += " where id in "+sids
|
|
||||||
# sql2 += " where cardId in "+sids
|
|
||||||
# self.db.execute(sql, now=time.time())
|
|
||||||
# self.db.execute(sql2)
|
|
||||||
# if self.qconf['newOrder'] == NEW_CARDS_RANDOM:
|
|
||||||
# # we need to re-randomize now
|
|
||||||
# self.randomizeNewCards(ids)
|
|
||||||
|
|
||||||
# def randomizeNewCards(self, cardIds=None):
|
# - should remove all scheduling history so we don't show more new ca
|
||||||
# "Randomize 'due' on all new cards."
|
def resetCards(self, ids=None):
|
||||||
# now = time.time()
|
"Reset progress on cards in IDS."
|
||||||
# query = "select distinct fid from cards where reps = 0"
|
print "position in resetCards()"
|
||||||
# if cardIds:
|
sql = """
|
||||||
# query += " and id in %s" % ids2str(cardIds)
|
update cards set mod=:now, position=0, type=2, queue=2, lastInterval=0,
|
||||||
# fids = self.db.list(query)
|
interval=0, due=created, factor=2.5, reps=0, successive=0, lapses=0, flags=0"""
|
||||||
# data = [{'fid': fid,
|
sql2 = "delete from revlog"
|
||||||
# 'rand': random.uniform(0, now),
|
if ids is None:
|
||||||
# 'now': now} for fid in fids]
|
lim = ""
|
||||||
# self.db.executemany("""
|
else:
|
||||||
# update cards
|
sids = ids2str(ids)
|
||||||
# set due = :rand + ord,
|
sql += " where id in "+sids
|
||||||
# mod = :now
|
sql2 += " where cardId in "+sids
|
||||||
# where fid = :fid
|
self.deck.db.execute(sql, now=time.time())
|
||||||
# and type = 2""", data)
|
self.deck.db.execute(sql2)
|
||||||
|
if self.qconf['newOrder'] == NEW_CARDS_RANDOM:
|
||||||
|
# we need to re-randomize now
|
||||||
|
self.randomizeNewCards(ids)
|
||||||
|
|
||||||
# def orderNewCards(self):
|
def rescheduleCards(self, ids, min, max):
|
||||||
# "Set 'due' to card creation time."
|
"Reset cards and schedule with new interval in days (min, max)."
|
||||||
# self.db.execute("""
|
self.resetCards(ids)
|
||||||
# update cards set
|
vals = []
|
||||||
# due = created,
|
for id in ids:
|
||||||
# mod = :now
|
r = random.uniform(min*86400, max*86400)
|
||||||
# where type = 2""", now=time.time())
|
vals.append({
|
||||||
|
'id': id,
|
||||||
|
'due': r + time.time(),
|
||||||
|
'int': r / 86400.0,
|
||||||
|
't': time.time(),
|
||||||
|
})
|
||||||
|
self.deck.db.executemany("""
|
||||||
|
update cards set
|
||||||
|
interval = :int,
|
||||||
|
due = :due,
|
||||||
|
reps = 1,
|
||||||
|
successive = 1,
|
||||||
|
yesCount = 1,
|
||||||
|
firstAnswered = :t,
|
||||||
|
queue = 1,
|
||||||
|
type = 1,
|
||||||
|
where id = :id""", vals)
|
||||||
|
|
||||||
# def rescheduleCards(self, ids, min, max):
|
# Reordering
|
||||||
# "Reset cards and schedule with new interval in days (min, max)."
|
##########################################################################
|
||||||
# self.resetCards(ids)
|
|
||||||
# vals = []
|
def randomizeNewCards(self, cardIds=None):
|
||||||
# for id in ids:
|
"Randomize 'due' on all new cards."
|
||||||
# r = random.uniform(min*86400, max*86400)
|
now = time.time()
|
||||||
# vals.append({
|
query = "select distinct fid from cards where reps = 0"
|
||||||
# 'id': id,
|
if cardIds:
|
||||||
# 'due': r + time.time(),
|
query += " and id in %s" % ids2str(cardIds)
|
||||||
# 'int': r / 86400.0,
|
fids = self.deck.db.list(query)
|
||||||
# 't': time.time(),
|
data = [{'fid': fid,
|
||||||
# })
|
'rand': random.uniform(0, now),
|
||||||
# self.db.executemany("""
|
'now': now} for fid in fids]
|
||||||
# update cards set
|
self.deck.db.executemany("""
|
||||||
# interval = :int,
|
update cards
|
||||||
# due = :due,
|
set due = :rand + ord,
|
||||||
# reps = 1,
|
mod = :now
|
||||||
# successive = 1,
|
where fid = :fid
|
||||||
# yesCount = 1,
|
and type = 2""", data)
|
||||||
# firstAnswered = :t,
|
|
||||||
# queue = 1,
|
def orderNewCards(self):
|
||||||
# type = 1,
|
"Set 'due' to card creation time."
|
||||||
# where id = :id""", vals)
|
self.deck.db.execute("""
|
||||||
|
update cards set
|
||||||
|
due = created,
|
||||||
|
mod = :now
|
||||||
|
where type = 2""", now=time.time())
|
||||||
|
|
Loading…
Reference in a new issue