Added sorting

Sort Game Modes by 'timePlayed' in descending order
Sort Weapons by 'kills' in descending order
Sort Field Upgrades by 'uses' in descending order
Sort Lethal and Tactical equipment by 'uses' in descending order
Sort Lethal and Support Scorestreaks by 'awardedCount' in descending order
Sort Accolades in descending order
This commit is contained in:
Ahrimdon 2023-10-03 05:22:41 -04:00
parent 7c349dee19
commit 6c3fc6e9d6
2 changed files with 781 additions and 760 deletions

View File

@ -12,12 +12,33 @@ def replace_and_sort_keys_in_json(file_path, replacements):
for key, value in obj.items(): for key, value in obj.items():
new_key = replacements.get(key, key) new_key = replacements.get(key, key)
new_obj[new_key] = recursive_key_replace(value, replacements) new_obj[new_key] = recursive_key_replace(value, replacements)
if new_key == "mode": # Sort Game Modes by 'timePlayed' in descending order
sorted_modes = dict(sorted(new_obj[new_key].items(), key=lambda item: item[1]['properties']['timePlayed'], reverse=True))
new_obj[new_key] = sorted_modes
if new_key in ["Assault Rifles", "Shotguns", "Marksman Rifles", "Snipers", "LMGs", "Launchers", "Pistols", "SMGs", "Melee"]: # Sort Weapons by 'kills' in descending order
sorted_weapons = dict(sorted(new_obj[new_key].items(), key=lambda item: item[1]['properties']['kills'], reverse=True))
new_obj[new_key] = sorted_weapons
if new_key in ["Field Upgrades"]: # Sort Field Upgrades by 'uses' in descending order
sorted_fieldupgrades = dict(sorted(new_obj[new_key].items(), key=lambda item: item[1]['properties']['uses'], reverse=True))
new_obj[new_key] = sorted_fieldupgrades
if new_key in ["Tactical Equipment", "Lethal Equipment"]: # Sort Lethal and Tactical equipment by 'uses' in descending order
sorted_equipment = dict(sorted(new_obj[new_key].items(), key=lambda item: item[1]['properties']['uses'], reverse=True))
new_obj[new_key] = sorted_equipment
if new_key == "Scorestreaks": # Sort Lethal and Support Scorestreaks by 'awardedCount' in descending order
for subcategory, scorestreaks in new_obj[new_key].items():
sorted_scorestreaks = dict(sorted(scorestreaks.items(), key=lambda item: item[1]['properties']['awardedCount'], reverse=True))
new_obj[new_key][subcategory] = sorted_scorestreaks
# Sort Accolades in descending order # Sort Accolades in descending order
if new_key == "Accolades": if new_key == "Accolades":
sorted_accolades = dict(sorted(new_obj[new_key]['properties'].items(), key=lambda item: item[1], reverse=True)) sorted_accolades = dict(sorted(new_obj[new_key]['properties'].items(), key=lambda item: item[1], reverse=True))
new_obj[new_key]['properties'] = sorted_accolades new_obj[new_key]['properties'] = sorted_accolades
return new_obj return new_obj
elif isinstance(obj, list): elif isinstance(obj, list):
for index, value in enumerate(obj): for index, value in enumerate(obj):
@ -274,4 +295,4 @@ if __name__ == "__main__":
file_path = "stats.json" file_path = "stats.json"
replace_and_sort_keys_in_json(file_path, replacements) replace_and_sort_keys_in_json(file_path, replacements)
print(f"Keys replaced and accolades sorted in {file_path}!") print(f"Keys sorted and replaced in {file_path}!")

File diff suppressed because it is too large Load Diff