Skip to content

Commit

Permalink
Feat/option to skip manually rescheduled cards
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed Aug 14, 2024
1 parent 75ce5c7 commit 5b27518
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
29 changes: 28 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aqt.gui_hooks import deck_browser_will_show_options_menu, state_did_change
from aqt import mw
from aqt.qt import QAction
from aqt.utils import tooltip, openLink
from aqt.utils import tooltip, openLink, askUser
from typing import Callable

from .dsr_state import init_dsr_status_hook
Expand Down Expand Up @@ -107,6 +107,31 @@ def set_auto_disperse_after_reschedule(checked, _):
)


def set_skip_manual_resched_cards(checked, _):
if config.skip_manual_resched_cards:
config.skip_manual_resched_cards = checked
else:
warning = (
"Due to technical limitations, FSRS Helper cannot distinguish among cards rescheduled by following operations:\n"
+ "- Set due date\n"
+ "- Reset (original Forget)\n"
+ "- Reschedule cards on change\n\n"
+ 'When you enable this option, all cards whose the latest review log\'s type is marked as "Manual" will be skipped during rescheduling.'
)
checked = askUser(
warning,
title="Warning",
)
config.skip_manual_resched_cards = checked
menu_skip_manual_resched_cards.setChecked(checked)


menu_skip_manual_resched_cards = checkable(
title="Skip manually rescheduled cards when rescheduling",
on_click=set_skip_manual_resched_cards,
)


def set_display_memory_state(checked, _):
config.display_memory_state = checked

Expand Down Expand Up @@ -191,6 +216,7 @@ def sponsor(did=None):
menu_for_easy_days = menu_for_helper.addMenu(
"Less Anki on Easy Days (requires Load Balancing)"
)
menu_for_helper.addAction(menu_skip_manual_resched_cards)
menu_for_helper.addSeparator()
menu_for_helper.addAction(menu_reschedule)
menu_for_helper.addAction(menu_reschedule_recent)
Expand Down Expand Up @@ -285,6 +311,7 @@ def adjust_menu():
menu_auto_disperse_after_reschedule.setChecked(
config.auto_disperse_after_reschedule
)
menu_skip_manual_resched_cards.setChecked(config.skip_manual_resched_cards)
menu_for_auto_easy_days.setChecked(config.auto_easy_days)
menu_for_easy_0.setChecked(0 in config.easy_days)
menu_for_easy_1.setChecked(1 in config.easy_days)
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"display_memory_state": false,
"auto_easy_days": false,
"has_rated": false,
"has_sponsored": false
"has_sponsored": false,
"skip_manual_resched_cards": false
}
10 changes: 10 additions & 0 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
AUTO_EASY_DAYS = "auto_easy_days"
HAS_RATED = "has_rated"
HAS_SPONSORED = "has_sponsored"
SKIP_MANUAL_RESCHED_CARDS = "skip_manual_resched_cards"


def load_config():
Expand Down Expand Up @@ -187,3 +188,12 @@ def has_sponsored(self):
def has_sponsored(self, value):
self.data[HAS_SPONSORED] = value
self.save()

@property
def skip_manual_resched_cards(self):
return self.data[SKIP_MANUAL_RESCHED_CARDS]

@skip_manual_resched_cards.setter
def skip_manual_resched_cards(self, value):
self.data[SKIP_MANUAL_RESCHED_CARDS] = value
self.save()
11 changes: 11 additions & 0 deletions schedule/reschedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ def reschedule_background(
if filter_flag:
filter_query = f"AND id IN {ids2str(filtered_cids)}"

if config.skip_manual_resched_cards:
skip_query = """
AND id NOT IN (
SELECT cid
FROM revlog
GROUP BY cid
HAVING MAX(CASE WHEN ease = 0 THEN id ELSE NULL END) = MAX(id)
)
"""

cid_did_nid = mw.col.db.all(
f"""
SELECT
Expand All @@ -261,6 +271,7 @@ def reschedule_background(
{did_query if did_query is not None else ""}
{recent_query if recent else ""}
{filter_query if filter_flag else ""}
{skip_query if config.skip_manual_resched_cards else ""}
ORDER BY ivl
"""
)
Expand Down

0 comments on commit 5b27518

Please sign in to comment.