Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Anki version >=2.1.26 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 24 additions & 18 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

# Find decks in settings group
def find_decks_in_settings_group(group_id):
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
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[str(group_id)]

# Find average ease and number of mature cards in deck
# mature defined as having an interval > 90 day
Expand Down Expand Up @@ -49,7 +51,7 @@ def mature_ease_in_settings_group(dogID):
group_id = dogID
if group_id:
# Find decks and cycle through
decks = find_decks_in_settings_group(group_id)
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
Expand All @@ -58,19 +60,20 @@ 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 = mw.col.decks.dconf[group_id]["new"]["initialFactor"]
cur_ease = mw.col.decks.dconf[group_id]["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
if group_id:
if group_id in mw.col.decks.dconf:
mw.col.decks.dconf[group_id]["new"]["initialFactor"] = int(ease_factor)
mw.col.decks.save(mw.col.decks.dconf[group_id])
#mw.col.decks.flush()
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):
avg_ease, cur_ease = mature_ease_in_settings_group(dogID)
Expand All @@ -80,15 +83,18 @@ def update_ease_factor(dogID):
# run this on profile load
def update_ease_factors():
#find all deck option groups
dconf = mw.col.decks.dconf
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
for k in dconf:
update_ease_factor(k)
#mw.progress.update("Init Ease Factor: %s" % dconf[k]['name'], i)
for dconf in all_config():
update_ease_factor(dconf['id'])
#mw.progress.update("Init Ease Factor: %s" % dconf['name'], i)
#i += 1
#time.sleep(1)
#mw.progress.finish()
Expand Down