Skip to content

Commit

Permalink
Feat/new fuzz range for overdue card (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Apr 26, 2024
1 parent 4ce1ff9 commit 86199dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions schedule/easy_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def easy_days(did):
recent=False,
filter_flag=True,
filtered_cids=set(due_in_easy_days_cids),
apply_easy_days=True,
)
if fut:
return fut.result()
Expand Down Expand Up @@ -158,6 +159,7 @@ def apply_easy_day_for_specific_date(self):
filter_flag=True,
filtered_cids=set(filtered_dues_cids),
easy_specific_due_dates=specific_dues,
apply_easy_days=True,
)


Expand Down
32 changes: 29 additions & 3 deletions schedule/reschedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FSRS:
card: Card
elapsed_days: int
allow_to_past: bool
apply_easy_days: bool

def __init__(self) -> None:
self.maximum_interval = 36500
Expand All @@ -35,6 +36,7 @@ def __init__(self) -> None:
self.p_obey_specific_due_dates = 1
self.elapsed_days = 0
self.allow_to_past = True
self.apply_easy_days = False

def set_load_balance(self):
self.enable_load_balance = True
Expand Down Expand Up @@ -81,6 +83,14 @@ def apply_fuzz(self, ivl):
else:
return int(self.fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl)
else:
if self.apply_easy_days:
last_review = get_last_review_date(self.card)
due = self.card.odue if self.card.odid else self.card.due
if due > last_review + max_ivl + 2:
current_ivl = due - last_review
min_ivl, max_ivl = get_fuzz_range(
current_ivl, self.elapsed_days, current_ivl
)
min_num_cards = math.inf
best_ivl = (max_ivl + min_ivl) // 2 if self.allow_to_past else max_ivl
step = (max_ivl - min_ivl) // 100 + 1
Expand Down Expand Up @@ -133,7 +143,12 @@ def set_card(self, card: Card):


def reschedule(
did, recent=False, filter_flag=False, filtered_cids={}, easy_specific_due_dates=[]
did,
recent=False,
filter_flag=False,
filtered_cids={},
easy_specific_due_dates=[],
apply_easy_days=False,
):
if not mw.col.get_config("fsrs"):
tooltip(FSRS_ENABLE_WARNING)
Expand All @@ -157,7 +172,12 @@ def on_done(future):

fut = mw.taskman.run_in_background(
lambda: reschedule_background(
did, recent, filter_flag, filtered_cids, easy_specific_due_dates
did,
recent,
filter_flag,
filtered_cids,
easy_specific_due_dates,
apply_easy_days,
),
on_done,
)
Expand All @@ -166,7 +186,12 @@ def on_done(future):


def reschedule_background(
did, recent=False, filter_flag=False, filtered_cids={}, easy_specific_due_dates=[]
did,
recent=False,
filter_flag=False,
filtered_cids={},
easy_specific_due_dates=[],
apply_easy_days=False,
):
config = Config()
config.load()
Expand All @@ -185,6 +210,7 @@ def reschedule_background(
)
if len(easy_specific_due_dates) > 0:
fsrs.allow_to_past = False
fsrs.apply_easy_days = apply_easy_days
DM = DeckManager(mw.col)
if did is not None:
did_list = ids2str(DM.deck_and_child_ids(did))
Expand Down

0 comments on commit 86199dd

Please sign in to comment.