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 189b955
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -40,27 +51,28 @@ 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
if tot_mature_cards > 0 and weighted_ease:
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 +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
Expand Down

0 comments on commit 189b955

Please sign in to comment.