From 074799d1471df407663931d6654847fa38484a3e Mon Sep 17 00:00:00 2001 From: Shadify Date: Mon, 4 Dec 2017 10:01:06 +0100 Subject: Fixed breakpoint in AQI calculation --- src/AppBundle/Controller/NewDataController.php | 1 - src/AppBundle/Utils/Aqi.php | 4 ++-- web/js/realtime.js | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AppBundle/Controller/NewDataController.php b/src/AppBundle/Controller/NewDataController.php index ecb1be9..5dd440f 100644 --- a/src/AppBundle/Controller/NewDataController.php +++ b/src/AppBundle/Controller/NewDataController.php @@ -36,7 +36,6 @@ class NewDataController extends Controller $response = new Response($data); $response->headers->set('Content-Type', 'application/json'); - return $response; } diff --git a/src/AppBundle/Utils/Aqi.php b/src/AppBundle/Utils/Aqi.php index 6451c77..1b324a8 100644 --- a/src/AppBundle/Utils/Aqi.php +++ b/src/AppBundle/Utils/Aqi.php @@ -19,12 +19,12 @@ class Aqi { $arr = $table ->{$gasName} ->{'breakpoints'}; foreach ($arr as $index => $value) { - if ($value < $concentration && $table->{$gasName}->{'breakpoints'}[$index + 1] > $concentration) { + if ($value <= $concentration && $table->{$gasName}->{'breakpoints'}[$index + 1] >= $concentration) { $bpLow = $value; $bpLowIndex = $index; } - if ($value > $concentration && $table->{$gasName}->{'breakpoints'}[$index - 1] < $concentration) { + if ($value >= $concentration && $table->{$gasName}->{'breakpoints'}[$index - 1] <= $concentration) { $bpHi = $value; $bpHiIndex = $index; } diff --git a/web/js/realtime.js b/web/js/realtime.js index 27cb25c..e090d05 100644 --- a/web/js/realtime.js +++ b/web/js/realtime.js @@ -30,12 +30,12 @@ function calculateAQI(gasName, concentration) { var bpLowIndex, bpHiIndex; table[gasName].breakpoints.forEach(function(value, index) { - if(value < concentration && table[gasName].breakpoints[index + 1] > concentration) { + if(value <= concentration && table[gasName].breakpoints[index + 1] >= concentration) { bpLow = value; bpLowIndex = index; } - if(value > concentration && table[gasName].breakpoints[index - 1] < concentration) { + if(value >= concentration && table[gasName].breakpoints[index - 1] <= concentration) { bpHi = value; bpHiIndex = index; } @@ -75,6 +75,7 @@ function update() { indexes.push(NO); indexes.push(SO); + var max = arrayMax(indexes); document.querySelector("#aq").innerHTML = `The current air quality index is ${max}`; -- cgit v1.2.3