Skip to content

updates to bring back to life, more to come soon#1

Open
iroxusux wants to merge 7 commits intomainfrom
irox_updates
Open

updates to bring back to life, more to come soon#1
iroxusux wants to merge 7 commits intomainfrom
irox_updates

Conversation

@iroxusux
Copy link
Copy Markdown
Collaborator

  • fixes for sprocket attrs
  • detach logic from cmd files for cleanliness
  • restructure for proper packaging (WIP)
    this gets the bot booting and performing the same functions as before.
    now, to bring more robustness / features.

- fixes for sprocket attrs
- detach logic from cmd files for cleanliness
- restructure for proper packaging (WIP)
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()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@iroxusux iroxusux closed this Mar 30, 2025
@iroxusux iroxusux reopened this Mar 30, 2025
@iroxusux
Copy link
Copy Markdown
Collaborator Author

sorry, idiot with git. getting used to it still

@iroxusux iroxusux requested a review from gankoji March 30, 2025 19:35
@iroxusux iroxusux self-assigned this Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants