mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2024-12-19 05:07:55 +00:00
recovery fixes
This commit is contained in:
parent
b44566f935
commit
a99f6de735
@ -139,20 +139,23 @@ def put(event, context):
|
|||||||
|
|
||||||
sonde_last_data = getSonde(recovered["serial"])
|
sonde_last_data = getSonde(recovered["serial"])
|
||||||
|
|
||||||
|
if recovered["serial"] == "":
|
||||||
|
return {"statusCode": 400, "body": json.dumps({"message": "serial cannot be empty"})}
|
||||||
|
|
||||||
if len(sonde_last_data) == 0:
|
if len(sonde_last_data) == 0:
|
||||||
return {"statusCode": 400, "body": json.dumps({"message":"serial not found in db"})}
|
return {"statusCode": 400, "body": json.dumps({"message": "serial not found in db"})}
|
||||||
|
|
||||||
already_recovered = getRecovered(recovered["serial"])
|
already_recovered = getRecovered(recovered["serial"])
|
||||||
if len(already_recovered) != 0:
|
if len(already_recovered) != 0:
|
||||||
recovered_by = already_recovered[0]['fields']['recovered_by.keyword'][0]
|
recovered_by = already_recovered[0]['fields']['recovered_by.keyword'][0]
|
||||||
return {"statusCode": 400, "body": json.dumps({"message":f"Already recovered by {recovered_by}"})}
|
return {"statusCode": 400, "body": json.dumps({"message": f"Already recovered by {recovered_by}"})}
|
||||||
|
|
||||||
recovered['position'] = [recovered['lon'], recovered['lat']]
|
recovered['position'] = [recovered['lon'], recovered['lat']]
|
||||||
|
|
||||||
result = es_request(recovered, "recovered/_doc", "POST")
|
result = es_request(recovered, "recovered/_doc", "POST")
|
||||||
|
|
||||||
# add in elasticsearch extra position field
|
# add in elasticsearch extra position field
|
||||||
return {"statusCode": 200, "body": json.dumps({"message":"telm logged. Have a good day ^_^"})}
|
return {"statusCode": 200, "body": json.dumps({"message": "telm logged. Have a good day ^_^"})}
|
||||||
|
|
||||||
|
|
||||||
def get(event, context):
|
def get(event, context):
|
||||||
@ -213,10 +216,47 @@ def get(event, context):
|
|||||||
"bool": {
|
"bool": {
|
||||||
"filter": filters
|
"filter": filters
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"aggs": {
|
||||||
|
"2": {
|
||||||
|
"terms": {
|
||||||
|
"field": "serial.keyword",
|
||||||
|
"order": {
|
||||||
|
"2-orderAgg": "desc"
|
||||||
|
},
|
||||||
|
"size": 500
|
||||||
|
},
|
||||||
|
"aggs": {
|
||||||
|
"2-orderAgg": {
|
||||||
|
"max": {
|
||||||
|
"field": "datetime"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1": {
|
||||||
|
"top_hits": {
|
||||||
|
"_source": True,
|
||||||
|
"size": 1,
|
||||||
|
"sort": [
|
||||||
|
{
|
||||||
|
"recovered": {
|
||||||
|
"order": "desc"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"datetime": {
|
||||||
|
"order": "desc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
results = es_request(query, "recovered*/_search", "POST")
|
results = es_request(query, "recovered*/_search", "POST")
|
||||||
output = [x["_source"] for x in results['hits']['hits']]
|
output = [x['1']['hits']['hits'][0]["_source"]
|
||||||
|
for x in results['aggregations']['2']['buckets']]
|
||||||
return {"statusCode": 200, "body": json.dumps(output)}
|
return {"statusCode": 200, "body": json.dumps(output)}
|
||||||
|
|
||||||
|
|
||||||
@ -267,8 +307,8 @@ if __name__ == "__main__":
|
|||||||
"recovered": True,
|
"recovered": True,
|
||||||
"recovered_by": "string",
|
"recovered_by": "string",
|
||||||
"description": "string"
|
"description": "string"
|
||||||
}),
|
}),
|
||||||
"isBase64Encoded": False,
|
"isBase64Encoded": False,
|
||||||
}
|
}
|
||||||
print(put(payload, {}))
|
# print(put(payload, {}))
|
||||||
# print(get(payload,{}))
|
print(get(payload, {}))
|
||||||
|
Loading…
Reference in New Issue
Block a user