rename some columns for consistency

- revlog's 'time' is now 'id', like the other tables
- 'taken' is now 'time'
- also dropped the eta code
This commit is contained in:
Damien Elmes 2011-09-06 21:33:19 +09:00
parent b3937a3280
commit 9130e09b3e
6 changed files with 23 additions and 55 deletions

View file

@ -563,9 +563,9 @@ where c.fid == f.id
c.flush()
# and delete revlog entry
last = self.db.scalar(
"select time from revlog where cid = ? "
"order by time desc limit 1", c.id)
self.db.execute("delete from revlog where time = ?", last)
"select id from revlog where cid = ? "
"order by id desc limit 1", c.id)
self.db.execute("delete from revlog where id = ?", last)
def _markOp(self, name):
"Call via .save()"

View file

@ -95,26 +95,6 @@ order by due""" % self._groupLimit(),
self.deck.db.execute(
"update cards set queue = type where queue between -3 and -2")
def etaStr(self):
eta = self.eta()
if not eta:
return ""
return fmtTimeSpan(eta)
def eta(self):
"A very rough estimate of time to review."
(cnt, sum) = self.deck.db.first("""
select count(), sum(taken) from (select * from revlog
order by time desc limit 10)""")
if not cnt:
return 0
avg = sum / float(cnt)
c = self.counts()
# Here we just assume new/lrn will require 3x the number of reviews.
# To improve on this we'll need to make grade count down so we can get
# a decent picture of required steps.
return (avg*c[0]*3 + avg*c[1]*3 + avg*c[2]) / 1000.0
# Counts
##########################################################################
@ -745,13 +725,13 @@ queue = 2 %s and due <= :lim order by %s limit %d""" % (
def timeToday(self):
"Time spent learning today, in seconds."
return self.deck.db.scalar(
"select sum(taken/1000.0) from revlog where time > ?*1000",
"select sum(time/1000.0) from revlog where id > ?*1000",
self.dayCutoff-86400) or 0
def repsToday(self):
"Number of cards answered today."
return self.deck.db.scalar(
"select count() from revlog where time > ?*1000",
"select count() from revlog where id > ?*1000",
self.dayCutoff-86400)
# Dynamic indices

View file

@ -24,9 +24,9 @@ class CardStats(object):
self.txt = "<table width=100%%>"
self.addLine(_("Added"), self.date(c.id/1000))
first = self.deck.db.scalar(
"select min(time) from revlog where cid = ?", c.id)
"select min(id) from revlog where cid = ?", c.id)
last = self.deck.db.scalar(
"select max(time) from revlog where cid = ?", c.id)
"select max(id) from revlog where cid = ?", c.id)
if first:
self.addLine(_("First Review"), self.date(first/1000))
self.addLine(_("Latest Review"), self.date(last/1000))
@ -40,7 +40,7 @@ class CardStats(object):
self.addLine(_("Interval"), fmt(c.ivl * 86400))
self.addLine(_("Ease"), "%d%%" % (c.factor/10.0))
(cnt, total) = self.deck.db.first(
"select count(), sum(taken)/1000 from revlog where cid = :id",
"select count(), sum(time)/1000 from revlog where cid = :id",
id=c.id)
if cnt:
self.addLine(_("Average Time"), self.time(total / float(cnt)))
@ -303,7 +303,7 @@ group by day order by day""" % (self._limit(), lim),
def _done(self, num=7, chunk=1):
lims = []
if num is not None:
lims.append("time > %d" % (
lims.append("id > %d" % (
(self.deck.sched.dayCutoff-(num*chunk*86400))*1000))
lim = self._revlogLimit()
if lim:
@ -318,18 +318,18 @@ group by day order by day""" % (self._limit(), lim),
tf = 3600.0 # hours
return self.deck.db.all("""
select
(cast((time/1000 - :cut) / 86400.0 as int))/:chunk as day,
(cast((id/1000 - :cut) / 86400.0 as int))/:chunk as day,
sum(case when type = 0 then 1 else 0 end), -- lrn count
sum(case when type = 1 and lastIvl < 21 then 1 else 0 end), -- yng count
sum(case when type = 1 and lastIvl >= 21 then 1 else 0 end), -- mtr count
sum(case when type = 2 then 1 else 0 end), -- lapse count
sum(case when type = 3 then 1 else 0 end), -- cram count
sum(case when type = 0 then taken/1000 else 0 end)/:tf, -- lrn time
sum(case when type = 0 then time/1000 else 0 end)/:tf, -- lrn time
-- yng + mtr time
sum(case when type = 1 and lastIvl < 21 then taken/1000 else 0 end)/:tf,
sum(case when type = 1 and lastIvl >= 21 then taken/1000 else 0 end)/:tf,
sum(case when type = 2 then taken/1000 else 0 end)/:tf, -- lapse time
sum(case when type = 3 then taken/1000 else 0 end)/:tf -- cram time
sum(case when type = 1 and lastIvl < 21 then time/1000 else 0 end)/:tf,
sum(case when type = 1 and lastIvl >= 21 then time/1000 else 0 end)/:tf,
sum(case when type = 2 then time/1000 else 0 end)/:tf, -- lapse time
sum(case when type = 3 then time/1000 else 0 end)/:tf -- cram time
from revlog %s
group by day order by day""" % lim,
cut=self.deck.sched.dayCutoff,
@ -341,7 +341,7 @@ group by day order by day""" % lim,
num = self._periodDays()
if num:
lims.append(
"time > %d" %
"id > %d" %
((self.deck.sched.dayCutoff-(num*86400))*1000))
rlim = self._revlogLimit()
if rlim:
@ -352,7 +352,7 @@ group by day order by day""" % lim,
lim = ""
return self.deck.db.first("""
select count(), abs(min(day)) from (select
(cast((time/1000 - :cut) / 86400.0 as int)+1) as day
(cast((id/1000 - :cut) / 86400.0 as int)+1) as day
from revlog %s
group by day order by day)""" % lim,
cut=self.deck.sched.dayCutoff)
@ -515,7 +515,7 @@ order by thetype, ease""" % lim)
sd = datetime.datetime.fromtimestamp(self.deck.crt)
return self.deck.db.all("""
select
23 - ((cast((:cut - time/1000) / 3600.0 as int)) %% 24) as hour,
23 - ((cast((:cut - id/1000) / 3600.0 as int)) %% 24) as hour,
sum(case when ease = 1 then 0 else 1 end) /
cast(count() as float) * 100,
count()

View file

@ -109,19 +109,19 @@ create table if not exists fsums (
);
create table if not exists graves (
time integer not null,
id integer not null,
oid integer not null,
type integer not null
);
create table if not exists revlog (
time integer primary key,
id integer primary key,
cid integer not null,
ease integer not null,
ivl integer not null,
lastIvl integer not null,
factor integer not null,
taken integer not null,
time integer not null,
type integer not null
);

View file

@ -178,7 +178,7 @@ class Syncer(object):
"select * from facts where mod > ?"),
# the rest
("models", "select * from models where mod > ?"),
("revlog", "select * from revlog where time > ?*1000"),
("revlog", "select * from revlog where id > ?*1000"),
("tags", "select * from tags where mod > ?"),
("gconf", "select * from gconf where mod > ?"),
("groups", "select * from groups where mod > ?"),

View file

@ -114,7 +114,7 @@ def test_learn():
assert c.grade == 1
assert c.cycles == 2
# check log is accurate
log = d.db.first("select * from revlog order by time desc")
log = d.db.first("select * from revlog order by id desc")
assert log[2] == 2
assert log[3] == -180
assert log[4] == -30
@ -793,15 +793,3 @@ def test_resched():
c.load()
assert c.due == d.sched.today+1
assert c.ivl == +1
def test_eta():
d = getEmptyDeck()
f = d.newFact()
f['Front'] = u"one"
d.addFact(f)
d.reset()
c = d.sched.getCard()
time.sleep(0.1)
d.sched.answerCard(c, 1)
time.sleep(0.1)
d.sched.answerCard(c, 1)