From 2f7a602cee5a03805122aa7cacadaa33df14c774 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 | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index ca19859..dab99a2 100644 --- a/__init__.py +++ b/__init__.py @@ -9,6 +9,25 @@ from aqt import mw #import time +# Find decks in settings group +def find_decks_in_settings_group(group_id): + try: + return mw.col.decks.didsForConf(mw.col.decks.get_config(group_id)) + except AttributeError: + members = [] + decks = mw.col.decks.decks + for d in decks: + if 'conf' in decks[d] and int(decks[d]['conf']) == int(group_id): + members.append(d) + return members + +# 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): @@ -50,17 +69,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 +91,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