From 189b955647d8527ca6a5152deeda1c725a4e4f09 Mon Sep 17 00:00:00 2001 From: Robert Irelan Date: Mon, 24 Aug 2020 01:34:06 -0700 Subject: [PATCH] Make backward compatible --- __init__.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index ca19859..f5d3f78 100644 --- a/__init__.py +++ b/__init__.py @@ -9,6 +9,17 @@ from aqt import mw #import time +# Find decks in settings group +def find_decks_in_settings_group(group_id): + return mw.col.decks.didsForConf(get_deck_config(group_id)) + +# Find deck configuration for settings group +def get_deck_config(group_id): + try: + return mw.col.decks.get_config(group_id) + except AttributeError: + return mw.col.decks.dconf[group_id] + # Find average ease and number of mature cards in deck # mature defined as having an interval > 90 day def find_average_ease_in_deck(deck_id): @@ -40,9 +51,8 @@ def mature_ease_in_settings_group(dogID): group_id = dogID if group_id: # Find decks and cycle through - dconf = mw.col.decks.get_config(group_id) - deck_ids = mw.col.decks.didsForConf(mw.col.decks.get_config(group_id)) - for d in deck_ids: + decks = mw.col.decks.didsForConf(get_deck_config(group_id)) + for d in decks: mature_cards, mature_ease = find_average_ease_in_deck(d) tot_mature_cards += mature_cards weighted_ease += mature_cards * mature_ease @@ -50,17 +60,19 @@ def mature_ease_in_settings_group(dogID): avg_mature_ease = int(weighted_ease / tot_mature_cards) else: # not enough data; don't change the init ease factor - avg_mature_ease = dconf["new"]["initialFactor"] - cur_ease = dconf["new"]["initialFactor"] + avg_mature_ease = get_deck_config(group_id)["new"]["initialFactor"] + cur_ease = get_deck_config(group_id)["new"]["initialFactor"] return avg_mature_ease, cur_ease # update initial ease factor of a settings group def update_initial_ease_factor(dogID, ease_factor): group_id = dogID - dconf = mw.col.decks.get_config(group_id) - dconf["new"]["initialFactor"] = int(ease_factor) - mw.col.decks.save(dconf) + if group_id: + dconf = get_deck_config(group_id) + dconf["new"]["initialFactor"] = int(ease_factor) + mw.col.decks.save(dconf) + #mw.col.decks.flush() # main function def update_ease_factor(dogID): @@ -70,13 +82,17 @@ def update_ease_factor(dogID): # run this on profile load def update_ease_factors(): + #find all deck option groups + try: + all_config = mw.col.decks.all_config + except AttributeError: + all_config = mw.col.decks.allConf #create progress bar - #ogs = len(dconf) + #ogs = len(all_config(mw.col.decks)) #mw.progress.start(max = ogs, label = "Init Ease Factor: %s" % ogs) #cycle through them one by one #i = 1 - #find all deck option groups - for dconf in mw.col.decks.all_config(): + for dconf in all_config(): update_ease_factor(dconf['id']) #mw.progress.update("Init Ease Factor: %s" % dconf['name'], i) #i += 1