Skip to content

Commit

Permalink
Make backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
telotortium committed Aug 24, 2020
1 parent f956b9c commit 2f7a602
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 2f7a602

Please sign in to comment.