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

WebHost: Round percentage of checks, fix possible 500 error #2270

Merged

Conversation

remyjette
Copy link
Collaborator

What is this fixing or adding?

  • Round the percentage of total checks done instead of truncating to an int

    Playing the Inscryption beta test, the world has exactly 100 checks and thanks to truncating and floats, sometimes they wouldn't match which was bothering me:

    image

  • Don't return a 500 error if a multiworld has no locations

    If the multiworld has no locations at all, the summary row added in WebHost: Add a summary row to the Multiworld Tracker #1965 would cause a divide-by-zero and return a 500 error. While a multiworld with 0 locations isn't really a real use case, I still don't like returning 500 errors.

How was this tested?

Ran WebHost.py locally

If this makes graphical changes, please attach screenshots.

image

@LegendaryLinux
Copy link
Member

I approve of the concept of this change, though I'm not familiar enough with the Jinja to make an educated assessment.

@Berserker66
Copy link
Member

the | operator works similar to a unix command line, it "pipes" the left stuff further with that modification. So in this case the number is rounded and then converted to an integer.

@LegendaryLinux
Copy link
Member

Ah, okay. Seems good to me then, though I have not tested it myself.

Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

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

I'm wondering if the flooring (i.e. int, not round) was intentional so it wouldn't show 100% unless you really have 100%?

Other than that, it might be nicer to move some processing from jinja to python (i.e. pass in the data differently), but i think reworking that is probably out of scope for this PR.

@remyjette
Copy link
Collaborator Author

I'm wondering if the flooring (i.e. int, not round) was intentional so it wouldn't show 100% unless you really have 100%?

Maybe, but I feel like rounding rather than truncating is still more intuitive to non-programmers

If someone sees 299/300 and then percent 100, I'd expect them to say "oh okay not every check is done but the percentage of checks is rounded, makes sense, that's what the raw numbers to the left are there for"

Whereas seeing 57/100 show 56% tends to make heads explode for folks who don't understand IEEE 754 floats - it looks like a bug.

I guess we could say "round except if it would make it 100% with checks done != total locations" but that seems messy to me

@black-sliver
Copy link
Member

black-sliver commented Oct 10, 2023

Could also multiply first and then do integer division to avoid the pesky float errors

@LegendaryLinux
Copy link
Member

LegendaryLinux commented Oct 10, 2023

What if we rounded the percentage to two decimal places? Then we could give a more accurate representation without taking up too much space.

@remyjette
Copy link
Collaborator Author

What if we rounded the percentage to two decimal places? Then we could give a more accurate representation without taking up too much space.

Here's what that would look like:

image

I'm happy to swap this PR to that if folks prefer it.

@LegendaryLinux
Copy link
Member

I like it. Others?

@LegendaryLinux LegendaryLinux self-assigned this Oct 11, 2023
@ThePhar ThePhar added is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. affects: webhost Issues/PRs that touch webhost and may need additional validation. labels Oct 17, 2023
@BootsinSoots
Copy link
Contributor

I feel like two decimal places is the appropriate number. People stop paying attention after the 2nd and this is still intuitive to people even if they struggled with mathematics

Copy link
Member

@LegendaryLinux LegendaryLinux left a comment

Choose a reason for hiding this comment

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

Let's go with the two decimal places and I'll approve and merge.

How the percentage of checks done should be displayed is a display
concern, so it makes sense to just always do it in the template. That
way, along with using .format() instead of .round, means we always get
exactly the same presentation regardless of whether it ends in .00
(which would not round to two decimal places), is an int (which
`round(2)` wouldn't touch at all), etc.
@remyjette
Copy link
Collaborator Author

Let's go with the two decimal places and I'll approve and merge.

Done. I've switched from using round() to "{0:.2f}".format as otherwise 0 checks would be 0.0 and I didn't like the inconsistency of 1 decimal in some places but two decimals in others. If that behavior is considered desirable I can always swap it back

Also made more sense to me to just always do the rounding in the template as it's a presentation concern so probably should be in the template and that way we dont need the "{0:.2f}".format in multiple spots in tracker.py.
In addition, doing it in the template means we don't have to special case spectator slots with no locations adding .0s everywhere in tracker.py to make things floats, because again I didn't like the inconsistency that that just showed as 100 while a completed slot showed as 100.00

@LegendaryLinux
Copy link
Member

LegendaryLinux commented Oct 27, 2023

I was all ready to approve, but then I decided to test things. The LttP tracker gives too many decimals.

image

@remyjette
Copy link
Collaborator Author

I was all ready to approve, but then I decided to test things. The LttP tracker gives too many decimals.

image

Crap. Thanks for catching that... I'll fix the lttp tracker and double check the Factorio tracker as well tomorrow.

@remyjette
Copy link
Collaborator Author

remyjette commented Oct 30, 2023

Fixed the rounding:

Generic

image

LttP:

image

Factorio

image

The LttP multitracker showing 0.0 for non-LttP games isn't a regression it shows 0 on main too. I'm going to see if I can fix it while I'm here though

@remyjette
Copy link
Collaborator Author

And, fixed
image

@LegendaryLinux LegendaryLinux merged commit 3bff20a into ArchipelagoMW:main Oct 31, 2023
12 checks passed
@remyjette remyjette deleted the round-checks-percent-done branch November 13, 2023 01:18
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
…agoMW#2270)

* WebHost: Round percentage of checks, fix possible 500 error

* Round using str.format in the template

How the percentage of checks done should be displayed is a display
concern, so it makes sense to just always do it in the template. That
way, along with using .format() instead of .round, means we always get
exactly the same presentation regardless of whether it ends in .00
(which would not round to two decimal places), is an int (which
`round(2)` wouldn't touch at all), etc.

* Round percent_total_checks_done in lttp multitracker

* Fix non-LttP games showing as 0% done in LttP MultiTracker
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
…agoMW#2270)

* WebHost: Round percentage of checks, fix possible 500 error

* Round using str.format in the template

How the percentage of checks done should be displayed is a display
concern, so it makes sense to just always do it in the template. That
way, along with using .format() instead of .round, means we always get
exactly the same presentation regardless of whether it ends in .00
(which would not round to two decimal places), is an int (which
`round(2)` wouldn't touch at all), etc.

* Round percent_total_checks_done in lttp multitracker

* Fix non-LttP games showing as 0% done in LttP MultiTracker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: webhost Issues/PRs that touch webhost and may need additional validation. is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants