From c3dca086d7a76b41c62a8f7893d4b6d5ad0666c3 Mon Sep 17 00:00:00 2001 From: Oliver Fritz Date: Mon, 27 Jan 2025 15:53:35 +0100 Subject: [PATCH 1/3] fix(street): get_image_metadata() error handling --- .../mapswipe_workers/utils/process_mapillary.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py index 1faf0b23b..25213faf6 100644 --- a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py +++ b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py @@ -16,7 +16,12 @@ from shapely.geometry import shape from vt2geojson import tools as vt2geojson_tools -from mapswipe_workers.definitions import MAPILLARY_API_KEY, MAPILLARY_API_LINK, logger +from mapswipe_workers.definitions import ( + MAPILLARY_API_KEY, + MAPILLARY_API_LINK, + CustomError, + logger, +) from mapswipe_workers.utils.spatial_sampling import spatial_sampling @@ -239,7 +244,7 @@ def get_image_metadata( downloaded_metadata = coordinate_download(aoi_polygon, level, attempt_limit) if downloaded_metadata.empty or downloaded_metadata.isna().all().all(): - raise ValueError("No Mapillary Features in the AoI.") + raise CustomError("No Mapillary Features in the AoI.") downloaded_metadata = downloaded_metadata[ downloaded_metadata["geometry"].apply(lambda geom: isinstance(geom, Point)) @@ -254,14 +259,14 @@ def get_image_metadata( or filtered_metadata.empty or filtered_metadata.isna().all().all() ): - raise ValueError("No Mapillary Features in the AoI match the filter criteria.") + raise CustomError("No Mapillary Features in the AoI match the filter criteria.") if sampling_threshold is not None: filtered_metadata = spatial_sampling(filtered_metadata, sampling_threshold) total_images = len(filtered_metadata) if total_images > 100000: - raise ValueError( + raise CustomError( f"Too many Images with selected filter options for the AoI: {total_images}" ) From 538c763ba882b8cfc14c4efc4660472129823215 Mon Sep 17 00:00:00 2001 From: Oliver Fritz Date: Mon, 27 Jan 2025 16:33:55 +0100 Subject: [PATCH 2/3] fix(street): adjust tests --- mapswipe_workers/tests/unittests/test_process_mapillary.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mapswipe_workers/tests/unittests/test_process_mapillary.py b/mapswipe_workers/tests/unittests/test_process_mapillary.py index 32c1bad46..573a259f9 100644 --- a/mapswipe_workers/tests/unittests/test_process_mapillary.py +++ b/mapswipe_workers/tests/unittests/test_process_mapillary.py @@ -7,6 +7,7 @@ from shapely import wkt from shapely.geometry import GeometryCollection, MultiPolygon, Point, Polygon +from mapswipe_workers.definitions import CustomError from mapswipe_workers.utils.process_mapillary import ( coordinate_download, create_tiles, @@ -326,7 +327,7 @@ def test_get_image_metadata_no_rows(self, mock_coordinate_download): "start_time": "1916-01-20 00:00:00", "end_time": "1922-01-21 23:59:59", } - with self.assertRaises(ValueError): + with self.assertRaises(CustomError): get_image_metadata(self.fixture_data, **params) @patch("mapswipe_workers.utils.process_mapillary.coordinate_download") @@ -335,7 +336,7 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download): df = df.drop(df.index) mock_coordinate_download.return_value = df - with self.assertRaises(ValueError): + with self.assertRaises(CustomError): get_image_metadata(self.fixture_data) @patch("mapswipe_workers.utils.process_mapillary.filter_results") @@ -346,7 +347,7 @@ def test_get_image_metadata_size_restriction( mock_filter_results.return_value = pd.DataFrame({"ID": range(1, 100002)}) mock_coordinate_download.return_value = self.fixture_df - with self.assertRaises(ValueError): + with self.assertRaises(CustomError): get_image_metadata(self.fixture_data) From 7899bfbb4200ebdbea357944511b3a10cd28519e Mon Sep 17 00:00:00 2001 From: Levi Szamek Date: Tue, 28 Jan 2025 18:02:42 +0100 Subject: [PATCH 3/3] refactor: use logger.info instead of logger.exception for missing values --- .../mapswipe_workers/utils/process_mapillary.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py index 25213faf6..6c866e43d 100644 --- a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py +++ b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py @@ -198,21 +198,19 @@ def filter_results( df = results_df.copy() if creator_id is not None: if df["creator_id"].isna().all(): - logger.exception( - "No Mapillary Feature in the AoI has a 'creator_id' value." - ) + logger.info("No Mapillary Feature in the AoI has a 'creator_id' value.") return None df = df[df["creator_id"] == creator_id] if is_pano is not None: if df["is_pano"].isna().all(): - logger.exception("No Mapillary Feature in the AoI has a 'is_pano' value.") + logger.info("No Mapillary Feature in the AoI has a 'is_pano' value.") return None df = df[df["is_pano"] == is_pano] if organization_id is not None: if df["organization_id"].isna().all(): - logger.exception( + logger.info( "No Mapillary Feature in the AoI has an 'organization_id' value." ) return None @@ -220,9 +218,7 @@ def filter_results( if start_time is not None: if df["captured_at"].isna().all(): - logger.exception( - "No Mapillary Feature in the AoI has a 'captured_at' value." - ) + logger.info("No Mapillary Feature in the AoI has a 'captured_at' value.") return None df = filter_by_timerange(df, start_time, end_time)