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

Sorting Issue: Incorrect Order when Sorting Monsters by Size #399

Closed
uribracha2611 opened this issue Dec 27, 2023 · 7 comments
Closed

Sorting Issue: Incorrect Order when Sorting Monsters by Size #399

uribracha2611 opened this issue Dec 27, 2023 · 7 comments

Comments

@uribracha2611
Copy link

uribracha2611 commented Dec 27, 2023

Issue:
When attempting to sort monsters by size using the Open5E API, there is an inconsistency in the sorting order. Currently, when sorting in descending order, the first results include "Titanic" monsters, followed by "Tiny" monsters, which deviates from the expected sorting order.

Steps to Reproduce:
Use the API endpoint for sorting monsters by size in descending order: https://api.open5e.com/monsters/?ordering=-size
Observe that the first results include "Titanic" monsters, but instead of continuing in descending order, the subsequent monsters are "Tiny."

Expected Behavior:
When sorting monsters by size in descending order, the expected order should be from the largest size category ("Titanic") to the smallest size category ("Tiny") according to the standard D&D size classification.

Note:
If I'm using the API incorrectly, please clarify the correct usage. However, if this is indeed a bug, I am willing to try to solve it and submit a pull request.

Thank you for your assistance!

@Sturlen
Copy link
Contributor

Sturlen commented Dec 28, 2023

This is because the API lacking any awareness for what "size" classification means in D&D and is just sorting alphabetically. A possible solution is to add a new numeric field e.g. size_rating where a tiny creature is 0, small is 1, and so forth. This would be similar to how the cr and challenge_rating fields work.

Size is defined here on the Monster Model:

size = models.TextField(help_text='Monster size category.')

@uribracha2611
Copy link
Author

uribracha2611 commented Dec 29, 2023

Thanks. So just to be sure, I need to add the representation in open5e-api/api/models/monster.py and I need to add the data itself in the for all the monsters in the json. Do i need to change something in api_v2?

@uribracha2611
Copy link
Author

uribracha2611 commented Dec 29, 2023

also i have found that there is a file Monster.json_SKIPPED. do i need to change it?

@uribracha2611
Copy link
Author

uribracha2611 commented Dec 29, 2023

i have created a pull request that can be seen here #401

@augustjohnson
Copy link
Collaborator

I have an alternative solution to this that covers all approaches in #425

@uribracha2611
Copy link
Author

It looks great! Does it require any changes to the monster.json?.

@augustjohnson
Copy link
Collaborator

I'm calling this resolved within V2. While it doesn't solve v1 at this time, the long-term plan will be to transition to v2. This feature is fully supported in v2 by doing a size lookup for any creature or item, then sorting on the Rank field.
https://api-beta.open5e.com/v2/sizes/

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

No branches or pull requests

3 participants