Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

131 locate free extensions #139

Merged
merged 9 commits into from
Nov 19, 2024
Merged

131 locate free extensions #139

merged 9 commits into from
Nov 19, 2024

Conversation

KiPageFault
Copy link
Collaborator

No description provided.

@KiPageFault KiPageFault linked an issue Nov 5, 2024 that may be closed by this pull request
Description Available In Docstring
Chopped4Life
Chopped4Life previously approved these changes Nov 5, 2024
Copy link
Owner

@Jordan-Prescott Jordan-Prescott left a comment

Choose a reason for hiding this comment

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

Need a few changes dude but the code and design is great! You have a good mind for this stuff for sure, just missing some python standards but that's understandable not writing this language before.

odins_spear/scripter.py Show resolved Hide resolved
@@ -167,6 +167,9 @@ def remove_numbers(self, service_provider_id: str, group_id: str, start_of_range
return scripts.remove_numbers.main(self.api, service_provider_id, group_id, start_of_range_number,
end_of_range_number)

def locate_free_extension(self, service_provider_id: str, group_id: str, field: list):

return scripts.locate_free_extension(self.api, service_provider_id, group_id, field)
Copy link
Owner

Choose a reason for hiding this comment

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

Have you ran the code? Missing '.main()' here on the end of 'locate_free_extension' which would have errored if you ran it.

odins_spear/scripts/locate_free_extension.py Show resolved Hide resolved
group_id
)

for data in dataset:
Copy link
Owner

Choose a reason for hiding this comment

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

This is a little repetitive looping three times, can we be more efficient here collecting all data and looping once maybe?

if not extensions:
return

return extensions
Copy link
Owner

Choose a reason for hiding this comment

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

Condensed version of lines 58-61:

return extensions if extensions else None

###

### Locate Initial Free Extension
extension_set = set(extensions)
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why you've done this dude, extensions is already an iterable. Converting to a set is usually only done when we want to remove duplicates or need specific set functionality.

### Locate Initial Free Extension
extension_set = set(extensions)

for extension in range(field[0] + 1, field[1]):
Copy link
Owner

Choose a reason for hiding this comment

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

Why do you skip the first extension in the range by adding 1? Range starts at the first value and goes up to but doesn't include the last value so would have thought you'd add 1 to the end to include the last value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believed the range would be better suitable for extensions between the passed range values however

extension_set = set(extensions)

for extension in range(field[0] + 1, field[1]):
if extension not in extension_set:
Copy link
Owner

Choose a reason for hiding this comment

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

Does this work as extensions will be a set of strings right like '100' and you are looking for an integer just 100.


for extension in range(field[0] + 1, field[1]):
if extension not in extension_set:
return extension
Copy link
Owner

Choose a reason for hiding this comment

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

This is just keeping convention we have but here return a python dict like the below.

return {'extension': extension}

return extension
####

print("Unable To Locate A Free Extension Within The Range")
Copy link
Owner

Choose a reason for hiding this comment

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

Here we want to raise an a new error that the user hasn't been found. The reason we do this is if a developer has a script that uses this function to first find a free extension and in the next step takes what is returned from this and inserts into a new function to build it printing we didnt find it has no control flow value. We need to interrupt otherwise we will cause rurther errors down the line.

As per Jordan's comment review, I have improved the script to better suite the codebase
@Jordan-Prescott Jordan-Prescott added the enhancement New feature or request label Nov 11, 2024
Copy link
Owner

@Jordan-Prescott Jordan-Prescott left a comment

Choose a reason for hiding this comment

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

Just the Exception to raise dude.

odins_spear/scripter.py Show resolved Hide resolved
'''Retrieves The Lowest Free Extension Available In The Designated Group Passed.
'''

if extension_range[0] > extension_range[1]:
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can avoid this range adjusting by separating into two params and raise an error if the end is larger. Instead of extension_range remove this and introduce 'start_of_range' and 'end_of_range'. Then in the code you can create a new error and do the below:

if start_of_range > end_of_range:
raise OSInvalidInput <- example (check if we have an existing error you could throw)

group_id,
)

for extension in range(extension_range[0], extension_range[1] + 1):
Copy link
Owner

Choose a reason for hiding this comment

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

You can update this inline with the new params

api,
service_provider_id: str,
group_id: str,
extension_range: list
Copy link
Owner

Choose a reason for hiding this comment

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

Still the old param not the new start of and end of range.

odins_spear/scripts/locate_free_extension.py Show resolved Hide resolved
Copy link
Owner

@Jordan-Prescott Jordan-Prescott left a comment

Choose a reason for hiding this comment

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

All good, really nice work dude!

@KiPageFault KiPageFault merged commit 85293e7 into main Nov 19, 2024
1 check passed
@Jordan-Prescott Jordan-Prescott deleted the 131-locate-free-extensions branch November 19, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Locate free extensions
3 participants