mysociety / caps

A simple, open database of local government climate action plan documents and emissions data.
https://cape.mysociety.org
Other
9 stars 2 forks source link

[Scorecards] Integer numbers instead of float numbers for question marks #699

Closed lucascumsille closed 2 weeks ago

lucascumsille commented 1 month ago

Minor issue raised by CEUK, but in some question we have marks that are displayed as float numbers instead of integer, which seems a bit odd when reading the whole table.

There are questions where using float numbers make sense because they can be eg. 1.25, we wouldn't want to lose that accuracy when it's necessary. Could we add in Django a conditional to only display float numbers if needed and display integer by default?

Screenshot 2024-10-21 at 11 03 28

Example extracted from: https://councilclimatescorecards.uk/councils/london-borough-of-islington/

zarino commented 3 weeks ago

Django’s floatformat filter gets us real close here. {{ 1.0|floatformat }} outputs 1, yay!

But if floatformat is used on a number with a fraction part, it will truncate or pad the decimals to either the requested number of places, or to the default (which is 1 decimal place). So {{ 1.25|floatformat }} will become 1.3.

Will this be a problem? Can the number of marks a council got on a question ever be a fraction with more than one decimal place? And if it can, do we care if it gets rounded to one decimal place?

Assuming it’s fine, I’ve prepped a PR here with the required changes: #702

lucascumsille commented 2 weeks ago

@zarino checking with CEUK, I think

I believe this was initiated because of the air quality questions... if you don't have the decimal points they show as 0 (because the minus figures are -0.48 so then they are rounded down to 0). And at the time of launch (I think Struan did this change) we accepted that we need to show the air quality questions as their true figure. Otherwise as the numbers don't add up unless you can choose the 2 decimal place option... So if it can be done so only those air quality questions have a decimal point that works fine... otherwise we will just have the same issue as before

Unless I have misunderstood, your fix should do the trick. We will be just rounding so -0.32 will be -0.3

zarino commented 2 weeks ago

If we want more decimal places, we can have them. |floatformat:-2 would display -0.32 as -0.32, but, if there are any other single-character decimals, like 1.2, say, they’d get displayed as 1.20.

Is the air quality mark the only one that can be a decimal? (The answer to this may be different last year and this year!)

lucascumsille commented 2 weeks ago

Checking with CEUK if that's the case

lucascumsille commented 2 weeks ago

@zarino there is no certainty from CEUK at least this week. Here is what I found checking the current 2023 site(note that this only cover if the council had marks(positive or negative)):

I wonder if in there is an easy way in the backend to differentiate them from the rest of questions

zarino commented 2 weeks ago

Ah, ok, so if there are a few, maybe it’s just best that we write a custom template filter, that does the right thing every time – so if the number has two decimal places, it shows two decimals, and if it only has one decimal, it shows just one. I’ll amend my PR to do that.