Skip to content

Commit

Permalink
changed method for determining which vocab gets kept which combining …
Browse files Browse the repository at this point in the history
…decks
  • Loading branch information
Bikatr7 committed Apr 2, 2024
1 parent 22cbdd1 commit e1c6a61
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions handlers/storage_settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,20 @@ def combine_vocab_decks() -> None:
new_typo_ids = []
new_incorrect_typo_ids = []

## perform elimination of duplicates
# Define a function to count the number of attributes in an object
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 for vocab2 in old_vocab)]

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 for vocab2 in new_vocab)]
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)]

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

0 comments on commit e1c6a61

Please sign in to comment.