aboutsummaryrefslogtreecommitdiff
path: root/src/MainPage.js
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2020-11-23 15:16:09 -0500
committerGalen Guyer <galen@galenguyer.com>2020-11-23 15:16:09 -0500
commit5c24198b08bf461fc226e080bd1b2dc23d6aebf5 (patch)
treedeaa61db2fcd20496b23235a2177800211affc3f /src/MainPage.js
parent05423554f6379e3d1e2325c853f6708a35ae72b1 (diff)
Make sure the test rates are between 0 and 100
Should fix #1
Diffstat (limited to 'src/MainPage.js')
-rw-r--r--src/MainPage.js20
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 (