Merge pull request #28 from MichaelBlume/future-division

use futuristic division
This commit is contained in:
Damien Elmes 2013-05-06 23:25:29 -07:00
commit e48a9f998b
4 changed files with 23 additions and 21 deletions

View File

@ -2,6 +2,7 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import division
import time, random, itertools
from operator import itemgetter
from heapq import *
@ -88,7 +89,7 @@ class Scheduler(object):
if card:
idx = self.countIdx(card)
if idx == 1:
counts[1] += card.left/1000
counts[1] += card.left // 1000
else:
counts[idx] += 1
return tuple(counts)
@ -368,7 +369,7 @@ select id, due from cards where did = ? and queue = 0 limit ?""", did, lim)
if self.col.conf['newSpread'] == NEW_CARDS_DISTRIBUTE:
if self.newCount:
self.newCardModulus = (
(self.newCount + self.revCount) / self.newCount)
(self.newCount + self.revCount) // self.newCount)
# if there are cards to review, ensure modulo >= 2
if self.revCount:
self.newCardModulus = max(2, self.newCardModulus)
@ -467,7 +468,7 @@ limit %d""" % (self._deckLimit(), self.reportLimit), lim=self.dayCutoff)
if self._lrnQueue[0][0] < cutoff:
id = heappop(self._lrnQueue)[1]
card = self.col.getCard(id)
self.lrnCount -= card.left/1000
self.lrnCount -= card.left // 1000
return card
# daily learning
@ -545,7 +546,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
card.due = int(time.time() + delay)
# due today?
if card.due < self.dayCutoff:
self.lrnCount += card.left/1000
self.lrnCount += card.left // 1000
# if the queue is not empty and there's nothing else to do, make
# sure we don't put it at the head of the queue and end up showing
# it twice in a row
@ -557,7 +558,7 @@ did = ? and queue = 3 and due <= ? limit ?""",
else:
# the card is due in one or more days, so we need to use the
# day learn queue
ahead = ((card.due - self.dayCutoff) / 86400) + 1
ahead = ((card.due - self.dayCutoff) // 86400) + 1
card.due = self.today + ahead
card.queue = 3
self._logLrn(card, ease, conf, leaving, type, lastLeft)
@ -811,12 +812,12 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
card.left = self._startingLeft(card)
# queue 1
if card.due < self.dayCutoff:
self.lrnCount += card.left/1000
self.lrnCount += card.left // 1000
card.queue = 1
heappush(self._lrnQueue, (card.due, card.id))
else:
# day learn queue
ahead = ((card.due - self.dayCutoff) / 86400) + 1
ahead = ((card.due - self.dayCutoff) // 86400) + 1
card.due = self.today + ahead
card.queue = 3
return delay
@ -860,9 +861,9 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
"Ideal next interval for CARD, given EASE."
delay = self._daysLate(card)
conf = self._revConf(card)
fct = card.factor / 1000.0
ivl2 = self._constrainedIvl((card.ivl + delay/4) * 1.2, conf, card.ivl)
ivl3 = self._constrainedIvl((card.ivl + delay/2) * fct, conf, ivl2)
fct = card.factor / 1000
ivl2 = self._constrainedIvl((card.ivl + delay // 4) * 1.2, conf, card.ivl)
ivl3 = self._constrainedIvl((card.ivl + delay // 2) * fct, conf, ivl2)
ivl4 = self._constrainedIvl(
(card.ivl + delay) * fct * conf['ease4'], conf, ivl3)
if ease == 2:
@ -1024,7 +1025,7 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data)
assert card.odid and card.type == 2
assert card.factor
elapsed = card.ivl - (card.odue - self.today)
factor = ((card.factor/1000.0)+1.2)/2.0
factor = ((card.factor/1000)+1.2)/2
ivl = int(max(card.ivl, elapsed * factor, 1))
conf = self._revConf(card)
return min(conf['maxIvl'], ivl)
@ -1039,7 +1040,7 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data)
return
# if over threshold or every half threshold reps after that
if (card.lapses >= lf and
(card.lapses-lf) % (max(lf/2, 1)) == 0):
(card.lapses-lf) % (max(lf // 2, 1)) == 0):
# add a leech tag
f = card.note()
f.addTag("leech")
@ -1124,7 +1125,7 @@ did = ?, queue = %s, due = ?, mod = ?, usn = ? where id = ?""" % queue, data)
def _updateCutoff(self):
# days since col created
self.today = int((time.time() - self.col.crt) / 86400)
self.today = (time.time() - self.col.crt) // 86400
# end of day cutoff
self.dayCutoff = self.col.crt + (self.today+1)*86400
# update all daily counts, but don't save decks to prevent needless

View File

@ -2,6 +2,7 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import division
import re, os, random, time, math, htmlentitydefs, subprocess, \
tempfile, shutil, string, httplib2, sys, locale
from hashlib import sha1
@ -90,15 +91,15 @@ def convertSecondsTo(seconds, type):
if type == "seconds":
return seconds
elif type == "minutes":
return seconds / 60.0
return seconds / 60
elif type == "hours":
return seconds / 3600.0
return seconds / 3600
elif type == "days":
return seconds / 86400.0
return seconds / 86400
elif type == "months":
return seconds / 2592000.0
return seconds / 2592000
elif type == "years":
return seconds / 31536000.0
return seconds / 31536000
assert False
def _pluralCount(time, point):

View File

@ -557,7 +557,7 @@ function showAnswer(txt) {
</script>
""" % dict(rem=self._remaining(), edit=_("Edit"),
editkey=_("Shortcut key: %s") % "E",
more=_("More"), time=self.card.timeTaken()/1000)
more=_("More"), time=self.card.timeTaken() // 1000)
def _showAnswerButton(self):
self._bottomReady = True

View File

@ -64,8 +64,8 @@ automatically."""))
self.mw.progress.update(label="%s\n%s" % (
self.label,
_("%(a)dkB up, %(b)dkB down") % dict(
a=self.sentBytes/1024,
b=self.recvBytes/1024)))
a=self.sentBytes // 1024,
b=self.recvBytes // 1024)))
def onEvent(self, evt, *args):
pu = self.mw.progress.update