mirror of
https://github.com/ankitects/anki.git
synced 2025-12-12 22:36:55 -05:00
new order is now a deck property
This commit is contained in:
parent
1e48ce9b99
commit
4428c04774
6 changed files with 29 additions and 31 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
# 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 time, os, random, re, stat, simplejson, datetime, copy, shutil
|
import time, os, random, re, stat, simplejson, datetime, copy, shutil, sys
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
from anki.utils import ids2str, hexifyID, checksum, fieldChecksum, stripHTML, \
|
from anki.utils import ids2str, hexifyID, checksum, fieldChecksum, stripHTML, \
|
||||||
intTime, splitFields, joinFields, maxID
|
intTime, splitFields, joinFields, maxID
|
||||||
|
|
@ -252,11 +252,8 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
if not cms:
|
if not cms:
|
||||||
return 0
|
return 0
|
||||||
note.flush()
|
note.flush()
|
||||||
# randomize?
|
# deck conf governs which of these are used
|
||||||
if self.models.randomNew():
|
due = self.nextID("pos")
|
||||||
due = self._randPos()
|
|
||||||
else:
|
|
||||||
due = self.nextID("pos")
|
|
||||||
# add cards
|
# add cards
|
||||||
ncards = 0
|
ncards = 0
|
||||||
for template in cms:
|
for template in cms:
|
||||||
|
|
@ -264,9 +261,6 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
ncards += 1
|
ncards += 1
|
||||||
return ncards
|
return ncards
|
||||||
|
|
||||||
def _randPos(self):
|
|
||||||
return random.randrange(1, sys.maxint)
|
|
||||||
|
|
||||||
def remNotes(self, ids):
|
def remNotes(self, ids):
|
||||||
self.remCards(self.db.list("select id from cards where nid in "+
|
self.remCards(self.db.list("select id from cards where nid in "+
|
||||||
ids2str(ids)))
|
ids2str(ids)))
|
||||||
|
|
@ -347,11 +341,23 @@ insert into cards values (?,?,?,?,?,-1,0,0,?,0,0,0,0,0,0,0,"")""",
|
||||||
card.nid = note.id
|
card.nid = note.id
|
||||||
card.ord = template['ord']
|
card.ord = template['ord']
|
||||||
card.did = template['did'] or note.did
|
card.did = template['did'] or note.did
|
||||||
card.due = due
|
card.due = self._dueForDid(card.did, due)
|
||||||
if flush:
|
if flush:
|
||||||
card.flush()
|
card.flush()
|
||||||
return card
|
return card
|
||||||
|
|
||||||
|
def _dueForDid(self, did, due):
|
||||||
|
conf = self.decks.conf(did)
|
||||||
|
# in order due?
|
||||||
|
if conf['new']['order']:
|
||||||
|
return due
|
||||||
|
else:
|
||||||
|
# random mode; seed with note ts so all cards of this note get the
|
||||||
|
# same random number
|
||||||
|
r = random.Random()
|
||||||
|
r.seed(due)
|
||||||
|
return r.randrange(1, 2**32-1)
|
||||||
|
|
||||||
# Cards
|
# Cards
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,6 @@ NEW_CARDS_FIRST = 2
|
||||||
NEW_CARDS_RANDOM = 0
|
NEW_CARDS_RANDOM = 0
|
||||||
NEW_CARDS_DUE = 1
|
NEW_CARDS_DUE = 1
|
||||||
|
|
||||||
# sort order for day's new cards
|
|
||||||
NEW_TODAY_ORD = 0
|
|
||||||
NEW_TODAY_DUE = 1
|
|
||||||
|
|
||||||
# review card sort order
|
# review card sort order
|
||||||
REV_CARDS_RANDOM = 0
|
REV_CARDS_RANDOM = 0
|
||||||
REV_CARDS_OLD_FIRST = 1
|
REV_CARDS_OLD_FIRST = 1
|
||||||
|
|
@ -64,9 +60,9 @@ def newCardSchedulingLabels():
|
||||||
|
|
||||||
def revCardOrderLabels():
|
def revCardOrderLabels():
|
||||||
return {
|
return {
|
||||||
0: _("Review cards in date due order"),
|
0: _("Sort by due date"),
|
||||||
1: _("Review cards from largest interval"),
|
1: _("Sort by decreasing interval (slower)"),
|
||||||
2: _("Review cards from smallest interval"),
|
2: _("Sort by increasing interval (slower)"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def alignmentLabels():
|
def alignmentLabels():
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ defaultConf = {
|
||||||
'delays': [1, 10],
|
'delays': [1, 10],
|
||||||
'ints': [1, 4, 7], # 7 is not currently used
|
'ints': [1, 4, 7], # 7 is not currently used
|
||||||
'initialFactor': 2500,
|
'initialFactor': 2500,
|
||||||
'order': NEW_TODAY_ORD,
|
'separate': True,
|
||||||
|
'order': NEW_CARDS_DUE,
|
||||||
'perDay': 20,
|
'perDay': 20,
|
||||||
},
|
},
|
||||||
'lapse': {
|
'lapse': {
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,9 @@ defaultModel = {
|
||||||
'sortf': 0,
|
'sortf': 0,
|
||||||
'did': 1,
|
'did': 1,
|
||||||
'clozectx': False,
|
'clozectx': False,
|
||||||
'newOrder': NEW_CARDS_DUE,
|
|
||||||
'latexPre': """\
|
'latexPre': """\
|
||||||
\\documentclass[12pt]{article}
|
\\documentclass[12pt]{article}
|
||||||
\\special{papersize=3in,5in}
|
\\special{papersize=3in,5in}
|
||||||
% \\usepackage[utf8x]{inputenc} % uncomment this for foreign characters
|
|
||||||
\\usepackage{amssymb,amsmath}
|
\\usepackage{amssymb,amsmath}
|
||||||
\\pagestyle{empty}
|
\\pagestyle{empty}
|
||||||
\\setlength{\\parindent}{0in}
|
\\setlength{\\parindent}{0in}
|
||||||
|
|
@ -172,9 +170,6 @@ select id from cards where nid in (select id from notes where mid = ?)""",
|
||||||
return self.col.db.scalar(
|
return self.col.db.scalar(
|
||||||
"select count() from notes where mid = ?", m['id'])
|
"select count() from notes where mid = ?", m['id'])
|
||||||
|
|
||||||
def randomNew(self):
|
|
||||||
return self.current()['newOrder'] == NEW_CARDS_RANDOM
|
|
||||||
|
|
||||||
# Copying
|
# Copying
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ select id, due from cards where did = ? and queue = 0 limit ?""", did, lim)
|
||||||
(id, due) = self._newQueue.pop()
|
(id, due) = self._newQueue.pop()
|
||||||
# move any siblings to the end?
|
# move any siblings to the end?
|
||||||
conf = self.col.decks.conf(self._newDids[0])
|
conf = self.col.decks.conf(self._newDids[0])
|
||||||
if conf['new']['order'] == NEW_TODAY_ORD:
|
if conf['new']['separate']:
|
||||||
n = len(self._newQueue)
|
n = len(self._newQueue)
|
||||||
while self._newQueue and self._newQueue[-1][1] == due:
|
while self._newQueue and self._newQueue[-1][1] == due:
|
||||||
self._newQueue.insert(0, self._newQueue.pop())
|
self._newQueue.insert(0, self._newQueue.pop())
|
||||||
|
|
@ -823,7 +823,7 @@ your short-term review workload will become."""))
|
||||||
"update cards set type=0,queue=0,ivl=0 where id in "+ids2str(ids))
|
"update cards set type=0,queue=0,ivl=0 where id in "+ids2str(ids))
|
||||||
pmax = self.col.db.scalar("select max(due) from cards where type=0")
|
pmax = self.col.db.scalar("select max(due) from cards where type=0")
|
||||||
# takes care of mod + usn
|
# takes care of mod + usn
|
||||||
self.sortCards(ids, start=pmax+1, shuffle=self.col.models.randomNew())
|
self.sortCards(ids, start=pmax+1)
|
||||||
|
|
||||||
def reschedCards(self, ids, imin, imax):
|
def reschedCards(self, ids, imin, imax):
|
||||||
"Put cards in review queue with a new interval in days (min, max)."
|
"Put cards in review queue with a new interval in days (min, max)."
|
||||||
|
|
|
||||||
|
|
@ -578,11 +578,6 @@ and ord = ? limit 1""", m['id'], t['ord']):
|
||||||
self._rewriteMediaRefs()
|
self._rewriteMediaRefs()
|
||||||
# template handling has changed
|
# template handling has changed
|
||||||
self._upgradeTemplates()
|
self._upgradeTemplates()
|
||||||
# set new card order
|
|
||||||
for m in col.models.all():
|
|
||||||
m['newOrder'] = col.conf['oldNewOrder']
|
|
||||||
col.models.save(m)
|
|
||||||
del col.conf['oldNewOrder']
|
|
||||||
# fix creation time
|
# fix creation time
|
||||||
col.sched._updateCutoff()
|
col.sched._updateCutoff()
|
||||||
d = datetime.datetime.today()
|
d = datetime.datetime.today()
|
||||||
|
|
@ -621,8 +616,13 @@ update cards set due = cast(
|
||||||
(case when due < :stamp then 0 else 1 end) +
|
(case when due < :stamp then 0 else 1 end) +
|
||||||
((due-:stamp)/86400) as int)+:today where type = 2
|
((due-:stamp)/86400) as int)+:today where type = 2
|
||||||
""", stamp=col.sched.dayCutoff, today=col.sched.today)
|
""", stamp=col.sched.dayCutoff, today=col.sched.today)
|
||||||
|
# set new card order
|
||||||
|
conf = col.decks.allConf()[0]
|
||||||
|
conf['new']['order'] = col.conf['oldNewOrder']
|
||||||
|
col.decks.save(conf)
|
||||||
|
del col.conf['oldNewOrder']
|
||||||
# possibly re-randomize
|
# possibly re-randomize
|
||||||
if col.models.randomNew():
|
if not conf['new']['order']:
|
||||||
col.sched.randomizeCards(1)
|
col.sched.randomizeCards(1)
|
||||||
# update insertion id
|
# update insertion id
|
||||||
col.conf['nextPos'] = (
|
col.conf['nextPos'] = (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue