From dca1cd03d1e6467471ce7096b2091638193cae6f Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Thu, 30 Jan 2020 18:03:11 -0800 Subject: [PATCH] REVLOG_LRN --- pylib/anki/consts.py | 1 + pylib/anki/sched.py | 2 +- pylib/anki/schedv2.py | 2 +- pylib/anki/stats.py | 21 +++++++++++---------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pylib/anki/consts.py b/pylib/anki/consts.py index bbb2bfae2..001bf7a46 100644 --- a/pylib/anki/consts.py +++ b/pylib/anki/consts.py @@ -70,6 +70,7 @@ BUTTON_THREE = 3 BUTTON_FOUR = 4 # Revlog types +REVLOG_LRN = 0 # Labels ########################################################################## diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index 1d8c1b6d8..530368875 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -560,7 +560,7 @@ did = ? and queue = 3 and due <= ? limit ?""", elif card.type == 2: type = 2 else: - type = 0 + type = REVLOG_LRN leaving = False # lrnCount was decremented once when card was fetched lastLeft = card.left diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 60073125d..6b11a5e5a 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -610,7 +610,7 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""", if card.type in (2, CARD_TYPE_RELEARNING): type = 2 else: - type = 0 + type = REVLOG_LRN # lrnCount was decremented once when card was fetched lastLeft = card.left diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index 50a4ccf7c..b2a6f8bd9 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -6,6 +6,7 @@ import json import time from typing import Any, Dict, List, Optional, Tuple +from anki.consts import * from anki.lang import _, ngettext from anki.utils import fmtTimeSpan, ids2str @@ -149,10 +150,10 @@ body {background-image: url(data:image/png;base64,%s); } if lim: lim = " and " + lim cards, thetime, failed, lrn, rev, relrn, filt = self.col.db.first( - """ + f""" select count(), sum(time)/1000, sum(case when ease = 1 then 1 else 0 end), /* failed */ -sum(case when type = 0 then 1 else 0 end), /* learning */ +sum(case when type = {REVLOG_LRN} then 1 else 0 end), /* learning */ sum(case when type = 1 then 1 else 0 end), /* review */ sum(case when type = 2 then 1 else 0 end), /* relearn */ sum(case when type = 3 then 1 else 0 end) /* filter */ @@ -544,15 +545,15 @@ group by day order by day""" else: tf = 3600.0 # hours return self.col.db.all( - """ + f""" select (cast((id/1000.0 - :cut) / 86400.0 as int))/:chunk as day, -sum(case when type = 0 then 1 else 0 end), -- lrn count +sum(case when type = {REVLOG_LRN} 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 time/1000.0 else 0 end)/:tf, -- lrn time +sum(case when type = {REVLOG_LRN} then time/1000.0 else 0 end)/:tf, -- lrn time -- yng + mtr time sum(case when type = 1 and lastIvl < 21 then time/1000.0 else 0 end)/:tf, sum(case when type = 1 and lastIvl >= 21 then time/1000.0 else 0 end)/:tf, @@ -755,12 +756,12 @@ select count(), avg(ivl), max(ivl) from cards where did in %s and queue = 2""" else: ease4repl = "ease" return self.col.db.all( - """ + f""" select (case -when type in (0,2) then 0 +when type in ({REVLOG_LRN},2) then 0 when lastIvl < 21 then 1 else 2 end) as thetype, -(case when type in (0,2) and ease = 4 then %s else ease end), count() from revlog %s +(case when type in ({REVLOG_LRN},2) and ease = 4 then %s else ease end), count() from revlog %s group by thetype, ease order by thetype, ease""" % (ease4repl, lim) @@ -849,13 +850,13 @@ order by thetype, ease""" if pd: lim += " and id > %d" % ((self.col.sched.dayCutoff - (86400 * pd)) * 1000) return self.col.db.all( - """ + f""" select 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() -from revlog where type in (0,1,2) %s +from revlog where type in ({REVLOG_LRN},1,2) %s group by hour having count() > 30 order by hour""" % lim, cut=self.col.sched.dayCutoff - (rolloverHour * 3600),