Grist-Data-Desk / STLoR

Code and methodology to produce the dataset in Grist and High Country News' investigation into state trust lands on reservations
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

fix acreage pct calc #16

Closed clayton-aldern closed 4 days ago

clayton-aldern commented 3 weeks ago

@parkerziegler I think this line should be $: pctCoverage = (stats.stl_total_acres / stats.acres * 2) * 100; (i.e. move the 2 inside the parentheses)?

parkerziegler commented 3 weeks ago

Good read that the calculation is off! Looking a bit closer, I think it should actually be:

$: pctCoverage = stats.stl_total_acres / (stats.acres * 2) * 100;

which Prettier will rewrite to:

$: pctCoverage = (stats.stl_total_acres / (stats.acres * 2)) * 100;

to try to disambiguate operator order (which, I absolutely needed on this one). As a quick sanity check, I punched the following into Node:

node
Welcome to Node.js v20.12.2.
Type ".help" for more information.
> // Original implementation.
undefined
> (294895.97 / 823718.64) * 2 * 100
71.60114040881726
> // Attempted fix.
undefined
> (294895.97 / 823718.64 * 2) * 100
71.60114040881726
> // Final fix.
undefined
> (294895.97 / (823718.64 * 2)) * 100
17.9002

The last agrees with the numbers you sent in Slack, so I'll push a commit with that change in real quick! Thanks for catching this eagle eyes 🙏