Skip to content
Open
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
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ werkzeug==3.1.8
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.1.4
44 changes: 30 additions & 14 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,45 @@ def texture_coordinates() -> flask.Response:
return flask.make_response({"texture_coordinates": texture_coordinates}, 200)


def attributes_metadata(manager: og.AttributeManager) -> list[dict[str, str | float]]:
attributes: list[dict[str, str | float]] = []
def attributes_metadata(
manager: og.AttributeManager,
) -> list[dict[str, str | int | float | list[float]]]:
attributes: list[dict[str, str | int | float | list[float]]] = []
nb_elements = manager.nb_elements()
for name in manager.attribute_names():
attribute = manager.find_generic_attribute(name)
nb_items = 1
min_value, max_value = -1.0, -1.0
min_values, max_values = [-1.0], [-1.0]
if attribute.is_genericable():
values = []
nb_items = attribute.nb_items()
for index in range(nb_elements):
for item in range(nb_items):
value = attribute.generic_item_value(index, item)
values.append(value)

valid_values = [
value for value in values if value is not None and not math.isnan(value)
]
if valid_values:
min_value, max_value = min(valid_values), max(valid_values)
min_values, max_values = [], []
for item in range(nb_items):
values = [
attribute.generic_item_value(idx, item)
for idx in range(nb_elements)
]
valid = [
value
for value in values
if value is not None and not math.isnan(value)
]
min_values.append(min(valid) if valid else -1.0)
max_values.append(max(valid) if valid else -1.0)
min_value, max_value = min_values[0], max_values[0]

attributes.append(
{"attribute_name": name, "min_value": min_value, "max_value": max_value}
{
"attribute_name": name,
"nb_items": nb_items,
"min_value": min_value,
"max_value": max_value,
Comment thread
MaxNumerique marked this conversation as resolved.
"min_values": min_values,
"max_values": max_values,
}
)
print(f"[ATTRIBUTES] Number of items: {nb_items}")
print(f"[ATTRIBUTES] Attributes: {attributes}")
return attributes


Expand Down
44 changes: 44 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ def test_vertex_attribute_names(client: FlaskClient, test_id: str) -> None:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute
print(
f"[ATTRIBUTES]: ",
[attribute["nb_items"] for attribute in attributes],
flush=True,
)


def test_cell_attribute_names(client: FlaskClient, test_id: str) -> None:
Expand Down Expand Up @@ -286,6 +294,14 @@ def test_cell_attribute_names(client: FlaskClient, test_id: str) -> None:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute
print(
f"[ATTRIBUTES]: ",
[attribute["nb_items"] for attribute in attributes],
flush=True,
)


def test_polygon_attribute_names(client: FlaskClient, test_id: str) -> None:
Expand Down Expand Up @@ -314,6 +330,14 @@ def test_polygon_attribute_names(client: FlaskClient, test_id: str) -> None:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute
print(
f"[ATTRIBUTES]: ",
[attribute["nb_items"] for attribute in attributes],
flush=True,
)


def test_polyhedron_attribute_names(client: FlaskClient, test_id: str) -> None:
Expand Down Expand Up @@ -343,9 +367,17 @@ def test_polyhedron_attribute_names(client: FlaskClient, test_id: str) -> None:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute
if attribute["attribute_name"] == "Range":
assert attribute["min_value"] == 0.0
assert attribute["max_value"] == 579.0
print(
f"[ATTRIBUTES]: ",
[attribute["nb_items"] for attribute in attributes],
flush=True,
)


def test_edge_attribute_names(client: FlaskClient, test_id: str) -> None:
Expand All @@ -370,11 +402,20 @@ def test_edge_attribute_names(client: FlaskClient, test_id: str) -> None:
print(response.get_json())
assert response.status_code == 200
attributes = response.get_json()["attributes"]
print(f"[ATTRIBUTES]: ", attributes, flush=True)
assert type(attributes) is list
for attribute in attributes:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute
print(
f"[ATTRIBUTES]: ",
[attribute["nb_items"] for attribute in attributes],
flush=True,
)


def test_database_uri_path(client: FlaskClient) -> None:
Expand Down Expand Up @@ -624,6 +665,9 @@ def _assert_attributes_response(response) -> None:
assert "attribute_name" in attribute
assert "min_value" in attribute
assert "max_value" in attribute
assert "nb_items" in attribute
assert "min_values" in attribute
assert "max_values" in attribute


def test_model_component_vertex_attribute_names(client: FlaskClient) -> None:
Expand Down
Loading