aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authormarwolaethblack <a.unal677@gmail.com>2017-11-27 13:53:08 +0100
committermarwolaethblack <a.unal677@gmail.com>2017-11-27 13:53:08 +0100
commit664b85ca0b3ee6bd2ee2e1a28864540ac4bdcbaf (patch)
treeabf648c2f9b06f7b7ba0671d57d5104917781766 /web
parent56cb58fdabf883a5641bfdb7d897f7b7dde2eb74 (diff)
air quality index calculations
Diffstat (limited to 'web')
-rw-r--r--web/js/realtime.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/web/js/realtime.js b/web/js/realtime.js
index 4526e5e..f0158a2 100644
--- a/web/js/realtime.js
+++ b/web/js/realtime.js
@@ -1,3 +1,45 @@
+const table = {
+ Co: {
+ breakpoints: [0, 4.4, 4.5, 9.4, 9.5, 12.4, 12.5, 15.4, 15.5, 30.4, 30.5, 40.4, 40.5, 50.4],
+ aq: [0, 50, 51, 100, 101, 150, 151, 200, 201, 300, 301, 400, 401, 500]
+ },
+ So: {
+ breakpoints: [0.000, 0.034, 0.035, 0.144, 0.145, 0.224, 0.225, 0.304, 0.305, 0.604, 0.605, 0.804, 0.805, 1.004],
+ aq:[0, 50, 51, 100, 101, 150, 151, 200, 201, 300, 301, 400, 401, 500]
+ },
+ No: {
+ breakpoints: [0.65, 1.24, 1.25, 1.64, 1.65, 2.04],
+ aq:[201, 300, 301, 400, 401, 500]
+ }
+};
+
+
+var calculateAQI = function(gasName, concentration) {
+ var bpLow,bpHi;
+ var bpLowIndex, bpHiIndex;
+
+ table[gasName].breakpoints.forEach(function(value, index) {
+ 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;
+ }
+
+ });
+
+
+
+ var airQualityIndex = ((table[gasName].aq[bpHiIndex] - table[gasName].aq[bpLowIndex]) / (bpHi - bpLow)) * (concentration - bpLow) + table[gasName].aq[bpLowIndex];
+
+ return airQualityIndex;
+
+}
+
+
function update() {
var data;
@@ -14,6 +56,14 @@ function update() {
table[2].textContent = data.No;
table[3].textContent = data.So;
+ var indexes = [];
+ indexes.push(calculateAQI("Co", data.Co));
+ indexes.push(calcaulteAQI("No", data.No));
+ indexes.push(calculateAQI("So", data.So));
+
+ var max = Math.max(...indexes);
+ console.log(max);
+
})
.catch(function(error) {
console.log(error);
@@ -25,3 +75,16 @@ function update() {
}
setInterval(update, 60000);
+
+
+
+
+
+
+
+
+
+
+
+
+