Skip to content

Commit

Permalink
update lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
Fruittips committed Nov 27, 2023
1 parent f773d91 commit c0c32dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
SUPABASE_KEY = os.environ.get("SUPABASE_KEY")

supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
PAST_RECORDS_DURATION = 5 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25)
PAST_RECORDS_DURATION = 13 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25)

def lambda_handler(event, context):
rowId = event.get('rowId')
Expand Down Expand Up @@ -37,13 +37,24 @@ def lambda_handler(event, context):

r_value = None
fire_probability = 0
if len(temp_arr) != 0 or len(humidity_arr) != 0:

if len(temp_arr) >= 0 and len(humidity_arr) > 0:
r_value = get_r_value(temp_arr, humidity_arr)

# if less than 25 records, dont calculate r value and return default fire probability
else:
return json.dumps({
'statusCode': 200,
'body': json.dumps({
'fire_probability': fire_probability,
'r_value': r_value,
})
})

if len(aq_arr) != 0 and r_value != None:
fire_probability = get_fire_probability(temp, aq_arr, flame, r_value)

#update row in supabase table with r_value and fire_probability
# TODO: update row in supabase table with r_value and fire_probability
try:
data, count = supabase.table('firecloud') \
.update({
Expand Down
2 changes: 1 addition & 1 deletion node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
_DEVICE_NAME = _DEVICE_NAME_PREFIX + str(_NODE_ID)

# Sampling intervals
_SAMPLING_INTERVAL_LOW = 60 # change to 30s in demo
_SAMPLING_INTERVAL_LOW = 30 # Actual: 60s, Demo: 30s
_SAMPLING_INTERVAL_HIGH = 5

# Frequencies
Expand Down

0 comments on commit c0c32dc

Please sign in to comment.