From 75e6e940bafd410d6bc2767abac02b7e751b94c9 Mon Sep 17 00:00:00 2001 From: Gigaszi Date: Fri, 17 May 2024 17:16:08 +0200 Subject: [PATCH 1/5] feat(attribute-completeness): add workaround for attribute_key and fix numpy float of rotate function --- ohsome_quality_api/attributes/definitions.py | 2 ++ .../indicators/attribute_completeness/indicator.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ohsome_quality_api/attributes/definitions.py b/ohsome_quality_api/attributes/definitions.py index dcccdc30b..e9cec8d5b 100644 --- a/ohsome_quality_api/attributes/definitions.py +++ b/ohsome_quality_api/attributes/definitions.py @@ -30,6 +30,8 @@ def get_attributes() -> dict[str, dict[str, Attribute]]: def get_attribute(topic_key, a_key: str) -> Attribute: attributes = get_attributes() try: + 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 diff --git a/ohsome_quality_api/indicators/attribute_completeness/indicator.py b/ohsome_quality_api/indicators/attribute_completeness/indicator.py index cc615e199..99ca57105 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/indicator.py +++ b/ohsome_quality_api/indicators/attribute_completeness/indicator.py @@ -33,7 +33,9 @@ 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 @@ -97,7 +99,8 @@ def rotate(ratio, offset=(0, 0)): 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( @@ -107,7 +110,7 @@ def rotate(ratio, offset=(0, 0)): type="indicator", gauge={ "axis": { - "range": [None, 100], + "range": [0, 100], "tickwidth": 1, "tickcolor": "darkblue", "ticksuffix": "%", @@ -171,7 +174,6 @@ def rotate(ratio, offset=(0, 0)): y=-0.2, borderwidth=0, ) - raw = fig.to_dict() raw["layout"].pop("template") # remove boilerplate self.result.figure = raw From f102375b2383bfe55bdbd7f5ebea8b3f7885459c Mon Sep 17 00:00:00 2001 From: Gigaszi Date: Fri, 17 May 2024 17:17:24 +0200 Subject: [PATCH 2/5] fix(attribute-completeness): add space to result description --- .../indicators/attribute_completeness/metadata.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohsome_quality_api/indicators/attribute_completeness/metadata.yaml b/ohsome_quality_api/indicators/attribute_completeness/metadata.yaml index e7ae921cd..1a7987e86 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/metadata.yaml +++ b/ohsome_quality_api/indicators/attribute_completeness/metadata.yaml @@ -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. From 6a3aba50022724f4afe31f80bea22bd79b5063f2 Mon Sep 17 00:00:00 2001 From: Gigaszi Date: Fri, 17 May 2024 17:22:26 +0200 Subject: [PATCH 3/5] chore: add CHANGELOG --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 266375283..3e9879de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## Current Main + +### New Features + +- attribute-completeness: add workaround for attribute_key to use indicator in dashboard ([#800]) + +### Bug Fixes + +- attribute-completeness: fix bugs in result figure ([#800]) + + +[#800]: https://github.com/GIScience/ohsome-quality-api/pull/800 + ## Release 1.3.0 ### Breaking Changes From 15486a642b89c0c9a3656ab41664dc0fbfbb9ece Mon Sep 17 00:00:00 2001 From: Gigaszi Date: Mon, 27 May 2024 11:52:00 +0200 Subject: [PATCH 4/5] fix(attribute-completeness): round result description to 2 digits and remove size restriction --- .../indicators/attribute_completeness/indicator.py | 2 +- ohsome_quality_api/oqt.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ohsome_quality_api/indicators/attribute_completeness/indicator.py b/ohsome_quality_api/indicators/attribute_completeness/indicator.py index 99ca57105..6c71238a6 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/indicator.py +++ b/ohsome_quality_api/indicators/attribute_completeness/indicator.py @@ -64,7 +64,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), ) diff --git a/ohsome_quality_api/oqt.py b/ohsome_quality_api/oqt.py index b93043da9..e03419597 100644 --- a/ohsome_quality_api/oqt.py +++ b/ohsome_quality_api/oqt.py @@ -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)) From 68038a92441f67182515654de142757897257dbb Mon Sep 17 00:00:00 2001 From: Matthias Schaub Date: Mon, 27 May 2024 13:46:42 +0200 Subject: [PATCH 5/5] style: add type hints and comments --- ohsome_quality_api/attributes/definitions.py | 4 +++- .../indicators/attribute_completeness/indicator.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ohsome_quality_api/attributes/definitions.py b/ohsome_quality_api/attributes/definitions.py index e9cec8d5b..02ddef6e7 100644 --- a/ohsome_quality_api/attributes/definitions.py +++ b/ohsome_quality_api/attributes/definitions.py @@ -27,9 +27,11 @@ 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] diff --git a/ohsome_quality_api/indicators/attribute_completeness/indicator.py b/ohsome_quality_api/indicators/attribute_completeness/indicator.py index 6c71238a6..da047800c 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/indicator.py +++ b/ohsome_quality_api/indicators/attribute_completeness/indicator.py @@ -34,7 +34,10 @@ class AttributeCompleteness(BaseIndicator): # TODO make attribute a list def __init__( - self, topic: Topic, feature: Feature, attribute_key: str = None + self, + topic: Topic, + feature: Feature, + attribute_key: str = None, ) -> None: super().__init__(topic=topic, feature=feature) self.threshold_yellow = 0.75 @@ -95,7 +98,7 @@ 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))) @@ -174,6 +177,7 @@ def rotate(ratio, offset=(0, 0)): y=-0.2, borderwidth=0, ) + raw = fig.to_dict() raw["layout"].pop("template") # remove boilerplate self.result.figure = raw