Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion cads_processing_api_service/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
from typing import Any

import fastapi
import structlog

from . import config

logger: structlog.stdlib.BoundLogger = structlog.get_logger(__name__)


def extract_groups_labels(
groups: list[Any], values: dict[str, str] | None = None
Expand Down Expand Up @@ -133,7 +136,7 @@ def translate_cds_form(


def make_request_labels(
input_value_ids: list[str],
input_value_ids: Any,
cds_input_schema: dict[str, Any],
) -> list[str]:
if cds_input_schema["type"] in (
Expand All @@ -147,6 +150,21 @@ def make_request_labels(
input_value_ids,
)
]
elif cds_input_schema["type"] == "GeographicLocationWidget":
location = input_value_ids[0]
try:
latitude = f"{location['latitude']}°"
longitude = f"{location['longitude']}°"
except Exception as e:
logger.error(
"Error extracting latitude and longitude from geographic location",
error=e,
)
latitude = longitude = "Unknown"
request_labels = [
f"Latitude: {latitude}",
f"Longitude: {longitude}",
]
else:
input_value_label = extract_labels(cds_input_schema)
request_labels = []
Expand Down
14 changes: 14 additions & 0 deletions tests/test_10_translators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

# Copyright 2022, European Union.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,6 +43,10 @@
"details": {"default": [1, 2, 3, 4]},
"type": "GeographicExtentMapWidget",
},
"geographic_location": {
"details": {},
"type": "GeographicLocationWidget",
},
"string_list_array_groups": {
"details": {
"groups": [
Expand Down Expand Up @@ -205,6 +211,14 @@ def test_make_request_labels() -> None:
)
assert res_output == exp_output

test_input_value_ids = [{"latitude": 10, "longitude": 10}]
test_input_cds_schema = TEST_INPUT_CDS_SCHEMAS["geographic_location"]
exp_output = ["Latitude: 10°", "Longitude: 10°"]
res_output = cads_processing_api_service.translators.make_request_labels(
test_input_value_ids, test_input_cds_schema
)
assert res_output == exp_output

test_input_value_ids = ["val1", "val2"]
test_input_cds_schema = TEST_INPUT_CDS_SCHEMAS["string_list"]
exp_output = ["Val1", "Val2"]
Expand Down