Skip to content

Commit

Permalink
feat: add AttributeEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigaszi committed Aug 27, 2024
1 parent a860485 commit 016ae53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ohsome_quality_api/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,15 @@ async def _post_indicator(
request: Request, key: str, parameters: IndicatorRequest
) -> Any:
validate_indicator_topic_combination(key, parameters.topic_key.value)
attribute_key = getattr(parameters, "attribute_key", None)
if attribute_key:
attribute_key = attribute_key.value
indicators = await oqt.create_indicator(
key=key,
bpolys=parameters.bpolys,
topic=get_topic_preset(parameters.topic_key.value),
include_figure=parameters.include_figure,
attribute_key=getattr(parameters, "attribute_key", None),
attribute_key=attribute_key,
)

if request.headers["accept"] == MEDIA_TYPE_JSON:
Expand Down
4 changes: 2 additions & 2 deletions ohsome_quality_api/api/request_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from geojson import FeatureCollection
from pydantic import BaseModel, ConfigDict, Field, field_validator

from ohsome_quality_api.attributes.definitions import AttributeEnum
from ohsome_quality_api.topics.definitions import TopicEnum
from ohsome_quality_api.topics.models import TopicData
from ohsome_quality_api.utils.helper import snake_to_lower_camel
Expand Down Expand Up @@ -63,8 +64,7 @@ class IndicatorRequest(BaseBpolys):


class AttributeCompletenessRequest(IndicatorRequest):
# TODO: Should be AttributeEnum
attribute_key: str = Field(
attribute_key: AttributeEnum = Field(
...,
title="Attribute Key",
alias="attribute",
Expand Down
10 changes: 10 additions & 0 deletions ohsome_quality_api/attributes/definitions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from enum import Enum
from typing import List

import yaml
Expand Down Expand Up @@ -68,3 +69,12 @@ def build_attribute_filter(attribute_key: List[str], topic_key: str) -> str:
return attribute_filter
except KeyError as error:
raise KeyError("Invalid topic or attribute key(s).") from error


attribute_keys = {
inner_key
for outer_dict in load_attributes().values()
for inner_key in outer_dict.keys()
}

AttributeEnum = Enum("AttributeEnum", {name: name for name in attribute_keys})

0 comments on commit 016ae53

Please sign in to comment.