From 7f86b9f9497ebbd694f715472327d44b35d07c1d Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 19:04:11 +0800 Subject: [PATCH 01/10] add utc timestamp --- fire-cloud/index.js | 16 ++++++++++++---- lambda/lambda_function.py | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fire-cloud/index.js b/fire-cloud/index.js index 5d8a221..1f663ac 100644 --- a/fire-cloud/index.js +++ b/fire-cloud/index.js @@ -91,12 +91,13 @@ async function connectAndSubscribe() { const humidity = messageJson.humidity; const airQualityPpm = messageJson.air; const flameSensorValue = messageJson.flame; + const utcTimestamp = convertEpochToUTC(messageJson.timestamp); const { data, error } = await supabase .from("firecloud") .insert({ node_id: messageJson.id, - timestamp: convertEpochToUTC(messageJson.timestamp), + timestamp: utcTimestamp, temperature: temperature, humidity: humidity, air_quality_ppm: airQualityPpm, @@ -110,7 +111,13 @@ async function connectAndSubscribe() { //invoke lambda function to calculate fire probability and update database const rowId = data[0].id; - const lambdaRes = await invokeAnalytics(nodeId, rowId, temperature, flameSensorValue); + const lambdaRes = await invokeAnalytics( + nodeId, + rowId, + temperature, + flameSensorValue, + utcTimestamp + ); const fireProbability = lambdaRes.fire_probability; @@ -176,7 +183,7 @@ async function publishMessage(topic, message) { } // Function to invoke the Analytics lambda function to calculate the fire probability and update the database -async function invokeAnalytics(nodeId, rowId, temp, flameValue) { +async function invokeAnalytics(nodeId, rowId, temp, flameValue, utcDatetime) { console.log("Invoking lambda function..."); const command = new InvokeCommand({ FunctionName: "greendot-analytics", @@ -186,12 +193,13 @@ async function invokeAnalytics(nodeId, rowId, temp, flameValue) { rowId: rowId, temp: temp, flame: flameValue, + utc_datetime_string: utcDatetime, }), }); const { Payload } = await lambdaClient.send(command); let result = Buffer.from(Payload).toString(); - result = JSON.parse(result) + result = JSON.parse(result); return JSON.parse(result.body); } diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index 32fd6a1..c5338b1 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -15,11 +15,15 @@ def lambda_handler(event, context): rowId = event.get('rowId') temp = event.get('temp') flame = event.get('flame') + utc_datatime = event.get('utc_datetime_string') # get past records from supabase temp_hum_aq_res = None try: - temp_hum_aq_res = supabase.rpc("get_past_records", {"interval_string": f"{PAST_RECORDS_DURATION} minutes", "node_id": nodeId}).execute() + temp_hum_aq_res = supabase.rpc("get_past_records", { + "interval_string": f"{PAST_RECORDS_DURATION} minutes", + "node_id": nodeId, + "utc_datetime_string": utc_datatime}).execute() except Exception as e: print(f"Error getting past records supabase: {e}") From 357a6b41a63ab570c66ce2da8f2a2362b6dbc5ce Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 19:39:21 +0800 Subject: [PATCH 02/10] get past 25 records --- lambda/lambda_function.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index c5338b1..ad48ee9 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -8,7 +8,6 @@ SUPABASE_KEY = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) -PAST_RECORDS_DURATION = 3 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25) def lambda_handler(event, context): nodeId = event.get('nodeId') @@ -21,7 +20,6 @@ def lambda_handler(event, context): temp_hum_aq_res = None try: temp_hum_aq_res = supabase.rpc("get_past_records", { - "interval_string": f"{PAST_RECORDS_DURATION} minutes", "node_id": nodeId, "utc_datetime_string": utc_datatime}).execute() except Exception as e: @@ -111,11 +109,14 @@ def get_air_quality_probability(air_quality_arr): if (len(air_quality_arr) == 0): return 0 - # if every value in the array is above threshold, return 1 - if (all(air_quality > air_quality_threshold for air_quality in air_quality_arr)): - return 1 - else: - return 0 + # check if at least 10 hits above threshold + hits_above_threshold = 0 + for air_quality in air_quality_arr: + if (air_quality > air_quality_threshold): + hits_above_threshold += 1 + if (hits_above_threshold >= 10): + return 1 + return 0 def get_temp_probability(temp): temp_threshold = 40 # highest in sg: 37 + 3 = 40 deg (3 for threshold) From 7995923b8b251992c743405bb6af723a73917d88 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 20:06:48 +0800 Subject: [PATCH 03/10] add checking of std d for calc --- lambda/lambda_function.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index ad48ee9..b385bcc 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -71,7 +71,6 @@ def lambda_handler(event, context): if len(aq_arr) != 0 and r_value != None: fire_probability = get_fire_probability(temp, aq_arr, flame, r_value) - # TODO: update row in supabase table with r_value and fire_probability try: supabase.table('firecloud') \ .update({ @@ -138,17 +137,9 @@ def get_temp_humidity_probability(r_value): return r_ratio def get_r_value(temp_arr, humidity_arr): + if np.std(temp_arr) == 0 or np.std(humidity_arr) == 0: + return None + r_corrcoef = np.corrcoef(temp_arr, humidity_arr, rowvar=False) r_actual = r_corrcoef[0][1] - return r_actual - -# # #TODO: DONT PUSH THIS REMOVE IT BEFORE PUSHING -# if __name__ == "__main__": -# x = lambda_handler({ -# "rowId": 646, -# "temp": 30.9, -# "humidity": 72.4, -# "flame": 0, -# "airQuality": 526.858 -# }, None) -# print(x) \ No newline at end of file + return r_actual \ No newline at end of file From c29abe66c62d3873a7c034568c6d5940a1527c35 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 21:08:12 +0800 Subject: [PATCH 04/10] grafana json model --- grafana.json | 818 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 818 insertions(+) create mode 100644 grafana.json diff --git a/grafana.json b/grafana.json new file mode 100644 index 0000000..6c0e2a7 --- /dev/null +++ b/grafana.json @@ -0,0 +1,818 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 1, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "node_0" + }, + "properties": [ + { + "id": "displayName", + "value": "Node 0" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "node_1" + }, + "properties": [ + { + "id": "displayName", + "value": "Node 1" + } + ] + } + ] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 9, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT \"timestamp\", fire_probability AS node_0 FROM firecloud WHERE node_id = 0 LIMIT 50 ", + "refId": "Node 0 Probability", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "\"timestamp\"", + "type": "functionParameter" + } + ], + "type": "function" + }, + { + "parameters": [ + { + "name": "fire_probability", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50, + "whereJsonTree": { + "children1": [ + { + "id": "8989ba8a-89ab-4cde-b012-318c10ba722f", + "properties": { + "field": "node_id", + "fieldSrc": "field", + "operator": "equal", + "value": [0], + "valueSrc": ["value"], + "valueType": ["number"] + }, + "type": "rule" + } + ], + "id": "8aa8aab9-89ab-4cde-b012-318c10b67cbe", + "type": "group" + }, + "whereString": "node_id = 0" + }, + "table": "firecloud" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "hide": false, + "rawQuery": true, + "rawSql": "SELECT \"timestamp\", fire_probability AS node_1 FROM firecloud WHERE node_id = 1 LIMIT 50 ", + "refId": "Node 1 Probability", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "\"timestamp\"", + "type": "functionParameter" + } + ], + "type": "function" + }, + { + "parameters": [ + { + "name": "fire_probability", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50, + "whereJsonTree": { + "children1": [ + { + "id": "ba8889ab-cdef-4012-b456-718c10be5f72", + "properties": { + "field": "node_id", + "fieldSrc": "field", + "operator": "equal", + "value": [1], + "valueSrc": ["value"], + "valueType": ["number"] + }, + "type": "rule" + } + ], + "id": "8aa8aab9-89ab-4cde-b012-318c10b67cbe", + "type": "group" + }, + "whereString": "node_id = 1" + }, + "table": "firecloud" + } + ], + "title": "Probability", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 11 + }, + "id": 1, + "panels": [], + "title": "Node 0", + "type": "row" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 1, + "min": 0, + "noValue": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 0.3 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 8, + "x": 0, + "y": 12 + }, + "id": 3, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": true, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "has_fire", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "table": "fire_status" + } + ], + "title": "Probability of Fire", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Flame Sensor Value", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "options": { + "0": { + "color": "green", + "index": 0, + "text": "No Flame" + }, + "1": { + "color": "red", + "index": 1, + "text": "Flame Detected" + } + }, + "type": "value" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 10, + "y": 12 + }, + "id": 5, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n flame_sensor_value\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Flame Sensor", + "type": "stat" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Presence of CO2 in Air (ppm)", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 547, + "min": 10, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 350 + } + ] + }, + "unit": "ppm" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 14, + "y": 12 + }, + "id": 6, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n air_quality_ppm\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Air Quality Sensor", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 43, + "min": 15, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 39 + } + ] + }, + "unit": "celsius" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 8, + "y": 18 + }, + "id": 2, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n temperature\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Temperature", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Humidity Level", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": false, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "#EAB839", + "value": 40 + }, + { + "color": "green", + "value": 65 + } + ] + }, + "unit": "humidity" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 12, + "y": 18 + }, + "id": 4, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n humidity\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "table": "firecloud" + } + ], + "title": "Humidity", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 1, + "min": -1.5, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "green", + "value": -1.18 + }, + { + "color": "red", + "value": -0.89 + }, + { + "color": "green", + "value": -0.6 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 16, + "y": 18 + }, + "id": 7, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n r_value\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Temperature & Humidity R-value", + "type": "gauge" + } + ], + "refresh": false, + "schemaVersion": 38, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "2023-11-27T04:06:40.480Z", + "to": "2023-11-27T16:06:40.480Z" + }, + "timepicker": {}, + "timezone": "", + "title": "GreenDot Dashboard", + "uid": "f3bbb846-51ad-47ed-b928-40d06727f5ad", + "version": 18, + "weekStart": "" +} From 23f365c10a49d9f0c3bb3d06c86f1e4165ff397a Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 21:24:16 +0800 Subject: [PATCH 05/10] update grafana json --- grafana.json | 659 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 601 insertions(+), 58 deletions(-) diff --git a/grafana.json b/grafana.json index 6c0e2a7..729eecb 100644 --- a/grafana.json +++ b/grafana.json @@ -263,6 +263,549 @@ "x": 0, "y": 11 }, + "id": 11, + "panels": [], + "title": "Node 1", + "type": "row" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 1, + "min": 0, + "noValue": "null", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 0.3 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 12, + "w": 8, + "x": 0, + "y": 12 + }, + "id": 12, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": true, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "has_fire", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "table": "fire_status" + } + ], + "title": "Probability of Fire", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Flame Sensor Value", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "options": { + "0": { + "color": "green", + "index": 0, + "text": "No Flame" + }, + "1": { + "color": "red", + "index": 1, + "text": "Flame Detected" + } + }, + "type": "value" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 8, + "y": 12 + }, + "id": 5, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n flame_sensor_value\nfrom\n firecloud\nwhere\n node_id = 1\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Flame Sensor", + "type": "stat" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Humidity Level", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": false, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + }, + { + "color": "#EAB839", + "value": 40 + }, + { + "color": "green", + "value": 65 + } + ] + }, + "unit": "humidity" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 12, + "y": 12 + }, + "id": 16, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n humidity\nfrom\n firecloud\nwhere\n node_id = 1\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "table": "firecloud" + } + ], + "title": "Humidity", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 43, + "min": 15, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 39 + } + ] + }, + "unit": "celsius" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 16, + "y": 12 + }, + "id": 17, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n temperature\nfrom\n firecloud\nwhere\n node_id = 1\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Temperature", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 1, + "min": -1.5, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "green", + "value": -1.18 + }, + { + "color": "red", + "value": -0.89 + }, + { + "color": "green", + "value": -0.6 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 8, + "y": 18 + }, + "id": 14, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n r_value\nfrom\n firecloud\nwhere\n node_id = 1\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Temperature & Humidity R-value", + "type": "gauge" + }, + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "description": "Current Presence of CO2 in Air (ppm)", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 547, + "min": 10, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 350 + } + ] + }, + "unit": "ppm" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 12, + "y": 18 + }, + "id": 15, + "options": { + "minVizHeight": 75, + "minVizWidth": 75, + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "select\n air_quality_ppm\nfrom\n firecloud\nwhere\n node_id = 1\norder by\n timestamp desc\nlimit\n 1;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Air Quality Sensor", + "type": "gauge" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 24 + }, "id": 1, "panels": [], "title": "Node 0", @@ -299,10 +842,10 @@ "overrides": [] }, "gridPos": { - "h": 11, + "h": 12, "w": 8, "x": 0, - "y": 12 + "y": 25 }, "id": 3, "options": { @@ -400,10 +943,10 @@ "gridPos": { "h": 6, "w": 4, - "x": 10, - "y": 12 + "x": 8, + "y": 25 }, - "id": 5, + "id": 13, "options": { "colorMode": "value", "graphMode": "area", @@ -456,39 +999,44 @@ "type": "postgres", "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" }, - "description": "Current Presence of CO2 in Air (ppm)", + "description": "Current Humidity Level", "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, + "fieldMinMax": false, "mappings": [], - "max": 547, - "min": 10, + "max": 100, + "min": 0, "thresholds": { "mode": "absolute", "steps": [ { - "color": "green", + "color": "red", "value": null }, { - "color": "red", - "value": 350 + "color": "#EAB839", + "value": 40 + }, + { + "color": "green", + "value": 65 } ] }, - "unit": "ppm" + "unit": "humidity" }, "overrides": [] }, "gridPos": { "h": 6, "w": 4, - "x": 14, - "y": 12 + "x": 12, + "y": 25 }, - "id": 6, + "id": 4, "options": { "minVizHeight": 75, "minVizWidth": 75, @@ -511,7 +1059,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "select\n air_quality_ppm\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "rawSql": "select\n humidity\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", "refId": "A", "sql": { "columns": [ @@ -529,10 +1077,11 @@ } ], "limit": 50 - } + }, + "table": "firecloud" } ], - "title": "Air Quality Sensor", + "title": "Humidity", "type": "gauge" }, { @@ -568,8 +1117,8 @@ "gridPos": { "h": 6, "w": 4, - "x": 8, - "y": 18 + "x": 16, + "y": 25 }, "id": 2, "options": { @@ -623,44 +1172,45 @@ "type": "postgres", "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" }, - "description": "Current Humidity Level", "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, - "fieldMinMax": false, "mappings": [], - "max": 100, - "min": 0, + "max": 1, + "min": -1.5, "thresholds": { "mode": "absolute", "steps": [ { - "color": "red", + "color": "green", "value": null }, { - "color": "#EAB839", - "value": 40 + "color": "green", + "value": -1.18 + }, + { + "color": "red", + "value": -0.89 }, { "color": "green", - "value": 65 + "value": -0.6 } ] - }, - "unit": "humidity" + } }, "overrides": [] }, "gridPos": { "h": 6, "w": 4, - "x": 12, - "y": 18 + "x": 8, + "y": 31 }, - "id": 4, + "id": 7, "options": { "minVizHeight": 75, "minVizWidth": 75, @@ -683,7 +1233,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "select\n humidity\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "rawSql": "select\n r_value\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", "refId": "A", "sql": { "columns": [ @@ -701,11 +1251,10 @@ } ], "limit": 50 - }, - "table": "firecloud" + } } ], - "title": "Humidity", + "title": "Temperature & Humidity R-value", "type": "gauge" }, { @@ -713,14 +1262,15 @@ "type": "postgres", "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" }, + "description": "Current Presence of CO2 in Air (ppm)", "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], - "max": 1, - "min": -1.5, + "max": 547, + "min": 10, "thresholds": { "mode": "absolute", "steps": [ @@ -728,30 +1278,23 @@ "color": "green", "value": null }, - { - "color": "green", - "value": -1.18 - }, { "color": "red", - "value": -0.89 - }, - { - "color": "green", - "value": -0.6 + "value": 350 } ] - } + }, + "unit": "ppm" }, "overrides": [] }, "gridPos": { "h": 6, "w": 4, - "x": 16, - "y": 18 + "x": 12, + "y": 31 }, - "id": 7, + "id": 6, "options": { "minVizHeight": 75, "minVizWidth": 75, @@ -774,7 +1317,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "select\n r_value\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", + "rawSql": "select\n air_quality_ppm\nfrom\n firecloud\nwhere\n node_id = 0\norder by\n timestamp desc\nlimit\n 1;", "refId": "A", "sql": { "columns": [ @@ -795,24 +1338,24 @@ } } ], - "title": "Temperature & Humidity R-value", + "title": "Air Quality Sensor", "type": "gauge" } ], - "refresh": false, + "refresh": "", "schemaVersion": 38, "tags": [], "templating": { "list": [] }, "time": { - "from": "2023-11-27T04:06:40.480Z", - "to": "2023-11-27T16:06:40.480Z" + "from": "2023-11-27T11:48:26.784Z", + "to": "2023-11-27T12:13:06.918Z" }, "timepicker": {}, "timezone": "", "title": "GreenDot Dashboard", "uid": "f3bbb846-51ad-47ed-b928-40d06727f5ad", - "version": 18, + "version": 29, "weekStart": "" } From 460b55ff808ef7c025c8d1e0a819e3ff45ad0d09 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 21:31:08 +0800 Subject: [PATCH 06/10] update grafana --- grafana.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/grafana.json b/grafana.json index 729eecb..4697de9 100644 --- a/grafana.json +++ b/grafana.json @@ -134,7 +134,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "SELECT \"timestamp\", fire_probability AS node_0 FROM firecloud WHERE node_id = 0 LIMIT 50 ", + "rawSql": "SELECT \"timestamp\", fire_probability AS node_0 FROM firecloud WHERE node_id = 0 order by\n timestamp desc LIMIT 50 ", "refId": "Node 0 Probability", "sql": { "columns": [ @@ -197,7 +197,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT \"timestamp\", fire_probability AS node_1 FROM firecloud WHERE node_id = 1 LIMIT 50 ", + "rawSql": "SELECT \"timestamp\", fire_probability AS node_1 FROM firecloud WHERE node_id = 1 order by\n timestamp desc LIMIT 50 ", "refId": "Node 1 Probability", "sql": { "columns": [ @@ -327,7 +327,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", + "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nwhere\n node_id = 1\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", "refId": "A", "sql": { "columns": [ @@ -870,7 +870,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", + "rawSql": "SELECT\n fire_probability,\n timestamp\nFROM\n firecloud\nwhere\n node_id = 0\nORDER BY\n timestamp DESC\nLIMIT\n 1\n", "refId": "A", "sql": { "columns": [ @@ -1342,20 +1342,20 @@ "type": "gauge" } ], - "refresh": "", + "refresh": false, "schemaVersion": 38, "tags": [], "templating": { "list": [] }, "time": { - "from": "2023-11-27T11:48:26.784Z", - "to": "2023-11-27T12:13:06.918Z" + "from": "2023-11-27T12:15:23.454Z", + "to": "2023-11-27T12:19:27.019Z" }, "timepicker": {}, "timezone": "", "title": "GreenDot Dashboard", "uid": "f3bbb846-51ad-47ed-b928-40d06727f5ad", - "version": 29, + "version": 32, "weekStart": "" } From 177e11698abb41333d0002520f6371ce3605d6f1 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 21:49:29 +0800 Subject: [PATCH 07/10] fix fire prob calculation --- lambda/lambda_function.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index b385bcc..9dd410c 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -38,7 +38,7 @@ def lambda_handler(event, context): humidity_arr = [] if temp_hum_aq_data.get("all_humidity", None) is None else temp_hum_aq_data.get("all_humidity") aq_arr = [] if temp_hum_aq_data.get("all_air_quality_ppm", None) is None else temp_hum_aq_data.get("all_air_quality_ppm") - r_value = None + r_value = 0 fire_probability = 0 if len(temp_arr) >= 25 and len(humidity_arr) >= 25: @@ -68,8 +68,7 @@ def lambda_handler(event, context): }) } - if len(aq_arr) != 0 and r_value != None: - fire_probability = get_fire_probability(temp, aq_arr, flame, r_value) + fire_probability = get_fire_probability(temp, aq_arr, flame, r_value) try: supabase.table('firecloud') \ @@ -138,7 +137,7 @@ def get_temp_humidity_probability(r_value): def get_r_value(temp_arr, humidity_arr): if np.std(temp_arr) == 0 or np.std(humidity_arr) == 0: - return None + return 0 r_corrcoef = np.corrcoef(temp_arr, humidity_arr, rowvar=False) r_actual = r_corrcoef[0][1] From 937707cf028dfd2ceb67f70e22cecbfcbad73693 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Wed, 29 Nov 2023 16:18:03 +0800 Subject: [PATCH 08/10] fix fire prob cdn --- fire-cloud/index.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fire-cloud/index.js b/fire-cloud/index.js index 1f663ac..888f936 100644 --- a/fire-cloud/index.js +++ b/fire-cloud/index.js @@ -139,20 +139,24 @@ async function validateAndPublishFireMessage(nodeId, fireProbability) { } //if fire is dying down - if (fireStatuses[nodeId] === 1 && fireProbability < fireProbabilityThreshold) { - if (noFireDurations[nodeId] === null) { - noFireDurations[nodeId] = new Date().getTime(); - } else { - const currentTime = new Date().getTime(); - const timeDiff = currentTime - noFireDurations[nodeId]; - const timeDiffInMinutes = timeDiff / 60000; - - // if status has been 0 for more than 5 minutes -> there is no more fire -> publish status 0 - if (timeDiffInMinutes > 5) { - await updateAndPublishFireMessage(FLAME_PRESENCE_TOPIC, 0); - fireStatuses[nodeId] = 0; - noFireDurations[nodeId] = null; + if (fireStatuses[nodeId] === 1) { + if (fireProbability < fireProbabilityThreshold) { + if (noFireDurations[nodeId] === null) { + noFireDurations[nodeId] = new Date().getTime(); + } else { + const currentTime = new Date().getTime(); + const timeDiff = currentTime - noFireDurations[nodeId]; + const timeDiffInMinutes = timeDiff / 60000; + + // if status has been 0 for more than 5 minutes -> there is no more fire -> publish status 0 + if (timeDiffInMinutes > 5) { + await updateAndPublishFireMessage(FLAME_PRESENCE_TOPIC, 0); + fireStatuses[nodeId] = 0; + noFireDurations[nodeId] = null; + } } + } else { + noFireDurations[nodeId] = null; } } } From bdefdbb6ec2f4df7ddb05a3b8bc7d20072683152 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Wed, 29 Nov 2023 17:11:53 +0800 Subject: [PATCH 09/10] update grafana and lambda --- grafana.json | 215 +++++++++++++++++++++++++------------- lambda/lambda_function.py | 4 +- 2 files changed, 144 insertions(+), 75 deletions(-) diff --git a/grafana.json b/grafana.json index 4697de9..9f67525 100644 --- a/grafana.json +++ b/grafana.json @@ -25,7 +25,7 @@ { "datasource": { "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + "uid": "fdcddc6a-cd72-4e41-b7a7-3bbc5cccd401" }, "fieldConfig": { "defaults": { @@ -107,8 +107,8 @@ ] }, "gridPos": { - "h": 11, - "w": 12, + "h": 13, + "w": 24, "x": 0, "y": 0 }, @@ -134,7 +134,7 @@ "editorMode": "code", "format": "table", "rawQuery": true, - "rawSql": "SELECT \"timestamp\", fire_probability AS node_0 FROM firecloud WHERE node_id = 0 order by\n timestamp desc LIMIT 50 ", + "rawSql": "SELECT \"timestamp\", fire_probability AS node_0 FROM firecloud WHERE node_id = 0 order by\n timestamp desc", "refId": "Node 0 Probability", "sql": { "columns": [ @@ -197,7 +197,7 @@ "format": "table", "hide": false, "rawQuery": true, - "rawSql": "SELECT \"timestamp\", fire_probability AS node_1 FROM firecloud WHERE node_id = 1 order by\n timestamp desc LIMIT 50 ", + "rawSql": "SELECT \"timestamp\", fire_probability AS node_1 FROM firecloud WHERE node_id = 1 order by\n timestamp desc", "refId": "Node 1 Probability", "sql": { "columns": [ @@ -255,13 +255,113 @@ "title": "Probability", "type": "timeseries" }, + { + "datasource": { + "type": "postgres", + "uid": "fdcddc6a-cd72-4e41-b7a7-3bbc5cccd401" + }, + "description": "Current Flame Sensor Value", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "options": { + "match": "false", + "result": { + "color": "green", + "index": 0, + "text": "Normal" + } + }, + "type": "special" + }, + { + "options": { + "match": "true", + "result": { + "color": "red", + "index": 1, + "text": "High Alert" + } + }, + "type": "special" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 1, + "y": 13 + }, + "id": 18, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "/^has_fire$/", + "values": false + }, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "10.2.2", + "targets": [ + { + "datasource": { + "type": "postgres", + "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT has_fire FROM fire_status WHERE id = 1", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "has_fire", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [], + "limit": 50 + }, + "table": "fire_status" + } + ], + "title": "Alert Status", + "type": "stat" + }, { "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, - "y": 11 + "y": 19 }, "id": 11, "panels": [], @@ -269,10 +369,7 @@ "type": "row" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -302,7 +399,7 @@ "h": 12, "w": 8, "x": 0, - "y": 12 + "y": 20 }, "id": 12, "options": { @@ -360,7 +457,7 @@ { "datasource": { "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" + "uid": "fdcddc6a-cd72-4e41-b7a7-3bbc5cccd401" }, "description": "Current Flame Sensor Value", "fieldConfig": { @@ -401,7 +498,7 @@ "h": 6, "w": 4, "x": 8, - "y": 12 + "y": 20 }, "id": 5, "options": { @@ -452,10 +549,7 @@ "type": "stat" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "description": "Current Humidity Level", "fieldConfig": { "defaults": { @@ -491,7 +585,7 @@ "h": 6, "w": 4, "x": 12, - "y": 12 + "y": 20 }, "id": 16, "options": { @@ -542,10 +636,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -575,7 +666,7 @@ "h": 6, "w": 4, "x": 16, - "y": 12 + "y": 20 }, "id": 17, "options": { @@ -625,10 +716,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -663,9 +751,9 @@ }, "gridPos": { "h": 6, - "w": 4, + "w": 5, "x": 8, - "y": 18 + "y": 26 }, "id": 14, "options": { @@ -715,10 +803,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "description": "Current Presence of CO2 in Air (ppm)", "fieldConfig": { "defaults": { @@ -748,8 +833,8 @@ "gridPos": { "h": 6, "w": 4, - "x": 12, - "y": 18 + "x": 13, + "y": 26 }, "id": 15, "options": { @@ -804,7 +889,7 @@ "h": 1, "w": 24, "x": 0, - "y": 24 + "y": 32 }, "id": 1, "panels": [], @@ -812,10 +897,7 @@ "type": "row" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -845,7 +927,7 @@ "h": 12, "w": 8, "x": 0, - "y": 25 + "y": 33 }, "id": 3, "options": { @@ -901,10 +983,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "description": "Current Flame Sensor Value", "fieldConfig": { "defaults": { @@ -944,7 +1023,7 @@ "h": 6, "w": 4, "x": 8, - "y": 25 + "y": 33 }, "id": 13, "options": { @@ -995,10 +1074,7 @@ "type": "stat" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "description": "Current Humidity Level", "fieldConfig": { "defaults": { @@ -1034,7 +1110,7 @@ "h": 6, "w": 4, "x": 12, - "y": 25 + "y": 33 }, "id": 4, "options": { @@ -1085,10 +1161,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -1118,7 +1191,7 @@ "h": 6, "w": 4, "x": 16, - "y": 25 + "y": 33 }, "id": 2, "options": { @@ -1168,10 +1241,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -1206,9 +1276,9 @@ }, "gridPos": { "h": 6, - "w": 4, + "w": 5, "x": 8, - "y": 31 + "y": 39 }, "id": 7, "options": { @@ -1258,10 +1328,7 @@ "type": "gauge" }, { - "datasource": { - "type": "postgres", - "uid": "b5236ea3-0347-4e2b-a627-0fbbe68b1304" - }, + "datasource": {}, "description": "Current Presence of CO2 in Air (ppm)", "fieldConfig": { "defaults": { @@ -1291,8 +1358,8 @@ "gridPos": { "h": 6, "w": 4, - "x": 12, - "y": 31 + "x": 13, + "y": 39 }, "id": 6, "options": { @@ -1342,20 +1409,22 @@ "type": "gauge" } ], - "refresh": false, + "refresh": "5s", "schemaVersion": 38, "tags": [], "templating": { "list": [] }, "time": { - "from": "2023-11-27T12:15:23.454Z", - "to": "2023-11-27T12:19:27.019Z" + "from": "now-15m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": ["5s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"] }, - "timepicker": {}, "timezone": "", "title": "GreenDot Dashboard", "uid": "f3bbb846-51ad-47ed-b928-40d06727f5ad", - "version": 32, + "version": 23, "weekStart": "" } diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index 9dd410c..ec485a0 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -107,12 +107,12 @@ def get_air_quality_probability(air_quality_arr): if (len(air_quality_arr) == 0): return 0 - # check if at least 10 hits above threshold + # check if at least 10 hits above threshold demo: 3 hits hits_above_threshold = 0 for air_quality in air_quality_arr: if (air_quality > air_quality_threshold): hits_above_threshold += 1 - if (hits_above_threshold >= 10): + if (hits_above_threshold >= 3): return 1 return 0 From e732f7cddaafb7ee76a550fe17e274ebf789c3ca Mon Sep 17 00:00:00 2001 From: Fruittips Date: Thu, 30 Nov 2023 19:12:19 +0800 Subject: [PATCH 10/10] empty push --- fire-cloud/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire-cloud/index.js b/fire-cloud/index.js index 888f936..87ec01f 100644 --- a/fire-cloud/index.js +++ b/fire-cloud/index.js @@ -138,7 +138,7 @@ async function validateAndPublishFireMessage(nodeId, fireProbability) { fireStatuses[nodeId] = 1; } - //if fire is dying down + //if fire is dying down aa if (fireStatuses[nodeId] === 1) { if (fireProbability < fireProbabilityThreshold) { if (noFireDurations[nodeId] === null) {