Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions ankihub/main/deck_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
from anki import deckconfig_pb2 as deck_config_pb2 # type: ignore

ANKIHUB_PRESET_NAME = "AnkiHub"
ANKING_PRESET_NAME = "AnKing"
ANKING_OVERRIDES = {
"new_limit": 9999,
"review_limit": 9999,
}
DEFAULT_OVERRIDES = {
"new_limit": 50,
"review_limit": 500,
}
DECK_CONFIG: Dict[str, Any] = {
"steps": [15, 1440],
"fsrs_steps": [15],
Expand All @@ -21,7 +30,6 @@
"new_mix": deck_config_pb2.DeckConfig.Config.ReviewMix.REVIEW_MIX_AFTER_REVIEWS,
"interday_learning_mix": deck_config_pb2.DeckConfig.Config.ReviewMix.REVIEW_MIX_BEFORE_REVIEWS,
"review_order": deck_config_pb2.DeckConfig.Config.ReviewCardOrder.REVIEW_CARD_ORDER_DAY,
"daily_limit": 9999,
"bury": True,
"new_intervals": [3, 4, 0],
"easy_bonus": 1.5,
Expand All @@ -46,10 +54,8 @@
"new_mix": ("newMix",),
"interday_learning_mix": ("interdayLearningMix",),
"review_order": ("reviewOrder",),
"daily_limit": (
"rev.perDay",
"new.perDay",
),
"new_limit": ("new.perDay",),
"review_limit": ("rev.perDay",),
"bury": ("rev.bury", "new.bury", "buryInterdayLearning"),
"new_intervals": ("new.ints",),
"easy_bonus": ("rev.ease4",),
Expand All @@ -69,6 +75,15 @@ def deep_set(data: Dict, path: str, value: Any) -> None:
d[last_key] = value


def get_effective_deck_config(preset_name: str) -> Dict[str, Any]:
is_anking_preset = preset_name == ANKING_PRESET_NAME
overrides = ANKING_OVERRIDES if is_anking_preset else DEFAULT_OVERRIDES
return {
**DECK_CONFIG,
**overrides,
}


def create_or_reset_deck_preset(
preset_name=ANKIHUB_PRESET_NAME,
) -> DeckConfigDict:
Expand All @@ -81,8 +96,9 @@ def create_or_reset_deck_preset(
else:
conf = aqt.mw.col.decks.add_config(preset_name)
fsrs_enabled = aqt.mw.col.get_config("fsrs")
for option, value in DECK_CONFIG.items():
if (fsrs_enabled and f"fsrs_{option}" in DECK_CONFIG) or (not fsrs_enabled and option.startswith("fsrs_")):
effective_config = get_effective_deck_config(preset_name=preset_name)
for option, value in effective_config.items():
if (fsrs_enabled and f"fsrs_{option}" in effective_config) or (not fsrs_enabled and option.startswith("fsrs_")):
continue
option_paths = CONFIG_NAME_TO_DECK_OPTIONS_PATH[option]
for path in option_paths:
Expand All @@ -99,7 +115,7 @@ def set_ankihub_config_for_deck(deck_id: DeckId, is_anking_deck: bool = False) -
return

if is_anking_deck and config.get_feature_flags().get("fsrs_in_recommended_deck_settings"):
conf = create_or_reset_deck_preset(preset_name="AnKing")
conf = create_or_reset_deck_preset(preset_name=ANKING_PRESET_NAME)
else:
conf = create_or_reset_deck_preset()

Expand Down
Loading