mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2025-01-18 02:39:45 +00:00
various fixes
This commit is contained in:
parent
4c1d5e9b03
commit
0ced09dff0
@ -13,6 +13,7 @@ import math
|
||||
import logging
|
||||
import gzip
|
||||
from io import BytesIO
|
||||
import base64
|
||||
|
||||
HOST = os.getenv("ES")
|
||||
|
||||
@ -67,7 +68,7 @@ def predict(event, context):
|
||||
{
|
||||
"range": {
|
||||
"datetime": {
|
||||
"gte": "now-3d",
|
||||
"gte": "now-6h",
|
||||
"lte": "now",
|
||||
"format": "strict_date_optional_time"
|
||||
}
|
||||
@ -114,8 +115,22 @@ def predict(event, context):
|
||||
"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):
|
||||
# get aws creds
|
||||
|
@ -97,10 +97,10 @@ def get_telem(event, context):
|
||||
"3d": (259200, 1200), # 3d, 20m
|
||||
"1d": (86400, 600), # 1d, 10m
|
||||
"12h": (43200, 600), # 1d, 10m
|
||||
"6h": (21600, 60), # 6h, 1m
|
||||
"3h": (10800, 30), # 3h, 10s
|
||||
"1h": (3600, 20),
|
||||
"30m": (1800, 10),
|
||||
"6h": (21600, 120), # 6h, 1m
|
||||
"3h": (10800, 60), # 3h, 10s
|
||||
"1h": (3600, 40),
|
||||
"30m": (1800, 20),
|
||||
"1m": (60, 1),
|
||||
"15s": (15, 1),
|
||||
"0": (0, 1) # for getting a single time point
|
||||
|
@ -264,7 +264,7 @@ def upload(event, context):
|
||||
time_delta_header = event["headers"]["date"]
|
||||
time_delta = (
|
||||
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()
|
||||
except:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user