[test] add get_parsed_bbox_points test case, refactor test structure
Browse files- src/app.py +2 -136
- src/io/lambda_helpers.py +100 -0
- src/utilities/type_hints.py +38 -1
- tests/events/get_parsed_bbox_points.json +208 -0
- tests/io/test_coordinates_pixel_conversion.py +7 -30
- tests/io/test_lambda_helpers.py +5 -0
- tests/io/test_utilities.py +26 -0
src/app.py
CHANGED
|
@@ -1,120 +1,11 @@
|
|
| 1 |
-
import json
|
| 2 |
import time
|
| 3 |
from http import HTTPStatus
|
| 4 |
-
from typing import Dict, List
|
| 5 |
|
| 6 |
-
from aws_lambda_powertools.event_handler import content_types
|
| 7 |
from aws_lambda_powertools.utilities.typing import LambdaContext
|
| 8 |
-
from aws_lambda_powertools.utilities.parser import BaseModel
|
| 9 |
|
| 10 |
from src import app_logger
|
| 11 |
-
from src.io.
|
| 12 |
from src.prediction_api.predictors import samexporter_predict
|
| 13 |
-
from src.utilities.constants import CUSTOM_RESPONSE_MESSAGES, DEFAULT_LOG_LEVEL
|
| 14 |
-
from src.utilities.utilities import base64_decode
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
list_float = List[float]
|
| 18 |
-
llist_float = List[list_float]
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
class LatLngDict(BaseModel):
|
| 22 |
-
lat: float
|
| 23 |
-
lng: float
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class RawBBox(BaseModel):
|
| 27 |
-
ne: LatLngDict
|
| 28 |
-
sw: LatLngDict
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
class RawPrompt(BaseModel):
|
| 32 |
-
type: str
|
| 33 |
-
data: LatLngDict
|
| 34 |
-
label: int = 0
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
class RawRequestInput(BaseModel):
|
| 38 |
-
bbox: RawBBox
|
| 39 |
-
prompt: RawPrompt
|
| 40 |
-
zoom: int | float
|
| 41 |
-
source_type: str = "Satellite"
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
class ParsedPrompt(BaseModel):
|
| 45 |
-
type: str
|
| 46 |
-
data: llist_float
|
| 47 |
-
label: int = 0
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
class ParsedRequestInput(BaseModel):
|
| 51 |
-
bbox: llist_float
|
| 52 |
-
prompt: ParsedPrompt
|
| 53 |
-
zoom: int | float
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
|
| 57 |
-
"""
|
| 58 |
-
Return a response for frontend clients.
|
| 59 |
-
|
| 60 |
-
Args:
|
| 61 |
-
status: status response
|
| 62 |
-
start_time: request start time (float)
|
| 63 |
-
request_id: str
|
| 64 |
-
response_body: dict we embed into our response
|
| 65 |
-
|
| 66 |
-
Returns:
|
| 67 |
-
str: json response
|
| 68 |
-
|
| 69 |
-
"""
|
| 70 |
-
app_logger.debug(f"response_body:{response_body}.")
|
| 71 |
-
response_body["duration_run"] = time.time() - start_time
|
| 72 |
-
response_body["message"] = CUSTOM_RESPONSE_MESSAGES[status]
|
| 73 |
-
response_body["request_id"] = request_id
|
| 74 |
-
|
| 75 |
-
response = {
|
| 76 |
-
"statusCode": status,
|
| 77 |
-
"header": {"Content-Type": content_types.APPLICATION_JSON},
|
| 78 |
-
"body": json.dumps(response_body),
|
| 79 |
-
"isBase64Encoded": False
|
| 80 |
-
}
|
| 81 |
-
app_logger.debug(f"response type:{type(response)} => {response}.")
|
| 82 |
-
return json.dumps(response)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def get_parsed_bbox_points(request_input: RawRequestInput) -> Dict:
|
| 86 |
-
app_logger.info(f"try to parsing input request {request_input}...")
|
| 87 |
-
bbox = request_input["bbox"]
|
| 88 |
-
app_logger.debug(f"request bbox: {type(bbox)}, value:{bbox}.")
|
| 89 |
-
ne = bbox["ne"]
|
| 90 |
-
sw = bbox["sw"]
|
| 91 |
-
app_logger.debug(f"request ne: {type(ne)}, value:{ne}.")
|
| 92 |
-
app_logger.debug(f"request sw: {type(sw)}, value:{sw}.")
|
| 93 |
-
ne_latlng = [float(ne["lat"]), float(ne["lng"])]
|
| 94 |
-
sw_latlng = [float(sw["lat"]), float(sw["lng"])]
|
| 95 |
-
bbox = [ne_latlng, sw_latlng]
|
| 96 |
-
zoom = int(request_input["zoom"])
|
| 97 |
-
for prompt in request_input["prompt"]:
|
| 98 |
-
app_logger.debug(f"current prompt: {type(prompt)}, value:{prompt}.")
|
| 99 |
-
data = prompt["data"]
|
| 100 |
-
if prompt["type"] == "point":
|
| 101 |
-
current_point = get_latlng_to_pixel_coordinates(ne, sw, data, zoom, "point")
|
| 102 |
-
app_logger.debug(f"current prompt: {type(current_point)}, value:{current_point}.")
|
| 103 |
-
new_prompt_data = [current_point['x'], current_point['y']]
|
| 104 |
-
app_logger.debug(f"new_prompt_data: {type(new_prompt_data)}, value:{new_prompt_data}.")
|
| 105 |
-
prompt["data"] = new_prompt_data
|
| 106 |
-
else:
|
| 107 |
-
raise ValueError("valid prompt type is only 'point'")
|
| 108 |
-
|
| 109 |
-
app_logger.debug(f"bbox => {bbox}.")
|
| 110 |
-
app_logger.debug(f'request_input-prompt updated => {request_input["prompt"]}.')
|
| 111 |
-
|
| 112 |
-
app_logger.info(f"unpacking elaborated {request_input}...")
|
| 113 |
-
return {
|
| 114 |
-
"bbox": bbox,
|
| 115 |
-
"prompt": request_input["prompt"],
|
| 116 |
-
"zoom": zoom
|
| 117 |
-
}
|
| 118 |
|
| 119 |
|
| 120 |
def lambda_handler(event: dict, context: LambdaContext):
|
|
@@ -125,7 +16,7 @@ def lambda_handler(event: dict, context: LambdaContext):
|
|
| 125 |
app_logger.info(f"event version: {event['version']}.")
|
| 126 |
|
| 127 |
try:
|
| 128 |
-
body = get_parsed_request_body(
|
| 129 |
|
| 130 |
try:
|
| 131 |
prompt_latlng = body["prompt"]
|
|
@@ -144,28 +35,3 @@ def lambda_handler(event: dict, context: LambdaContext):
|
|
| 144 |
|
| 145 |
app_logger.info(f"response_dumped:{response}...")
|
| 146 |
return response
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
def get_parsed_request_body(context, event):
|
| 150 |
-
app_logger.info(f"event:{json.dumps(event)}...")
|
| 151 |
-
app_logger.info(f"context:{context}...")
|
| 152 |
-
try:
|
| 153 |
-
body = event["body"]
|
| 154 |
-
except Exception as e_constants1:
|
| 155 |
-
app_logger.error(f"e_constants1:{e_constants1}.")
|
| 156 |
-
body = event
|
| 157 |
-
app_logger.debug(f"body, #1: {type(body)}, {body}...")
|
| 158 |
-
if isinstance(body, str):
|
| 159 |
-
body_decoded_str = base64_decode(body)
|
| 160 |
-
app_logger.debug(f"body_decoded_str: {type(body_decoded_str)}, {body_decoded_str}...")
|
| 161 |
-
body = json.loads(body_decoded_str)
|
| 162 |
-
app_logger.info(f"body, #2: {type(body)}, {body}...")
|
| 163 |
-
try:
|
| 164 |
-
log_level = 'DEBUG' if body['debug'] else DEFAULT_LOG_LEVEL
|
| 165 |
-
app_logger.warning(f"set logger level to DEBUG")
|
| 166 |
-
app_logger.setLevel(log_level)
|
| 167 |
-
except KeyError:
|
| 168 |
-
app_logger.warning(f"can't set log level, reset it...")
|
| 169 |
-
app_logger.setLevel(DEFAULT_LOG_LEVEL)
|
| 170 |
-
app_logger.warning(f"logger level is {app_logger.log_level}.")
|
| 171 |
-
return body
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
from http import HTTPStatus
|
|
|
|
| 3 |
|
|
|
|
| 4 |
from aws_lambda_powertools.utilities.typing import LambdaContext
|
|
|
|
| 5 |
|
| 6 |
from src import app_logger
|
| 7 |
+
from src.io.lambda_helpers import get_parsed_request_body, get_parsed_bbox_points, get_response
|
| 8 |
from src.prediction_api.predictors import samexporter_predict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def lambda_handler(event: dict, context: LambdaContext):
|
|
|
|
| 16 |
app_logger.info(f"event version: {event['version']}.")
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
body = get_parsed_request_body(event, context)
|
| 20 |
|
| 21 |
try:
|
| 22 |
prompt_latlng = body["prompt"]
|
|
|
|
| 35 |
|
| 36 |
app_logger.info(f"response_dumped:{response}...")
|
| 37 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/io/lambda_helpers.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import time
|
| 3 |
+
from typing import Dict
|
| 4 |
+
|
| 5 |
+
from aws_lambda_powertools.event_handler import content_types
|
| 6 |
+
|
| 7 |
+
from src import app_logger
|
| 8 |
+
from src.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
|
| 9 |
+
from src.utilities.constants import CUSTOM_RESPONSE_MESSAGES, DEFAULT_LOG_LEVEL
|
| 10 |
+
from src.utilities.type_hints import RawRequestInput
|
| 11 |
+
from src.utilities.utilities import base64_decode, LogArgumentsDecorator
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
|
| 15 |
+
"""
|
| 16 |
+
Return a response for frontend clients.
|
| 17 |
+
|
| 18 |
+
Args:
|
| 19 |
+
status: status response
|
| 20 |
+
start_time: request start time (float)
|
| 21 |
+
request_id: str
|
| 22 |
+
response_body: dict we embed into our response
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
str: json response
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
app_logger.debug(f"response_body:{response_body}.")
|
| 29 |
+
response_body["duration_run"] = time.time() - start_time
|
| 30 |
+
response_body["message"] = CUSTOM_RESPONSE_MESSAGES[status]
|
| 31 |
+
response_body["request_id"] = request_id
|
| 32 |
+
|
| 33 |
+
response = {
|
| 34 |
+
"statusCode": status,
|
| 35 |
+
"header": {"Content-Type": content_types.APPLICATION_JSON},
|
| 36 |
+
"body": json.dumps(response_body),
|
| 37 |
+
"isBase64Encoded": False
|
| 38 |
+
}
|
| 39 |
+
app_logger.debug(f"response type:{type(response)} => {response}.")
|
| 40 |
+
return json.dumps(response)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def get_parsed_bbox_points(request_input: RawRequestInput) -> Dict:
|
| 44 |
+
app_logger.info(f"try to parsing input request {request_input}...")
|
| 45 |
+
bbox = request_input["bbox"]
|
| 46 |
+
app_logger.debug(f"request bbox: {type(bbox)}, value:{bbox}.")
|
| 47 |
+
ne = bbox["ne"]
|
| 48 |
+
sw = bbox["sw"]
|
| 49 |
+
app_logger.debug(f"request ne: {type(ne)}, value:{ne}.")
|
| 50 |
+
app_logger.debug(f"request sw: {type(sw)}, value:{sw}.")
|
| 51 |
+
ne_latlng = [float(ne["lat"]), float(ne["lng"])]
|
| 52 |
+
sw_latlng = [float(sw["lat"]), float(sw["lng"])]
|
| 53 |
+
bbox = [ne_latlng, sw_latlng]
|
| 54 |
+
zoom = int(request_input["zoom"])
|
| 55 |
+
for prompt in request_input["prompt"]:
|
| 56 |
+
app_logger.debug(f"current prompt: {type(prompt)}, value:{prompt}.")
|
| 57 |
+
data = prompt["data"]
|
| 58 |
+
if prompt["type"] == "point":
|
| 59 |
+
current_point = get_latlng_to_pixel_coordinates(ne, sw, data, zoom, "point")
|
| 60 |
+
app_logger.debug(f"current prompt: {type(current_point)}, value:{current_point}.")
|
| 61 |
+
new_prompt_data = [current_point['x'], current_point['y']]
|
| 62 |
+
app_logger.debug(f"new_prompt_data: {type(new_prompt_data)}, value:{new_prompt_data}.")
|
| 63 |
+
prompt["data"] = new_prompt_data
|
| 64 |
+
else:
|
| 65 |
+
raise ValueError("valid prompt type is only 'point'")
|
| 66 |
+
|
| 67 |
+
app_logger.debug(f"bbox => {bbox}.")
|
| 68 |
+
app_logger.debug(f'request_input-prompt updated => {request_input["prompt"]}.')
|
| 69 |
+
|
| 70 |
+
app_logger.info(f"unpacking elaborated {request_input}...")
|
| 71 |
+
return {
|
| 72 |
+
"bbox": bbox,
|
| 73 |
+
"prompt": request_input["prompt"],
|
| 74 |
+
"zoom": zoom
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def get_parsed_request_body(event, context):
|
| 79 |
+
app_logger.info(f"event:{json.dumps(event)}...")
|
| 80 |
+
app_logger.info(f"context:{context}...")
|
| 81 |
+
try:
|
| 82 |
+
body = event["body"]
|
| 83 |
+
except Exception as e_constants1:
|
| 84 |
+
app_logger.error(f"e_constants1:{e_constants1}.")
|
| 85 |
+
body = event
|
| 86 |
+
app_logger.debug(f"body, #1: {type(body)}, {body}...")
|
| 87 |
+
if isinstance(body, str):
|
| 88 |
+
body_decoded_str = base64_decode(body)
|
| 89 |
+
app_logger.debug(f"body_decoded_str: {type(body_decoded_str)}, {body_decoded_str}...")
|
| 90 |
+
body = json.loads(body_decoded_str)
|
| 91 |
+
app_logger.info(f"body, #2: {type(body)}, {body}...")
|
| 92 |
+
try:
|
| 93 |
+
log_level = 'DEBUG' if body['debug'] else DEFAULT_LOG_LEVEL
|
| 94 |
+
app_logger.warning(f"set logger level to DEBUG")
|
| 95 |
+
app_logger.setLevel(log_level)
|
| 96 |
+
except KeyError:
|
| 97 |
+
app_logger.warning(f"can't set log level, reset it...")
|
| 98 |
+
app_logger.setLevel(DEFAULT_LOG_LEVEL)
|
| 99 |
+
app_logger.warning(f"logger level is {app_logger.log_level}.")
|
| 100 |
+
return body
|
src/utilities/type_hints.py
CHANGED
|
@@ -1,11 +1,48 @@
|
|
| 1 |
"""custom type hints"""
|
|
|
|
| 2 |
from typing import TypedDict
|
| 3 |
|
| 4 |
|
| 5 |
ts_dict_str2 = dict[str, str]
|
| 6 |
ts_dict_str3 = dict[str, str, any]
|
| 7 |
ts_ddict1 = dict[str, dict[str, any], dict, dict, any]
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
class PixelCoordinate(TypedDict):
|
|
|
|
| 1 |
"""custom type hints"""
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
from typing import TypedDict
|
| 4 |
|
| 5 |
|
| 6 |
ts_dict_str2 = dict[str, str]
|
| 7 |
ts_dict_str3 = dict[str, str, any]
|
| 8 |
ts_ddict1 = dict[str, dict[str, any], dict, dict, any]
|
| 9 |
+
list_float = list[float]
|
| 10 |
+
llist_float = list[list_float]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LatLngDict(BaseModel):
|
| 14 |
+
lat: float
|
| 15 |
+
lng: float
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class RawBBox(BaseModel):
|
| 19 |
+
ne: LatLngDict
|
| 20 |
+
sw: LatLngDict
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class RawPrompt(BaseModel):
|
| 24 |
+
type: str
|
| 25 |
+
data: LatLngDict
|
| 26 |
+
label: int = 0
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class RawRequestInput(BaseModel):
|
| 30 |
+
bbox: RawBBox
|
| 31 |
+
prompt: RawPrompt
|
| 32 |
+
zoom: int | float
|
| 33 |
+
source_type: str = "Satellite"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ParsedPrompt(BaseModel):
|
| 37 |
+
type: str
|
| 38 |
+
data: llist_float
|
| 39 |
+
label: int = 0
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class ParsedRequestInput(BaseModel):
|
| 43 |
+
bbox: llist_float
|
| 44 |
+
prompt: ParsedPrompt
|
| 45 |
+
zoom: int | float
|
| 46 |
|
| 47 |
|
| 48 |
class PixelCoordinate(TypedDict):
|
tests/events/get_parsed_bbox_points.json
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"europe": {
|
| 3 |
+
"input": {
|
| 4 |
+
"request_input": {
|
| 5 |
+
"bbox": {
|
| 6 |
+
"ne": {
|
| 7 |
+
"lat": 38.03932961278458,
|
| 8 |
+
"lng": 15.36808069832851
|
| 9 |
+
},
|
| 10 |
+
"sw": {
|
| 11 |
+
"lat": 37.455509218936974,
|
| 12 |
+
"lng": 14.632807441554068
|
| 13 |
+
}
|
| 14 |
+
},
|
| 15 |
+
"prompt": [
|
| 16 |
+
{
|
| 17 |
+
"type": "point",
|
| 18 |
+
"data": {
|
| 19 |
+
"lat": 37.0,
|
| 20 |
+
"lng": 15.0
|
| 21 |
+
},
|
| 22 |
+
"label": 0
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"zoom": 10,
|
| 26 |
+
"source_type": "Satellite",
|
| 27 |
+
"debug": true
|
| 28 |
+
}
|
| 29 |
+
},
|
| 30 |
+
"output": {
|
| 31 |
+
"bbox": [
|
| 32 |
+
[
|
| 33 |
+
38.03932961278458,
|
| 34 |
+
15.36808069832851
|
| 35 |
+
],
|
| 36 |
+
[
|
| 37 |
+
37.455509218936974,
|
| 38 |
+
14.632807441554068
|
| 39 |
+
]
|
| 40 |
+
],
|
| 41 |
+
"prompt": [
|
| 42 |
+
{
|
| 43 |
+
"type": "point",
|
| 44 |
+
"data": [
|
| 45 |
+
267,
|
| 46 |
+
954
|
| 47 |
+
],
|
| 48 |
+
"label": 0
|
| 49 |
+
}
|
| 50 |
+
],
|
| 51 |
+
"zoom": 10
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"north_america": {
|
| 55 |
+
"input": {
|
| 56 |
+
"request_input": {
|
| 57 |
+
"bbox": {
|
| 58 |
+
"ne": {
|
| 59 |
+
"lat": 44.918201144476456,
|
| 60 |
+
"lng": -111.7859533595829
|
| 61 |
+
},
|
| 62 |
+
"sw": {
|
| 63 |
+
"lat": 39.35135789075441,
|
| 64 |
+
"lng": -123.03595335958288
|
| 65 |
+
}
|
| 66 |
+
},
|
| 67 |
+
"prompt": [
|
| 68 |
+
{
|
| 69 |
+
"type": "point",
|
| 70 |
+
"data": {
|
| 71 |
+
"lat": 41.142370385846974,
|
| 72 |
+
"lng": -112.64967251996322
|
| 73 |
+
},
|
| 74 |
+
"label": 0
|
| 75 |
+
}
|
| 76 |
+
],
|
| 77 |
+
"zoom": 7,
|
| 78 |
+
"source_type": "Satellite"
|
| 79 |
+
}
|
| 80 |
+
},
|
| 81 |
+
"output": {
|
| 82 |
+
"bbox": [
|
| 83 |
+
[
|
| 84 |
+
44.918201144476456,
|
| 85 |
+
-111.7859533595829
|
| 86 |
+
],
|
| 87 |
+
[
|
| 88 |
+
39.35135789075441,
|
| 89 |
+
-123.03595335958288
|
| 90 |
+
]
|
| 91 |
+
],
|
| 92 |
+
"prompt": [
|
| 93 |
+
{
|
| 94 |
+
"type": "point",
|
| 95 |
+
"data": [
|
| 96 |
+
946,
|
| 97 |
+
471
|
| 98 |
+
],
|
| 99 |
+
"label": 0
|
| 100 |
+
}
|
| 101 |
+
],
|
| 102 |
+
"zoom": 7
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
"oceania": {
|
| 106 |
+
"input": {
|
| 107 |
+
"request_input": {
|
| 108 |
+
"bbox": {
|
| 109 |
+
"ne": {
|
| 110 |
+
"lat": -1.4939713066293112,
|
| 111 |
+
"lng": 155.30273437500003
|
| 112 |
+
},
|
| 113 |
+
"sw": {
|
| 114 |
+
"lat": -52.32191088594772,
|
| 115 |
+
"lng": 65.30273437500001
|
| 116 |
+
}
|
| 117 |
+
},
|
| 118 |
+
"prompt": [
|
| 119 |
+
{
|
| 120 |
+
"type": "point",
|
| 121 |
+
"data": {
|
| 122 |
+
"lat": -42.51390169585491,
|
| 123 |
+
"lng": 147.0746141732014
|
| 124 |
+
},
|
| 125 |
+
"label": 0
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
"zoom": 4,
|
| 129 |
+
"source_type": "Satellite"
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
"output": {
|
| 133 |
+
"bbox": [
|
| 134 |
+
[
|
| 135 |
+
-1.4939713066293112,
|
| 136 |
+
155.30273437500003
|
| 137 |
+
],
|
| 138 |
+
[
|
| 139 |
+
-52.32191088594772,
|
| 140 |
+
65.30273437500001
|
| 141 |
+
]
|
| 142 |
+
],
|
| 143 |
+
"prompt": [
|
| 144 |
+
{
|
| 145 |
+
"type": "point",
|
| 146 |
+
"data": [
|
| 147 |
+
930,
|
| 148 |
+
518
|
| 149 |
+
],
|
| 150 |
+
"label": 0
|
| 151 |
+
}
|
| 152 |
+
],
|
| 153 |
+
"zoom": 4
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
"south_america": {
|
| 157 |
+
"input": {
|
| 158 |
+
"request_input": {
|
| 159 |
+
"bbox": {
|
| 160 |
+
"ne": {
|
| 161 |
+
"lat": -24.80663308621806,
|
| 162 |
+
"lng": -63.98446722241735
|
| 163 |
+
},
|
| 164 |
+
"sw": {
|
| 165 |
+
"lat": -31.42861774444052,
|
| 166 |
+
"lng": -75.23446722241735
|
| 167 |
+
}
|
| 168 |
+
},
|
| 169 |
+
"prompt": [
|
| 170 |
+
{
|
| 171 |
+
"type": "point",
|
| 172 |
+
"data": {
|
| 173 |
+
"lat": -29.911045956544207,
|
| 174 |
+
"lng": -64.78226803685988
|
| 175 |
+
},
|
| 176 |
+
"label": 0
|
| 177 |
+
}
|
| 178 |
+
],
|
| 179 |
+
"zoom": 7,
|
| 180 |
+
"source_type": "Satellite"
|
| 181 |
+
}
|
| 182 |
+
},
|
| 183 |
+
"output": {
|
| 184 |
+
"bbox": [
|
| 185 |
+
[
|
| 186 |
+
-24.80663308621806,
|
| 187 |
+
-63.98446722241735
|
| 188 |
+
],
|
| 189 |
+
[
|
| 190 |
+
-31.42861774444052,
|
| 191 |
+
-75.23446722241735
|
| 192 |
+
]
|
| 193 |
+
],
|
| 194 |
+
"prompt": [
|
| 195 |
+
{
|
| 196 |
+
"type": "point",
|
| 197 |
+
"data": [
|
| 198 |
+
952,
|
| 199 |
+
524
|
| 200 |
+
],
|
| 201 |
+
"label": 0
|
| 202 |
+
}
|
| 203 |
+
],
|
| 204 |
+
"zoom": 7
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
tests/io/test_coordinates_pixel_conversion.py
CHANGED
|
@@ -1,36 +1,13 @@
|
|
| 1 |
-
import
|
| 2 |
-
from unittest import TestCase
|
| 3 |
|
| 4 |
-
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection, get_point_latlng_to_pixel_coordinates, \
|
| 5 |
-
get_latlng_to_pixel_coordinates
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
-
|
| 11 |
-
"
|
| 12 |
-
"get_point_latlng_to_pixel_coordinates": get_point_latlng_to_pixel_coordinates,
|
| 13 |
-
"get_latlng_to_pixel_coordinates": get_latlng_to_pixel_coordinates
|
| 14 |
-
}
|
| 15 |
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
with open(TEST_EVENTS_FOLDER / f"{name_fn}.json") as tst_json:
|
| 21 |
-
inputs_outputs = json.load(tst_json)
|
| 22 |
-
for k, input_output in inputs_outputs.items():
|
| 23 |
-
print(f"k:{k}.")
|
| 24 |
-
output = fn(**input_output["input"])
|
| 25 |
-
assert output == input_output["output"]
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
class Test(TestCase):
|
| 29 |
-
def test_get_latlng2pixel_projection(self):
|
| 30 |
-
test_fn_reading_json_inputs_outputs("get_latlng2pixel_projection")
|
| 31 |
-
|
| 32 |
-
def test_get_point_latlng_to_pixel_coordinates(self):
|
| 33 |
-
test_fn_reading_json_inputs_outputs("get_point_latlng_to_pixel_coordinates")
|
| 34 |
-
|
| 35 |
-
def test_get_latlng_to_pixel_coordinates(self):
|
| 36 |
-
test_fn_reading_json_inputs_outputs("get_latlng_to_pixel_coordinates")
|
|
|
|
| 1 |
+
from tests.io.test_utilities import fn_reading_json_inputs_outputs__test
|
|
|
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def test_get_latlng2pixel_projection():
|
| 5 |
+
fn_reading_json_inputs_outputs__test(name_fn="get_latlng2pixel_projection")
|
| 6 |
|
| 7 |
|
| 8 |
+
def test_get_point_latlng_to_pixel_coordinates():
|
| 9 |
+
fn_reading_json_inputs_outputs__test(name_fn="get_point_latlng_to_pixel_coordinates")
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
+
def test_get_latlng_to_pixel_coordinates():
|
| 13 |
+
fn_reading_json_inputs_outputs__test(name_fn="get_latlng_to_pixel_coordinates")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/io/test_lambda_helpers.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tests.io.test_utilities import fn_reading_json_inputs_outputs__test
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_get_parsed_bbox_points():
|
| 5 |
+
fn_reading_json_inputs_outputs__test(name_fn="get_parsed_bbox_points")
|
tests/io/test_utilities.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection, get_point_latlng_to_pixel_coordinates, \
|
| 4 |
+
get_latlng_to_pixel_coordinates
|
| 5 |
+
from src.io.lambda_helpers import get_parsed_bbox_points
|
| 6 |
+
|
| 7 |
+
from tests import TEST_EVENTS_FOLDER
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
names_fn_dict = {
|
| 11 |
+
"get_latlng2pixel_projection": get_latlng2pixel_projection,
|
| 12 |
+
"get_point_latlng_to_pixel_coordinates": get_point_latlng_to_pixel_coordinates,
|
| 13 |
+
"get_latlng_to_pixel_coordinates": get_latlng_to_pixel_coordinates,
|
| 14 |
+
"get_parsed_bbox_points": get_parsed_bbox_points
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def fn_reading_json_inputs_outputs__test(name_fn):
|
| 19 |
+
fn = names_fn_dict[name_fn]
|
| 20 |
+
|
| 21 |
+
with open(TEST_EVENTS_FOLDER / f"{name_fn}.json") as tst_json:
|
| 22 |
+
inputs_outputs = json.load(tst_json)
|
| 23 |
+
for k, input_output in inputs_outputs.items():
|
| 24 |
+
print(f"k:{k}.")
|
| 25 |
+
output = fn(**input_output["input"])
|
| 26 |
+
assert output == input_output["output"]
|