mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
Merge branch 'master' of https://github.com/dae/anki
This commit is contained in:
commit
16f54c98dd
8 changed files with 39 additions and 20 deletions
|
@ -2,7 +2,9 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# 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:
|
if sys.version_info[0] > 2:
|
||||||
raise Exception("Anki should be run with Python 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.path.insert(0, os.path.join(ext, "py2.%d-%s" % (
|
||||||
sys.version_info[1], arch[0][0:2])))
|
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
|
from anki.storage import Collection
|
||||||
__all__ = ["Collection"]
|
__all__ = ["Collection"]
|
||||||
|
|
|
@ -205,11 +205,8 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
# Object creation helpers
|
# Object creation helpers
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def getCard(self, id, log=True):
|
def getCard(self, id):
|
||||||
c = anki.cards.Card(self, id)
|
return anki.cards.Card(self, id)
|
||||||
if log:
|
|
||||||
self.log(c, stack=1)
|
|
||||||
return c
|
|
||||||
|
|
||||||
def getNote(self, id):
|
def getNote(self, id):
|
||||||
return anki.notes.Note(self, id=id)
|
return anki.notes.Note(self, id=id)
|
||||||
|
|
|
@ -228,7 +228,7 @@ class MediaManager(object):
|
||||||
nfcFile = unicodedata.normalize("NFC", file)
|
nfcFile = unicodedata.normalize("NFC", file)
|
||||||
# we enforce NFC fs encoding on non-macs; on macs we'll have gotten
|
# we enforce NFC fs encoding on non-macs; on macs we'll have gotten
|
||||||
# NFD so we use the above variable for comparing references
|
# NFD so we use the above variable for comparing references
|
||||||
if not isMac and local:
|
if not isMac and not local:
|
||||||
if file != nfcFile:
|
if file != nfcFile:
|
||||||
# delete if we already have the NFC form, otherwise rename
|
# delete if we already have the NFC form, otherwise rename
|
||||||
if os.path.exists(nfcFile):
|
if os.path.exists(nfcFile):
|
||||||
|
|
|
@ -69,7 +69,7 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
|
||||||
return joinFields(self.fields)
|
return joinFields(self.fields)
|
||||||
|
|
||||||
def cards(self):
|
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)]
|
"select id from cards where nid = ? order by ord", self.id)]
|
||||||
|
|
||||||
def model(self):
|
def model(self):
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Scheduler(object):
|
||||||
self.queueLimit = 50
|
self.queueLimit = 50
|
||||||
self.reportLimit = 1000
|
self.reportLimit = 1000
|
||||||
self.reps = 0
|
self.reps = 0
|
||||||
|
self.today = None
|
||||||
self._haveQueues = False
|
self._haveQueues = False
|
||||||
self._updateCutoff()
|
self._updateCutoff()
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ class Scheduler(object):
|
||||||
self.reset()
|
self.reset()
|
||||||
card = self._getCard()
|
card = self._getCard()
|
||||||
if card:
|
if card:
|
||||||
|
self.col.log(card)
|
||||||
if not self._burySiblingsOnAnswer:
|
if not self._burySiblingsOnAnswer:
|
||||||
self._burySiblings(card)
|
self._burySiblings(card)
|
||||||
self.reps += 1
|
self.reps += 1
|
||||||
|
@ -47,7 +49,6 @@ class Scheduler(object):
|
||||||
return card
|
return card
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
deck = self.col.decks.current()
|
|
||||||
self._updateCutoff()
|
self._updateCutoff()
|
||||||
self._resetLrn()
|
self._resetLrn()
|
||||||
self._resetRev()
|
self._resetRev()
|
||||||
|
@ -361,14 +362,18 @@ did = ? and queue = 0 limit ?)""", did, lim)
|
||||||
if lim:
|
if lim:
|
||||||
# fill the queue with the current did
|
# fill the queue with the current did
|
||||||
self._newQueue = self.col.db.list("""
|
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:
|
if self._newQueue:
|
||||||
self._newQueue.reverse()
|
self._newQueue.reverse()
|
||||||
return True
|
return True
|
||||||
# nothing left in the deck; move to next
|
# nothing left in the deck; move to next
|
||||||
self._newDids.pop(0)
|
self._newDids.pop(0)
|
||||||
# if count>0 but queue empty, the other cards were buried
|
if self.newCount:
|
||||||
self.newCount = 0
|
# 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):
|
def _getNewCard(self):
|
||||||
if self._fillNew():
|
if self._fillNew():
|
||||||
|
@ -772,8 +777,12 @@ did = ? and queue = 2 and due <= ? limit ?""",
|
||||||
return True
|
return True
|
||||||
# nothing left in the deck; move to next
|
# nothing left in the deck; move to next
|
||||||
self._revDids.pop(0)
|
self._revDids.pop(0)
|
||||||
# if count>0 but queue empty, the other cards were buried
|
if self.revCount:
|
||||||
self.revCount = 0
|
# 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):
|
def _getRevCard(self):
|
||||||
if self._fillRev():
|
if self._fillRev():
|
||||||
|
@ -1118,11 +1127,13 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data)
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _updateCutoff(self):
|
def _updateCutoff(self):
|
||||||
|
oldToday = self.today
|
||||||
# days since col created
|
# days since col created
|
||||||
self.today = int((time.time() - self.col.crt) // 86400)
|
self.today = int((time.time() - self.col.crt) // 86400)
|
||||||
# end of day cutoff
|
# end of day cutoff
|
||||||
self.dayCutoff = self.col.crt + (self.today+1)*86400
|
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
|
# update all daily counts, but don't save decks to prevent needless
|
||||||
# conflicts. we'll save on card answer instead
|
# conflicts. we'll save on card answer instead
|
||||||
def update(g):
|
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):
|
def resetCards(self, ids):
|
||||||
"Completely reset cards for export."
|
"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(
|
nonNew = self.col.db.list(
|
||||||
"select id from cards where id in %s and (queue != 0 or type != 0)"
|
"select id from cards where id in %s and (queue != 0 or type != 0)"
|
||||||
% ids2str(ids))
|
% sids)
|
||||||
|
# reset all cards
|
||||||
self.col.db.execute(
|
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.forgetCards(nonNew)
|
||||||
self.col.log(ids)
|
self.col.log(ids)
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ group by day order by day""" % (self._limit(), lim),
|
||||||
perMin = ngettext("%d card/minute", "%d cards/minute", perMin) % perMin
|
perMin = ngettext("%d card/minute", "%d cards/minute", perMin) % perMin
|
||||||
self._line(
|
self._line(
|
||||||
i, _("Average answer time"),
|
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)
|
return self._lineTbl(i), int(tot)
|
||||||
|
|
||||||
def _splitRepData(self, data, spec):
|
def _splitRepData(self, data, spec):
|
||||||
|
|
|
@ -201,6 +201,9 @@ def run():
|
||||||
rd = os.path.abspath(moduleDir + "/../../..")
|
rd = os.path.abspath(moduleDir + "/../../..")
|
||||||
QCoreApplication.setLibraryPaths([rd])
|
QCoreApplication.setLibraryPaths([rd])
|
||||||
|
|
||||||
|
if isMac:
|
||||||
|
QFont.insertSubstitution(".Lucida Grande UI", "Lucida Grande")
|
||||||
|
|
||||||
# create the app
|
# create the app
|
||||||
app = AnkiApp(sys.argv)
|
app = AnkiApp(sys.argv)
|
||||||
QCoreApplication.setApplicationName("Anki")
|
QCoreApplication.setApplicationName("Anki")
|
||||||
|
|
|
@ -45,7 +45,7 @@ class DataModel(QAbstractTableModel):
|
||||||
def getCard(self, index):
|
def getCard(self, index):
|
||||||
id = self.cards[index.row()]
|
id = self.cards[index.row()]
|
||||||
if not id in self.cardObjs:
|
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]
|
return self.cardObjs[id]
|
||||||
|
|
||||||
def refreshNote(self, note):
|
def refreshNote(self, note):
|
||||||
|
|
Loading…
Reference in a new issue