Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix attribute completeness and add workaround for dashboard #800

Merged
merged 7 commits into from
May 28, 2024
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
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

## Current Main

### Other Changes
### New Features

- road-comparison: change color of bar to grey ([#798])
- attribute-completeness: add workaround for attribute_key to use indicator in dashboard ([#800])

### Bug Fixes

- road-comparison: bar for not covered roads is now shown in the plot ([#798])
- attribute-completeness: fix bugs in result figure ([#800])


### Other Changes

- road-comparison: change color of bar to grey ([#798])


[#798]: https://github.com/GIScience/ohsome-quality-api/pull/798
[#800]: https://github.com/GIScience/ohsome-quality-api/pull/800

## Release 1.3.0

Expand Down
6 changes: 5 additions & 1 deletion ohsome_quality_api/attributes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ def get_attributes() -> dict[str, dict[str, Attribute]]:
return load_attributes()


def get_attribute(topic_key, a_key: str) -> Attribute:
def get_attribute(topic_key, a_key: str | None) -> Attribute:
attributes = get_attributes()
try:
# TODO: Workaround to be able to display indicator in dashboard.
# Remove if dashboard handles attribution key selection.
if a_key is None:
return next(iter(attributes[topic_key].values()))
return attributes[topic_key][a_key]
except KeyError as error:
raise KeyError("Invalid topic or attribute key.") from error
16 changes: 11 additions & 5 deletions ohsome_quality_api/indicators/attribute_completeness/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class AttributeCompleteness(BaseIndicator):
"""

# TODO make attribute a list
def __init__(self, topic: Topic, feature: Feature, attribute_key: str) -> None:
def __init__(
self,
topic: Topic,
feature: Feature,
attribute_key: str = None,
) -> None:
super().__init__(topic=topic, feature=feature)
self.threshold_yellow = 0.75
self.threshold_red = 0.25
Expand Down Expand Up @@ -62,7 +67,7 @@ def calculate(self) -> None:
if self.result.value is None:
return
description = Template(self.metadata.result_description).substitute(
result=round(self.result.value, 1),
result=round(self.result.value, 2),
all=round(self.absolute_value_1, 1),
matched=round(self.absolute_value_2, 1),
)
Expand Down Expand Up @@ -93,11 +98,12 @@ def create_figure(self) -> None:
attribute(s).
"""

def rotate(ratio, offset=(0, 0)):
def rotate(ratio, offset=(0, 0)) -> list[float]:
theta = ratio * pi
c, s = np.cos(theta), np.sin(theta)
r = np.array(((c, -s), (s, c)))
return np.matmul(r.T, (-1, 0)) + offset
rotated_list = np.matmul(r.T, (-1, 0)) + offset
return [float(np_float) for np_float in rotated_list]

fig = go.Figure(
go.Indicator(
Expand All @@ -107,7 +113,7 @@ def rotate(ratio, offset=(0, 0)):
type="indicator",
gauge={
"axis": {
"range": [None, 100],
"range": [0, 100],
"tickwidth": 1,
"tickcolor": "darkblue",
"ticksuffix": "%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ attribute-completeness:
The quality level could not be calculated for this indicator.
result_description: >-
The ratio of the features (all: $all) compared to features with
expected tags (matched: $matched) is $result.
expected tags (matched: $matched) is $result.
1 change: 1 addition & 0 deletions ohsome_quality_api/oqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async def create_indicator(
"currentness",
"building-comparison",
"road-comparison",
"attribute-completeness",
]:
validate_area(feature)
tasks.append(_create_indicator(key, feature, topic, include_figure))
Expand Down