This commit is contained in:
Soren I. Bjornstad 2013-11-01 08:10:10 -05:00
commit 16f54c98dd
8 changed files with 39 additions and 20 deletions

View File

@ -2,7 +2,9 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import sys, os, platform
import sys
import os
import platform
if sys.version_info[0] > 2:
raise Exception("Anki should be run with Python 2")
@ -28,6 +30,6 @@ if arch[1] == "ELF":
sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % (
sys.version_info[1], arch[0][0:2])))
version="2.0.15" # build scripts grep this line, so preserve formatting
version="2.0.16" # build scripts grep this line, so preserve formatting
from anki.storage import Collection
__all__ = ["Collection"]

View File

@ -205,11 +205,8 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
# Object creation helpers
##########################################################################
def getCard(self, id, log=True):
c = anki.cards.Card(self, id)
if log:
self.log(c, stack=1)
return c
def getCard(self, id):
return anki.cards.Card(self, id)
def getNote(self, id):
return anki.notes.Note(self, id=id)

View File

@ -228,7 +228,7 @@ class MediaManager(object):
nfcFile = unicodedata.normalize("NFC", file)
# we enforce NFC fs encoding on non-macs; on macs we'll have gotten
# NFD so we use the above variable for comparing references
if not isMac and local:
if not isMac and not local:
if file != nfcFile:
# delete if we already have the NFC form, otherwise rename
if os.path.exists(nfcFile):

View File

@ -69,7 +69,7 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
return joinFields(self.fields)
def cards(self):
return [self.col.getCard(id, log=False) for id in self.col.db.list(
return [self.col.getCard(id) for id in self.col.db.list(
"select id from cards where nid = ? order by ord", self.id)]
def model(self):

View File

@ -30,6 +30,7 @@ class Scheduler(object):
self.queueLimit = 50
self.reportLimit = 1000
self.reps = 0
self.today = None
self._haveQueues = False
self._updateCutoff()
@ -40,6 +41,7 @@ class Scheduler(object):
self.reset()
card = self._getCard()
if card:
self.col.log(card)
if not self._burySiblingsOnAnswer:
self._burySiblings(card)
self.reps += 1
@ -47,7 +49,6 @@ class Scheduler(object):
return card
def reset(self):
deck = self.col.decks.current()
self._updateCutoff()
self._resetLrn()
self._resetRev()
@ -361,14 +362,18 @@ did = ? and queue = 0 limit ?)""", did, lim)
if lim:
# fill the queue with the current did
self._newQueue = self.col.db.list("""
select id from cards where did = ? and queue = 0 limit ?""", did, lim)
select id from cards where did = ? and queue = 0 order by due limit ?""", did, lim)
if self._newQueue:
self._newQueue.reverse()
return True
# nothing left in the deck; move to next
self._newDids.pop(0)
# if count>0 but queue empty, the other cards were buried
self.newCount = 0
if self.newCount:
# if we didn't get a card but the count is non-zero,
# we need to check again for any cards that were
# removed from the queue but not buried
self._resetNew()
return self._fillNew()
def _getNewCard(self):
if self._fillNew():
@ -772,8 +777,12 @@ did = ? and queue = 2 and due <= ? limit ?""",
return True
# nothing left in the deck; move to next
self._revDids.pop(0)
# if count>0 but queue empty, the other cards were buried
self.revCount = 0
if self.revCount:
# if we didn't get a card but the count is non-zero,
# we need to check again for any cards that were
# removed from the queue but not buried
self._resetRev()
return self._fillRev()
def _getRevCard(self):
if self._fillRev():
@ -1118,11 +1127,13 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data)
##########################################################################
def _updateCutoff(self):
oldToday = self.today
# days since col created
self.today = int((time.time() - self.col.crt) // 86400)
# end of day cutoff
self.dayCutoff = self.col.crt + (self.today+1)*86400
self.col.log(self.today, self.dayCutoff)
if oldToday != self.today:
self.col.log(self.today, self.dayCutoff)
# update all daily counts, but don't save decks to prevent needless
# conflicts. we'll save on card answer instead
def update(g):
@ -1348,11 +1359,17 @@ usn=:usn, mod=:mod, factor=:fact where id=:id and odid=0 and queue >=0""",
def resetCards(self, ids):
"Completely reset cards for export."
sids = ids2str(ids)
# we want to avoid resetting due number of existing new cards on export
nonNew = self.col.db.list(
"select id from cards where id in %s and (queue != 0 or type != 0)"
% ids2str(ids))
% sids)
# reset all cards
self.col.db.execute(
"update cards set reps=0, lapses=0 where id in " + ids2str(nonNew))
"update cards set reps=0,lapses=0,odid=0,odue=0"
" where id in %s" % sids
)
# and forget any non-new cards, changing their due numbers
self.forgetCards(nonNew)
self.col.log(ids)

View File

@ -356,7 +356,7 @@ group by day order by day""" % (self._limit(), lim),
perMin = ngettext("%d card/minute", "%d cards/minute", perMin) % perMin
self._line(
i, _("Average answer time"),
"%0.1fs (%s)" % ((tot*60)/total, perMin))
_("%(a)0.1fs (%(b)s)") % dict(a=(tot*60)/total, b=perMin))
return self._lineTbl(i), int(tot)
def _splitRepData(self, data, spec):

View File

@ -201,6 +201,9 @@ def run():
rd = os.path.abspath(moduleDir + "/../../..")
QCoreApplication.setLibraryPaths([rd])
if isMac:
QFont.insertSubstitution(".Lucida Grande UI", "Lucida Grande")
# create the app
app = AnkiApp(sys.argv)
QCoreApplication.setApplicationName("Anki")

View File

@ -45,7 +45,7 @@ class DataModel(QAbstractTableModel):
def getCard(self, index):
id = self.cards[index.row()]
if not id in self.cardObjs:
self.cardObjs[id] = self.col.getCard(id, log=False)
self.cardObjs[id] = self.col.getCard(id)
return self.cardObjs[id]
def refreshNote(self, note):