本文整理汇总了Python中anki.sched.Scheduler._updateStats方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler._updateStats方法的具体用法?Python Scheduler._updateStats怎么用?Python Scheduler._updateStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.sched.Scheduler
的用法示例。
在下文中一共展示了Scheduler._updateStats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.sched import Scheduler [as 别名]
# 或者: from anki.sched.Scheduler import _updateStats [as 别名]
#.........这里部分代码省略.........
def markReview(self, card):
old = []
if self._undo:
if self._undo[0] == 1:
old = self._undo[2]
self.clearUndo()
wasLeech = card.note().hasTag("leech") or False
self._undo = [1, _("Review"), old + [copy.copy(card)], wasLeech]
def _undoReview(self):
data = self._undo[2]
wasLeech = self._undo[3]
c = data.pop()
if not data:
self.clearUndo()
# remove leech tag if it didn't have it before
if not wasLeech and c.note().hasTag("leech"):
c.note().delTag("leech")
c.note().flush()
# write old data
c.flush()
# and delete revlog entry
last = self.db.scalar(
"select id from revlog where cid = ? "
"order by id desc limit 1", c.id)
self.db.execute("delete from revlog where id = ?", last)
# restore any siblings
self.db.execute(
"update cards set queue=type,mod=?,usn=? where queue=-2 and nid=?",
intTime(), self.usn(), c.nid)
# and finally, update daily counts
n = 1 if c.queue == 3 else c.queue
type = ("new", "lrn", "rev")[n]
self.sched._updateStats(c, type, -1)
self.sched.reps -= 1
return c.id
def _markOp(self, name):
"Call via .save()"
if name:
self._undo = [2, name]
else:
# saving disables old checkpoint, but not review undo
if self._undo and self._undo[0] == 2:
self.clearUndo()
def _undoOp(self):
self.rollback()
self.clearUndo()
# DB maintenance
##########################################################################
def basicCheck(self):
"Basic integrity check for syncing. True if ok."
# cards without notes
if self.db.scalar("""
select 1 from cards where nid not in (select id from notes) limit 1"""):
return
# notes without cards or models
if self.db.scalar("""
select 1 from notes where id not in (select distinct nid from cards)
or mid not in %s limit 1""" % ids2str(self.models.ids())):
return
# invalid ords
for m in self.models.all():
示例2: _Collection
# 需要导入模块: from anki.sched import Scheduler [as 别名]
# 或者: from anki.sched.Scheduler import _updateStats [as 别名]
#.........这里部分代码省略.........
# type 1 = review; type 2 = checkpoint
self._undo = None
def undoName(self):
"Undo menu item name, or None if undo unavailable."
if not self._undo:
return None
return self._undo[1]
def undo(self):
if self._undo[0] == 1:
return self._undoReview()
else:
self._undoOp()
def markReview(self, card):
old = []
if self._undo:
if self._undo[0] == 1:
old = self._undo[2]
self.clearUndo()
self._undo = [1, _("Review"), old + [copy.copy(card)]]
def _undoReview(self):
data = self._undo[2]
c = data.pop()
if not data:
self.clearUndo()
# write old data
c.flush()
# and delete revlog entry
last = self.db.scalar(
"select id from revlog where cid = ? "
"order by id desc limit 1", c.id)
self.db.execute("delete from revlog where id = ?", last)
# and finally, update daily counts
# fixme: what to do in cramming case?
type = ("new", "lrn", "rev")[c.queue]
self.sched._updateStats(c, type, -1)
return c.id
def _markOp(self, name):
"Call via .save()"
if name:
self._undo = [2, name]
else:
# saving disables old checkpoint, but not review undo
if self._undo and self._undo[0] == 2:
self.clearUndo()
def _undoOp(self):
self.rollback()
self.clearUndo()
# DB maintenance
##########################################################################
def fixIntegrity(self):
"Fix possible problems and rebuild caches."
problems = []
self.save()
oldSize = os.stat(self.path)[stat.ST_SIZE]
if self.db.scalar("pragma integrity_check") != "ok":
return _("Collection is corrupt. Please see the manual.")
# delete any notes with missing cards
ids = self.db.list("""
select id from notes where id not in (select distinct nid from cards)""")
self._remNotes(ids)
# tags
self.tags.registerNotes()
# field cache
for m in self.models.all():
self.updateFieldCache(self.models.nids(m))
# new card position
self.conf['nextPos'] = self.db.scalar(
"select max(due)+1 from cards where type = 0") or 0
# reviews should have a reasonable due #
ids = self.db.list(
"select id from cards where queue = 2 and due > 10000")
if ids:
problems.append("Reviews had incorrect due date.")
self.db.execute(
"update cards set due = 0, mod = ?, usn = ? where id in %s"
% ids2str(ids), intTime(), self.usn())
# and finally, optimize
self.optimize()
newSize = os.stat(self.path)[stat.ST_SIZE]
save = (oldSize - newSize)/1024
txt = _("Database rebuilt and optimized.")
if save > 0:
txt += "\n" + _("Saved %dKB.") % save
ok = not problems
problems.append(txt)
self.save()
return ("\n".join(problems), ok)
def optimize(self):
self.db.execute("vacuum")
self.db.execute("analyze")
self.lock()