diff options
author | Galen Guyer <galen@galenguyer.com> | 2020-11-23 15:16:09 -0500 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2020-11-23 15:16:09 -0500 |
commit | 5c24198b08bf461fc226e080bd1b2dc23d6aebf5 (patch) | |
tree | deaa61db2fcd20496b23235a2177800211affc3f | |
parent | 05423554f6379e3d1e2325c853f6708a35ae72b1 (diff) |
Make sure the test rates are between 0 and 100
Should fix #1
-rw-r--r-- | src/MainPage.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/MainPage.js b/src/MainPage.js index 1657bec..f5fa303 100644 --- a/src/MainPage.js +++ b/src/MainPage.js @@ -8,13 +8,21 @@ const MainPage = (props) => { const prior = data[data.length - (1 + props.timeDifference)]; const priorPrior = data[data.length - (1 + props.timeDifference * 2)]; - const positiveTestRate = ( - ((latest.total_students - prior.total_students) * 100) / - (latest.tests_administered - prior.tests_administered) + const positiveTestRate = Math.max( + 0, + Math.min( + 100, + ((latest.total_students - prior.total_students) * 100) / + (latest.tests_administered - prior.tests_administered) + ) ).toFixed(1); - const priorPositiveTestRate = ( - ((prior.total_students - priorPrior.total_students) * 100) / - (prior.tests_administered - priorPrior.tests_administered) + const priorPositiveTestRate = Math.max( + 0, + Math.min( + 100, + ((prior.total_students - priorPrior.total_students) * 100) / + (prior.tests_administered - priorPrior.tests_administered) + ) ).toFixed(1); return ( |