updates to bring back to life, more to come soon#1
Conversation
- fixes for sprocket attrs - detach logic from cmd files for cleanliness - restructure for proper packaging (WIP)
MLEBot/task_sprocket.py
Outdated
| known_guild = next((x for x in self.bot.guild_ids if str(x['id']) == interaction.guild.id.__str__()), None) | ||
| if not known_guild: | ||
| return None | ||
| return next((x for x in self.data['sprocket_teams'] if x['Franchise'].upper() == known_guild['team'].upper()), |
There was a problem hiding this comment.
You use this pattern often, so it's worth noting that it's horrifically inefficient. Just for clarity:
(x for x in data['dataset_key'] if x['prop_key'] = thing_were_searching_for)
is the same as
for x in data['dataset_key']:
if x['prop_key'] == thing_were_searching_for:
return x
I.e., all of these methods are using linear search over potentially large datasets to find bits of data. Python (and every other modern language/runtime combo) has a muuuuuch better choice for this type of operation: the hash map, or dictionary.
Whenever the datasets are fetched, it would make a great deal more sense to spend the time to process them into datasets, keyed by whatever you're going to search with later (like 'Franchise', 'discord_id', 'name', 'member_id', etc). Then, all f these methods here on lines 146-205 become lightning fast dictionary lookups, instead of linear searches through arrays.
There was a problem hiding this comment.
Worth noting what I mean by slow and fast: Linear search is O(n), n being the size of the dataset being searched (which in the case of player_stats is many millions). Dictionary lookup is O(1).
There was a problem hiding this comment.
with my latest commit i believe i have mostly solved this issue. there's a few more tweaks i'm sure i could make in the future, but this should do for now
When pulled into main, will distribute to Roxanne.
|
sorry, idiot with git. getting used to it still |
addition of unit-tests that i would like another dev to start on another branch.
…increase later but wanted to save time for now).
this gets the bot booting and performing the same functions as before.
now, to bring more robustness / features.