mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2024-12-19 21:27:55 +00:00
add tile insights
This commit is contained in:
parent
2c5811609d
commit
4e950ec12f
@ -433,6 +433,8 @@ def predict(event, context):
|
||||
async def predict_async(event, context):
|
||||
sem = asyncio.Semaphore(5)
|
||||
path = "telm-*/_search"
|
||||
interval = 10
|
||||
lag = 3 # how many samples to use
|
||||
payload = {
|
||||
"aggs": {
|
||||
"2": {
|
||||
@ -447,7 +449,7 @@ async def predict_async(event, context):
|
||||
"3": {
|
||||
"date_histogram": {
|
||||
"field": "datetime",
|
||||
"fixed_interval": "5s"
|
||||
"fixed_interval": f"{interval}s"
|
||||
},
|
||||
"aggs": {
|
||||
"1": {
|
||||
@ -578,7 +580,7 @@ async def predict_async(event, context):
|
||||
serials[x['key']] = {
|
||||
"alt": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['1']['hits']['hits'][0]['fields']['alt'][0],
|
||||
"position": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['5']['hits']['hits'][0]['fields']['position'][0].split(","),
|
||||
"rate": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['4']['value']/25, # as we bucket for every 5 seconds with a lag of 5
|
||||
"rate": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['4']['value']/(lag*interval), # as we bucket for every 5 seconds with a lag of 5
|
||||
"time": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['key_as_string'],
|
||||
"type": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['5']['hits']['hits'][0]["_source"]["type"],
|
||||
"subtype": sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['5']['hits']['hits'][0]["_source"]["subtype"] if "subtype" in sorted(x['3']['buckets'], key=lambda k: k['key_as_string'])[-1]['5']['hits']['hits'][0]["_source"] else None
|
||||
|
26
lambda/tile_counts/__init__.py
Normal file
26
lambda/tile_counts/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
import json
|
||||
import zlib
|
||||
import base64
|
||||
import datetime
|
||||
from email.utils import parsedate
|
||||
import os
|
||||
import base64
|
||||
import gzip
|
||||
from io import BytesIO
|
||||
import boto3
|
||||
|
||||
|
||||
def lambda_handler(event, context):
|
||||
if "isBase64Encoded" in event and event["isBase64Encoded"] == True:
|
||||
event["body"] = base64.b64decode(event["body"])
|
||||
if (
|
||||
"content-encoding" in event["headers"]
|
||||
and event["headers"]["content-encoding"] == "gzip"
|
||||
):
|
||||
event["body"] = zlib.decompress(event["body"], 16 + zlib.MAX_WBITS)
|
||||
try:
|
||||
payload = json.loads(event["body"])
|
||||
except:
|
||||
return {"statusCode": 400, "body": "JSON decode issue"}
|
||||
print(json.dumps(payload))
|
||||
|
53
lambda/tile_counts/__main__.py
Normal file
53
lambda/tile_counts/__main__.py
Normal file
@ -0,0 +1,53 @@
|
||||
from . import *
|
||||
payload = {
|
||||
"version": "2.0",
|
||||
"routeKey": "PUT /tiles/count",
|
||||
"rawPath": "/tiles/count",
|
||||
"rawQueryString": "",
|
||||
"headers": {
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"content-length": "2135",
|
||||
"content-type": "application/json",
|
||||
"host": "api.v2.sondehub.org",
|
||||
"user-agent": "autorx-1.4.1-beta4",
|
||||
"x-amzn-trace-id": "Root=1-6015f571-6aef2e73165042d53fcc317a",
|
||||
"x-forwarded-for": "103.107.130.22",
|
||||
"x-forwarded-port": "443",
|
||||
"x-forwarded-proto": "https",
|
||||
"date": "Sun, 31 Jan 2021 00:21:45 GMT",
|
||||
},
|
||||
"requestContext": {
|
||||
"accountId": "143841941773",
|
||||
"apiId": "r03szwwq41",
|
||||
"domainName": "api.v2.sondehub.org",
|
||||
"domainPrefix": "api",
|
||||
"http": {
|
||||
"method": "PUT",
|
||||
"path": "/tiles/count",
|
||||
"protocol": "HTTP/1.1",
|
||||
"sourceIp": "103.107.130.22",
|
||||
"userAgent": "autorx-1.4.1-beta4",
|
||||
},
|
||||
"requestId": "Z_NJvh0RoAMEJaw=",
|
||||
"routeKey": "PUT /tiles/count",
|
||||
"stage": "$default",
|
||||
"time": "31/Jan/2021:00:10:25 +0000",
|
||||
"timeEpoch": 1612051825409,
|
||||
},
|
||||
"body": """
|
||||
{
|
||||
"client": "SondeHub-Tracker-1581027979",
|
||||
"tile_loads": {
|
||||
"Mapnik": 82,
|
||||
"DarkMatter": 0,
|
||||
"WorldImagery": 0,
|
||||
"Terrain": 0,
|
||||
"Voyager": 0,
|
||||
"OpenTopoMap": 0
|
||||
}
|
||||
}
|
||||
""",
|
||||
"isBase64Encoded": False,
|
||||
}
|
||||
print(lambda_handler(payload, {}))
|
Loading…
Reference in New Issue
Block a user