diff options
author | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-16 17:48:44 +0100 |
---|---|---|
committer | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-16 17:48:44 +0100 |
commit | ed01011dfb563e7d8ab13b6a0718eed7bf857880 (patch) | |
tree | 104a22a75d287d0607668eea3177eec626ab3f80 /pollutometer-php/src/AppBundle/Utils | |
parent | 1d24e941dc7d9da10c9045203ae18f5234c774f5 (diff) |
Moved PHP website to separate directory.
Diffstat (limited to 'pollutometer-php/src/AppBundle/Utils')
-rw-r--r-- | pollutometer-php/src/AppBundle/Utils/Aqi.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/pollutometer-php/src/AppBundle/Utils/Aqi.php b/pollutometer-php/src/AppBundle/Utils/Aqi.php new file mode 100644 index 0000000..1b324a8 --- /dev/null +++ b/pollutometer-php/src/AppBundle/Utils/Aqi.php @@ -0,0 +1,43 @@ +<?php +/** + * Created by PhpStorm. + * User: andy + * Date: 11/30/17 + * Time: 11:27 AM + * + * + */ + +Namespace AppBundle\Utils; + +class Aqi { + public function calculateAQI($gasName, $concentration, $table) { + $bpLow = 1; + $bpHi = 2; + $bpLowIndex = 1; + $bpHiIndex = 1; + + $arr = $table ->{$gasName} ->{'breakpoints'}; + foreach ($arr as $index => $value) { + if ($value <= $concentration && $table->{$gasName}->{'breakpoints'}[$index + 1] >= $concentration) { + $bpLow = $value; + $bpLowIndex = $index; + } + + if ($value >= $concentration && $table->{$gasName}->{'breakpoints'}[$index - 1] <= $concentration) { + $bpHi = $value; + $bpHiIndex = $index; + } + + }; + + + + $airQualityIndex = (($table->{$gasName}->{'aq'}[$bpHiIndex] - $table->{$gasName}->{'aq'}[$bpLowIndex]) / ($bpHi - $bpLow)) * ($concentration - $bpLow) + $table->{$gasName}->{'aq'}[$bpLowIndex]; + + return $airQualityIndex; + + } +} + +?>
\ No newline at end of file |