Skip to content
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
5 changes: 3 additions & 2 deletions ohsome_quality_api/indicators/currentness/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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. "
Expand Down
Original file line number Diff line number Diff line change
@@ -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 km<sup>2</sup>) 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 km<sup>2</sup>) were edited (created or modified) for the last time in the period between Oct 2022 and Sep 2025.
Most features are up-to-date.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
53 changes: 53 additions & 0 deletions tests/integrationtests/indicators/test_currentness.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from datetime import datetime
from unittest.mock import patch

import asyncpg_recorder
import geojson
Expand All @@ -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,
Expand Down Expand Up @@ -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 == ""