From 5c24198b08bf461fc226e080bd1b2dc23d6aebf5 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Mon, 23 Nov 2020 15:16:09 -0500 Subject: Make sure the test rates are between 0 and 100 Should fix #1 --- src/MainPage.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') 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 ( -- cgit v1.2.3