Skip to content

Commit

Permalink
Disqualify cards not in review queue during review_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel committed May 27, 2020
1 parent c35a79f commit 5882e5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 9 additions & 13 deletions src/lib/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,15 @@ def calculate_ease_change(card: Card, reward: int, sett_min: int, sett_max: int)
def get_easeplus(col: _Collection, card: Card, straightlen: int) -> int:
sett = get_setting(col, card)

if (
sett.straight_length >= 1 and
straightlen >= sett.straight_length
):
# easeplus of 0 will be falsy
return calculate_ease_change(
card,
sett.base_ease + (straightlen - sett.straight_length) * sett.step_ease,
sett.start_ease,
sett.stop_ease,
)

return 0
# easeplus of 0 will be falsy
return 0 if (
sett.straight_length == 0 or straightlen < sett.straight_length
) else calculate_ease_change(
card,
sett.base_ease + (straightlen - sett.straight_length) * sett.step_ease,
sett.start_ease,
sett.stop_ease,
)

def get_straight_len(col: _Collection, card_id: int, skip: int = 0) -> int:
"""Returns the length of the current straight from revlog"""
Expand Down
8 changes: 5 additions & 3 deletions src/lib/review_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from aqt.utils import tooltip

from anki.hooks import card_will_flush
from anki.consts import BUTTON_THREE, BUTTON_FOUR
from anki.consts import CARD_TYPE_REV, REVLOG_REV
from anki.cards import Card

from .logic import get_straight_len, get_easeplus, notifications_enabled
from .logic import get_straight_len, get_easeplus, notifications_enabled, review_success

def display_success(straightlen: int, easeplus: int):
MSG = (
Expand All @@ -24,7 +24,9 @@ def review_hook_closure():
def check_straight_reward(ease_tuple: Tuple[bool, int], _reviewer, card) -> Tuple[bool, int]:
nonlocal gains

if ease_tuple[1] not in [BUTTON_THREE, BUTTON_FOUR]:
# check whether current review makes card qualify for straight reward
# CARD_TYPE_* does not match to REVLOG_*, because 3 is RELRN as card type, but CRAM as revlog
if card.type != CARD_TYPE_REV or not review_success((REVLOG_REV, ease_tuple[1])):
return ease_tuple

# check whether it is a filtered deck ("dynamic") which does not reschedule
Expand Down

0 comments on commit 5882e5d

Please sign in to comment.