open5e-api icon indicating copy to clipboard operation
open5e-api copied to clipboard

Sorting Issue: Incorrect Order when Sorting Monsters by Size

Open uribracha2611 opened this issue 2 years ago • 4 comments

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!

uribracha2611 avatar Dec 27 '23 20:12 uribracha2611

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: https://github.com/open5e/open5e-api/blob/b16e3d12b739eb1801935f2ebc6c90d47029f5b3/api/models/monster.py#L11

Sturlen avatar Dec 28 '23 21:12 Sturlen

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 avatar Dec 29 '23 05:12 uribracha2611

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

uribracha2611 avatar Dec 29 '23 07:12 uribracha2611

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

uribracha2611 avatar Dec 29 '23 10:12 uribracha2611

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

augustjohnson avatar Mar 15 '24 14:03 augustjohnson

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

uribracha2611 avatar Mar 15 '24 15:03 uribracha2611

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/

augustjohnson avatar Apr 04 '24 12:04 augustjohnson