Skip to content

Commit

Permalink
use a constant for the starting factor
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Feb 8, 2017
1 parent 18ccf26 commit 227ca09
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 2 additions & 0 deletions anki/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
MODEL_STD = 0
MODEL_CLOZE = 1

STARTING_FACTOR = 2500

# deck schema & syncing vars
SCHEMA_VERSION = 11
SYNC_ZIP_SIZE = int(2.5*1024*1024)
Expand Down
2 changes: 1 addition & 1 deletion anki/decks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'new': {
'delays': [1, 10],
'ints': [1, 4, 7], # 7 is not currently used
'initialFactor': 2500,
'initialFactor': STARTING_FACTOR,
'separate': True,
'order': NEW_CARDS_DUE,
'perDay': 20,
Expand Down
4 changes: 2 additions & 2 deletions anki/importing/noteimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

import cgi
from anki.consts import NEW_CARDS_RANDOM
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
from anki.lang import _
from anki.utils import fieldChecksum, guid64, timestampID, \
joinFields, intTime, splitFields
Expand All @@ -25,7 +25,7 @@ class ForeignCard(object):
def __init__(self):
self.due = 0
self.ivl = 1
self.factor = 2500
self.factor = STARTING_FACTOR
self.reps = 0
self.lapses = 0

Expand Down
4 changes: 2 additions & 2 deletions anki/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ def forgetCards(self, ids):
self.remFromDyn(ids)
self.col.db.execute(
"update cards set type=0,queue=0,ivl=0,due=0,odue=0,factor=?"
" where id in "+ids2str(ids), 2500)
" where id in "+ids2str(ids), STARTING_FACTOR)
pmax = self.col.db.scalar(
"select max(due) from cards where type=0") or 0
# takes care of mod + usn
Expand All @@ -1353,7 +1353,7 @@ def reschedCards(self, ids, imin, imax):
for id in ids:
r = random.randint(imin, imax)
d.append(dict(id=id, due=r+t, ivl=max(1, r), mod=mod,
usn=self.col.usn(), fact=2500))
usn=self.col.usn(), fact=STARTING_FACTOR))
self.remFromDyn(ids)
self.col.db.executemany("""
update cards set type=2,queue=2,ivl=:ivl,due=:due,odue=0,
Expand Down
19 changes: 10 additions & 9 deletions tests/test_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import copy

from anki.consts import STARTING_FACTOR
from tests.shared import getEmptyCol
from anki.utils import intTime
from anki.hooks import addHook
Expand Down Expand Up @@ -278,7 +279,7 @@ def test_reviews():
c.type = 2
c.queue = 2
c.due = d.sched.today - 8
c.factor = 2500
c.factor = STARTING_FACTOR
c.reps = 3
c.lapses = 1
c.ivl = 100
Expand Down Expand Up @@ -332,7 +333,7 @@ def test_reviews():
assert checkRevIvl(d, c, 260)
assert c.due == d.sched.today + c.ivl
# factor should have been left alone
assert c.factor == 2500
assert c.factor == STARTING_FACTOR
# ease 4
##################################################
c = copy.copy(cardcopy)
Expand Down Expand Up @@ -393,7 +394,7 @@ def test_overdue_lapse():
c.queue = 1
c.due = -1
c.odue = -1
c.factor = 2500
c.factor = STARTING_FACTOR
c.left = 2002
c.ivl = 0
c.flush()
Expand Down Expand Up @@ -467,15 +468,15 @@ def test_nextIvl():
##################################################
c.type = 2
c.ivl = 100
c.factor = 2500
c.factor = STARTING_FACTOR
assert ni(c, 1) == 60
assert ni(c, 2) == 100*86400
assert ni(c, 3) == 100*86400
# review cards
##################################################
c.queue = 2
c.ivl = 100
c.factor = 2500
c.factor = STARTING_FACTOR
# failing it should put it at 60s
assert ni(c, 1) == 60
# or 1 day if relearn is false
Expand Down Expand Up @@ -557,7 +558,7 @@ def test_cram():
# due in 25 days, so it's been waiting 75 days
c.due = d.sched.today + 25
c.mod = 1
c.factor = 2500
c.factor = STARTING_FACTOR
c.startTimer()
c.flush()
d.reset()
Expand Down Expand Up @@ -699,7 +700,7 @@ def test_cram_resched():
c.ivl = 100
c.type = c.queue = 2
c.due = d.sched.today + 25
c.factor = 2500
c.factor = STARTING_FACTOR
c.flush()
cardcopy = copy.copy(c)
d.sched.rebuildDyn(did)
Expand Down Expand Up @@ -1078,7 +1079,7 @@ def test_norelearn():
c.type = 2
c.queue = 2
c.due = 0
c.factor = 2500
c.factor = STARTING_FACTOR
c.reps = 3
c.lapses = 1
c.ivl = 100
Expand All @@ -1099,7 +1100,7 @@ def test_failmult():
c.queue = 2
c.ivl = 100
c.due = d.sched.today - c.ivl
c.factor = 2500
c.factor = STARTING_FACTOR
c.reps = 3
c.lapses = 1
c.startTimer()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from anki import Collection as aopen, Collection
from anki.utils import intTime
from anki.sync import Syncer, LocalServer
from anki.consts import STARTING_FACTOR
from tests.shared import getEmptyCol, getEmptyDeckWith

# Local tests
Expand Down Expand Up @@ -343,7 +344,7 @@ def test_filtered_delete():
card = note.cards()[0]
card.type = 2
card.ivl = 10
card.factor = 2500
card.factor = STARTING_FACTOR
card.due = deck1.sched.today
card.flush()
# put cards into a filtered deck
Expand Down

0 comments on commit 227ca09

Please sign in to comment.