Skip to content

Commit

Permalink
slight change in how combining decks is done
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed Apr 24, 2024
1 parent e1c6a61 commit 9559eb6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions handlers/storage_settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,20 @@ def count_attributes(obj):
return len(obj.__dict__)

# Perform elimination of duplicates
new_vocab = [vocab1 for vocab1 in new_vocab if
not any((vocab1.main_testing_material.value == vocab2.main_testing_material.value and
vocab1.main_reading.romaji == vocab2.main_reading.romaji and
count_attributes(vocab1) <= count_attributes(vocab2)) for vocab2 in old_vocab)]

old_vocab = [vocab1 for vocab1 in old_vocab if
not any((vocab1.main_testing_material.value == vocab2.main_testing_material.value and
vocab1.main_reading.romaji == vocab2.main_reading.romaji and
count_attributes(vocab1) <= count_attributes(vocab2)) for vocab2 in new_vocab)]
new_vocab = []
for vocab1 in LocalHandler.vocab:
duplicates = [vocab2 for vocab2 in old_vocab if vocab1.main_testing_material.value == vocab2.main_testing_material.value and vocab1.main_reading.romaji == vocab2.main_reading.romaji]
if duplicates:
# If there are duplicates, choose the one with more attributes or higher counts
duplicate = max(duplicates, key=lambda x: (count_attributes(x), x.correct_count, x.incorrect_count))
if count_attributes(vocab1) > count_attributes(duplicate) or (vocab1.correct_count, vocab1.incorrect_count) > (duplicate.correct_count, duplicate.incorrect_count):
new_vocab.append(vocab1)
else:
new_vocab.append(duplicate)
else:
new_vocab.append(vocab1)

old_vocab = [vocab1 for vocab1 in old_vocab if not any(vocab1.main_testing_material.value == vocab2.main_testing_material.value and vocab1.main_reading.romaji == vocab2.main_reading.romaji for vocab2 in new_vocab)]

## apply new vocab to file
for vocab in new_vocab:
Expand Down

0 comments on commit 9559eb6

Please sign in to comment.