diff --git a/ohsome_quality_api/indicators/currentness/indicator.py b/ohsome_quality_api/indicators/currentness/indicator.py index aca0e724f..6444a72f7 100644 --- a/ohsome_quality_api/indicators/currentness/indicator.py +++ b/ohsome_quality_api/indicators/currentness/indicator.py @@ -209,6 +209,7 @@ def calculate(self): self.result.description = check_minor_edge_cases( self.contrib_sum, self.bin_total, + self.topic.aggregation_type, ) self.bin_up_to_date = create_bin( @@ -452,13 +453,13 @@ def check_major_edge_cases(contrib_sum) -> str: return "" -def check_minor_edge_cases(contrib_sum, bin_total) -> str: +def check_minor_edge_cases(contrib_sum, bin_total, aggregation_type) -> str: """Check edge cases and return description. Minor edge cases should *not* lead to cancellation of calculation. """ num_months = get_num_months_last_contrib(bin_total.contrib_abs) - if contrib_sum < 25: # not enough data + if contrib_sum < 25 and aggregation_type == "count": # not enough data return ( "Please note that in the area of interest less than 25 features of the " "selected topic are present today. " diff --git a/tests/approvals/integrationtests/indicators/test_currentness.py-TestCalculation-test_calculate_aggregation_types[building-area].approved.txt b/tests/approvals/integrationtests/indicators/test_currentness.py-TestCalculation-test_calculate_aggregation_types[building-area].approved.txt index 98470fd18..71d75c51f 100644 --- a/tests/approvals/integrationtests/indicators/test_currentness.py-TestCalculation-test_calculate_aggregation_types[building-area].approved.txt +++ b/tests/approvals/integrationtests/indicators/test_currentness.py-TestCalculation-test_calculate_aggregation_types[building-area].approved.txt @@ -1,2 +1,2 @@ -Please note that in the area of interest less than 25 features of the selected topic are present today. In the area of interest 58% of the features (6.6 km2) were edited (created or modified) for the last time in the period between Oct 2022 and Sep 2025. +In the area of interest 58% of the features (6.6 km2) were edited (created or modified) for the last time in the period between Oct 2022 and Sep 2025. Most features are up-to-date. diff --git a/tests/conftest.py b/tests/conftest.py index c6b7c03b5..15e378165 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from geojson import Feature, FeatureCollection, Polygon from ohsome_quality_api.attributes.models import Attribute +from ohsome_quality_api.indicators.currentness.indicator import Bin from ohsome_quality_api.indicators.definitions import ( get_indicator, get_indicator_metadata, @@ -297,3 +298,11 @@ def feature_land_cover(): @pytest.fixture def topic_land_cover() -> TopicDefinition: return get_topic_preset("land-cover") + + +@pytest.fixture +def bin_total_factory(): + def _factory(contrib_abs=[], contrib_rel=[], timestamps=[]): + return Bin(contrib_abs, contrib_rel, timestamps) + + return _factory diff --git a/tests/integrationtests/indicators/test_currentness.py b/tests/integrationtests/indicators/test_currentness.py index 606c1be6c..8bf3d9698 100644 --- a/tests/integrationtests/indicators/test_currentness.py +++ b/tests/integrationtests/indicators/test_currentness.py @@ -1,6 +1,7 @@ import json import os from datetime import datetime +from unittest.mock import patch import asyncpg_recorder import geojson @@ -13,6 +14,8 @@ from ohsome_quality_api.indicators.currentness.indicator import ( Bin, Currentness, + check_major_edge_cases, + check_minor_edge_cases, create_bin, get_median_month, get_num_months_last_contrib, @@ -330,3 +333,53 @@ def test_create_bin(): assert ( len(new_bin.contrib_abs) == len(new_bin.contrib_rel) == len(new_bin.timestamps) ) + + +def test_check_major_edge_cases_no_data(): + result = check_major_edge_cases(0) + assert "no features of the selected topic" in result + + +def test_check_major_edge_cases_has_data(): + result = check_major_edge_cases(10) + assert result == "" + + +def test_check_minor_edge_cases_low_data(bin_total_factory): + bin_total = bin_total_factory(contrib_abs=10) + with patch( + "ohsome_quality_api.indicators.currentness.indicator.get_num_months_last_contrib", + return_value=0, + ): + result = check_minor_edge_cases(10, bin_total, "count") + assert "less than 25" in result + + +def test_check_minor_edge_cases_inactivity(bin_total_factory): + bin_total = bin_total_factory(contrib_abs=100) + with patch( + "ohsome_quality_api.indicators.currentness.indicator.get_num_months_last_contrib", + return_value=12, + ): + result = check_minor_edge_cases(100, bin_total, "count") + assert "no mapping activity for 12 months" in result + + +def test_check_minor_edge_cases_area_more_than_25(bin_total_factory): + bin_total = bin_total_factory(contrib_abs=100) + with patch( + "ohsome_quality_api.indicators.currentness.indicator.get_num_months_last_contrib", + return_value=5, + ): + result = check_minor_edge_cases(100, bin_total, "area") + assert result == "" + + +def test_check_minor_edge_cases_area_less_than_25(bin_total_factory): + bin_total = bin_total_factory(contrib_abs=10) + with patch( + "ohsome_quality_api.indicators.currentness.indicator.get_num_months_last_contrib", + return_value=5, + ): + result = check_minor_edge_cases(10, bin_total, "area") + assert result == ""