Commit ff3abd15 authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Added documentation and cleanup

parent 7ba3a17c
......@@ -35,7 +35,7 @@ def group_tags(occupancy_mapping: list[dict[str, str]]) -> dict[str, dict[str, s
class OccupancyMapper:
"""Map building tags to `GEM_occupancy`"""
"""Map osm tags to `GEM_occupancy` categories."""
def __init__(self, mapping):
self.mapping = mapping
......@@ -77,6 +77,13 @@ class OccupancyMapper:
class OverridingOccupancy:
"""Takes precedence over other mappings.
If `OverridingOccupancy.apply` returns a result this will be the designated occupancy.
Otherwise will return None.
"""
def __init__(self, mapping):
self.mapping = mapping
......@@ -86,7 +93,7 @@ class OverridingOccupancy:
return occupancy
else:
raise KeyError("No overriding occupancy matched")
return None
@classmethod
def read_csv(cls, fn: str) -> dict[str, str]:
......
......@@ -25,7 +25,7 @@ from rabotnikobm.occupancy.mapping import OccupancyMapper
logger = logging.getLogger()
class GetBuildingTaxonomy(Rule):
class GetBuildingOccupancy(Rule):
"""A rule to map OSM tags to building occupancies."""
def __init__(self, storage: StorageBase, occupancy_mapper: OccupancyMapper):
......
......@@ -18,13 +18,13 @@
import pytest
from rabotnikobm.rules.get_building_occupancy import GetBuildingTaxonomy
from rabotnikobm.rules.get_building_occupancy import GetBuildingOccupancy
@pytest.mark.requires_storage
@pytest.mark.asyncio
async def test_get_building_taxonomy(connected_storage, building_poi_mapper):
rule = GetBuildingTaxonomy(storage=connected_storage, occupancy_mapper=building_poi_mapper)
async def test_rule_get_building_occupancy(connected_storage, building_poi_mapper):
rule = GetBuildingOccupancy(storage=connected_storage, occupancy_mapper=building_poi_mapper)
payload = {"building_id": -6744517}
result = await rule.evaluate(payload=payload)
......
......@@ -16,9 +16,18 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import pytest
from rabotnikobm.occupancy.mapping import group_tags, OverridingOccupancy
@pytest.fixture()
def overriding_occupancies(pytestconfig):
fn_mapping = pytestconfig.rootpath / "data/rules/occupancy/overriding_occupancies.csv"
overriding_occupancies = OverridingOccupancy.from_csv(fn_mapping)
yield overriding_occupancies
def test_group_tags():
rows = [
{"key": "a", "value": 0},
......@@ -40,10 +49,13 @@ def test_mapper_landuse(landuse_mapper):
assert landuse_mapper.apply(sample_tags) == ["EDU3", "UNDECIDABLE"]
def test_occupancy_mapper(pytestconfig):
fn_mapping = pytestconfig.rootpath / "data/rules/occupancy/overriding_occupancies.csv"
overriding_mapping = OverridingOccupancy.from_csv(fn_mapping)
def test_overriding_occupancy(overriding_occupancies):
demo_tags = ["ASS1", "COM10"]
occupancy = overriding_mapping.apply(demo_tags)
occupancy = overriding_occupancies.apply(demo_tags)
assert occupancy == "airport"
def test_overriding_occupancy_unknown(overriding_occupancies):
demo_tags = ["unknown tag"]
occupancy = overriding_occupancies.apply(demo_tags)
assert occupancy is None
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment