From 4387e3ed86df6681f18e87ef320c988d099b283e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 1 Mar 2021 21:47:44 +1000 Subject: [PATCH] fix reps updating in v2, but do it in answerCard instead of getCard --- pylib/anki/collection.py | 10 ++++++++-- pylib/anki/sched.py | 1 + pylib/anki/scheduler.py | 4 +--- pylib/anki/schedv2.py | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index e6fbd759a..914c46809 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -702,13 +702,19 @@ table.review-log {{ {revlog_style} }} # Timeboxing ########################################################################## + # fixme: there doesn't seem to be a good reason why this code is in main.py + # instead of covered in reviewer, and the reps tracking is covered by both + # the scheduler and reviewer.py. in the future, we should probably move + # reps tracking to reviewer.py, and remove the startTimebox() calls from + # other locations like overview.py. We just need to make sure not to reset + # the count on things like edits, which we probably could do by checking + # the previous state in moveToState. def startTimebox(self) -> None: self._startTime = time.time() self._startReps = self.sched.reps - # FIXME: Use Literal[False] when on Python 3.8 - def timeboxReached(self) -> Union[bool, Tuple[Any, int]]: + def timeboxReached(self) -> Union[Literal[False], Tuple[Any, int]]: "Return (elapsedTime, reps) if timebox reached, or False." if not self.conf["timeLim"]: # timeboxing disabled diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index 7e98e9c6e..3b4ceada1 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -49,6 +49,7 @@ class Scheduler(V2): if self._burySiblingsOnAnswer: self._burySiblings(card) card.reps += 1 + self.reps += 1 # former is for logging new cards, latter also covers filt. decks card.wasNew = card.type == CARD_TYPE_NEW # type: ignore wasNewQ = card.queue == QUEUE_TYPE_NEW diff --git a/pylib/anki/scheduler.py b/pylib/anki/scheduler.py index 5ec1fde1c..c35e17970 100644 --- a/pylib/anki/scheduler.py +++ b/pylib/anki/scheduler.py @@ -28,7 +28,6 @@ UnburyCurrentDeck = _pb.UnburyCardsInCurrentDeckIn BuryOrSuspend = _pb.BuryOrSuspendCardsIn # fixme: reviewer.cardQueue/editCurrent/undo handling/retaining current card -# fixme: .reps class Scheduler: @@ -36,8 +35,7 @@ class Scheduler: def __init__(self, col: anki.collection.Collection) -> None: self.col = col.weakref() - # fixme: only used by the timeboxing code, and was double-incremented - # for ages - just move to gui? + # don't rely on this, it will likely be removed out in the future self.reps = 0 # Timing diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 46c740563..1c141c757 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -489,6 +489,7 @@ limit ?""" self._answerCardPreview(card, ease) return + self.reps += 1 card.reps += 1 new_delta = 0