various fixes

This commit is contained in:
Michaela 2021-09-17 23:50:36 +10:00
parent 4c1d5e9b03
commit 0ced09dff0
3 changed files with 23 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import math
import logging import logging
import gzip import gzip
from io import BytesIO from io import BytesIO
import base64
HOST = os.getenv("ES") HOST = os.getenv("ES")
@ -67,7 +68,7 @@ def predict(event, context):
{ {
"range": { "range": {
"datetime": { "datetime": {
"gte": "now-3d", "gte": "now-6h",
"lte": "now", "lte": "now",
"format": "strict_date_optional_time" "format": "strict_date_optional_time"
} }
@ -114,8 +115,22 @@ def predict(event, context):
"data": json.dumps(data['data']) "data": json.dumps(data['data'])
}) })
return json.dumps(output) compressed = BytesIO()
with gzip.GzipFile(fileobj=compressed, mode='w') as f:
json_response = json.dumps(output)
f.write(json_response.encode('utf-8'))
gzippedResponse = compressed.getvalue()
return {
"body": base64.b64encode(gzippedResponse).decode(),
"isBase64Encoded": True,
"statusCode": 200,
"headers": {
"Content-Encoding": "gzip",
"content-type": "application/json"
}
}
def es_request(payload, path, method): def es_request(payload, path, method):
# get aws creds # get aws creds

View File

@ -97,10 +97,10 @@ def get_telem(event, context):
"3d": (259200, 1200), # 3d, 20m "3d": (259200, 1200), # 3d, 20m
"1d": (86400, 600), # 1d, 10m "1d": (86400, 600), # 1d, 10m
"12h": (43200, 600), # 1d, 10m "12h": (43200, 600), # 1d, 10m
"6h": (21600, 60), # 6h, 1m "6h": (21600, 120), # 6h, 1m
"3h": (10800, 30), # 3h, 10s "3h": (10800, 60), # 3h, 10s
"1h": (3600, 20), "1h": (3600, 40),
"30m": (1800, 10), "30m": (1800, 20),
"1m": (60, 1), "1m": (60, 1),
"15s": (15, 1), "15s": (15, 1),
"0": (0, 1) # for getting a single time point "0": (0, 1) # for getting a single time point

View File

@ -264,7 +264,7 @@ def upload(event, context):
time_delta_header = event["headers"]["date"] time_delta_header = event["headers"]["date"]
time_delta = ( time_delta = (
datetime.datetime(*parsedate(time_delta_header)[:7]) datetime.datetime(*parsedate(time_delta_header)[:7])
- datetime.datetime.utcnow() - datetime.datetime.utcnow() # TODO we should use the request context datetime here so that timedelta works for chunked requests
).total_seconds() ).total_seconds()
except: except:
pass pass