aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2017-11-30 12:58:21 +0100
committermarcinzelent <zelent.marcin@gmail.com>2017-11-30 12:58:21 +0100
commit4246f15d64d9ec460b3cb5acc2e838978bc2c91c (patch)
tree1a7087c1870dff4dedd57b4e893a710785cebe32 /src/AppBundle/Utils/Aqi.php
parent1a572a61f0bc6fe58a7270fca57a4b97066eeac2 (diff)
parent1e5946aba89293d1a3103adb885bff4a69c6f769 (diff)
Merge remote-tracking branch 'origin/master'
# Conflicts: # .idea/workspace.xml
Diffstat (limited to 'src/AppBundle/Utils/Aqi.php')
-rw-r--r--src/AppBundle/Utils/Aqi.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/AppBundle/Utils/Aqi.php b/src/AppBundle/Utils/Aqi.php
new file mode 100644
index 0000000..6451c77
--- /dev/null
+++ b/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