Skip to content

Commit b18fe01

Browse files
refactor: remove centroid extraction and request type
1 parent 2ca6c47 commit b18fe01

File tree

7 files changed

+4
-61
lines changed

7 files changed

+4
-61
lines changed

sketch_map_tool/definitions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"sketch-map",
1717
"raster-results",
1818
"vector-results",
19-
"centroid-results",
2019
]
2120
# Colors to be detected
2221
COLORS = {

sketch_map_tool/helpers.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import numpy as np
88
from billiard.exceptions import TimeLimitExceeded
99
from celery.result import AsyncResult, GroupResult
10-
from geojson import Feature, FeatureCollection, Point
10+
from geojson import Feature, FeatureCollection
1111
from numpy.typing import NDArray
1212
from reportlab.graphics.shapes import Drawing
13-
from shapely.geometry import shape
1413

1514
from sketch_map_tool.exceptions import TimeLimitExceededError, TranslatableError
1615

@@ -110,16 +109,3 @@ def extract_errors(
110109
if len(errors_) > 0:
111110
errors = errors + [e.translate() for e in errors_]
112111
return errors
113-
114-
115-
def extract_centroids(feature_collection: FeatureCollection) -> FeatureCollection:
116-
centroids = []
117-
118-
for feature in feature_collection.features:
119-
geom = shape(feature.geometry)
120-
centroid_point = Point((geom.centroid.x, geom.centroid.y))
121-
centroids.append(
122-
Feature(geometry=centroid_point, properties=feature.properties)
123-
)
124-
125-
return FeatureCollection(centroids)

sketch_map_tool/routes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131
from sketch_map_tool.helpers import (
3232
N_,
33-
extract_centroids,
3433
extract_errors,
3534
merge,
3635
to_array,
@@ -220,7 +219,7 @@ def get_async_result(uuid: str, type_: REQUEST_TYPES) -> AsyncResult | GroupResu
220219
"""Get Celery `AsyncResult` or restore `GroupResult` for given Celery UUID."""
221220
if type_ == "sketch-map":
222221
async_result = celery_app.AsyncResult(uuid)
223-
elif type_ in ("vector-results", "centroid-results", "raster-results"):
222+
elif type_ in ("vector-results", "raster-results"):
224223
async_result = celery_app.GroupResult.restore(uuid)
225224
else:
226225
raise TypeError()
@@ -326,16 +325,13 @@ def download(uuid: str, type_: REQUEST_TYPES, lang="en") -> Response:
326325
else:
327326
# support legacy results
328327
file: BytesIO = async_result.get()
329-
case "vector-results" | "centroid-results":
328+
case "vector-results":
330329
db_client_flask.update_files_download_vector(uuid)
331330
mimetype = "application/geo+json"
332331
download_name = type_ + ".geojson"
333332
if isinstance(async_result, GroupResult):
334333
results = async_result.get(propagate=False)
335-
if type_ == "centroid-results":
336-
vector_results = [extract_centroids(r[-2]) for r in results]
337-
else:
338-
vector_results = [r[-2] for r in results]
334+
vector_results = [r[-2] for r in results]
339335
raw = geojson.dumps(merge(vector_results))
340336
file: BytesIO = BytesIO(raw.encode("utf-8"))
341337
else:

tests/integration/test_routes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def test_api_status_uuid_sketch_map(uuid_create, flask_client):
233233
(
234234
"raster-results",
235235
"vector-results",
236-
"centroid-results",
237236
),
238237
)
239238
def test_api_status_uuid_digitize(uuid_digitize, type_, flask_client):
@@ -306,7 +305,6 @@ def test_api_download_uuid_sketch_map(uuid_create, flask_client):
306305
"type_",
307306
[
308307
"vector-results",
309-
"centroid-results",
310308
"raster-results",
311309
],
312310
)

tests/unit/test_helpers.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,3 @@ def test_zip_(sketch_map_frame_markings_detected):
4949
assert zip_info[1].file_size == 5407584
5050
assert zip_info[2].filename == "attributions.txt"
5151
assert zip_info[2].file_size == 11
52-
53-
54-
def test_extract_centroids(detected_markings_cleaned):
55-
result_centroids = helpers.extract_centroids(detected_markings_cleaned)
56-
assert isinstance(result_centroids, FeatureCollection)
57-
assert len(result_centroids.features)
58-
assert len(result_centroids) == len(detected_markings_cleaned.features)
59-
for i, feature in enumerate(result_centroids.features):
60-
assert feature.geometry.type == "Point"
61-
assert (
62-
result_centroids.features[i].properties
63-
== detected_markings_cleaned.features[i].properties
64-
)

tests/unit/test_routes_api_download.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@ def test_download_failure(client, uuid):
2828
(
2929
"raster-results",
3030
"vector-results",
31-
"centroid-results",
3231
),
3332
)
3433
def test_group_download_success(client, uuid, type_, monkeypatch):
3534
monkeypatch.setattr(
3635
"sketch_map_tool.routes.merge",
3736
lambda *_: {"type": "FeatureCollection", "features": []},
3837
)
39-
monkeypatch.setattr(
40-
"sketch_map_tool.routes.extract_centroids",
41-
lambda *_: {"type": "FeatureCollection", "features": []},
42-
)
4338
monkeypatch.setattr(
4439
"sketch_map_tool.routes.zip_",
4540
lambda *_: BytesIO(),
@@ -55,7 +50,6 @@ def test_group_download_success(client, uuid, type_, monkeypatch):
5550
(
5651
"raster-results",
5752
"vector-results",
58-
"centroid-results",
5953
),
6054
)
6155
def test_group_started(client, uuid, type_):
@@ -69,7 +63,6 @@ def test_group_started(client, uuid, type_):
6963
(
7064
"raster-results",
7165
"vector-results",
72-
"centroid-results",
7366
),
7467
)
7568
def test_group_failure(client, uuid, type_):
@@ -83,14 +76,9 @@ def test_group_failure(client, uuid, type_):
8376
(
8477
"raster-results",
8578
"vector-results",
86-
"centroid-results",
8779
),
8880
)
8981
def test_group_started_success_failure(client, uuid, type_, monkeypatch):
90-
monkeypatch.setattr(
91-
"sketch_map_tool.routes.extract_centroids",
92-
lambda *_: {"type": "FeatureCollection", "features": []},
93-
)
9482
resp = client.get("/api/download/{0}/{1}".format(uuid, type_))
9583
assert resp.status_code == 500
9684

@@ -100,7 +88,6 @@ def test_group_started_success_failure(client, uuid, type_, monkeypatch):
10088
(
10189
"raster-results",
10290
"vector-results",
103-
"centroid-results",
10491
),
10592
)
10693
def test_group_success_failure(
@@ -114,10 +101,6 @@ def test_group_success_failure(
114101
"sketch_map_tool.routes.merge",
115102
lambda *_: {"type": "FeatureCollection", "features": []},
116103
)
117-
monkeypatch.setattr(
118-
"sketch_map_tool.routes.extract_centroids",
119-
lambda *_: {"type": "FeatureCollection", "features": []},
120-
)
121104
monkeypatch.setattr(
122105
"sketch_map_tool.routes.zip_",
123106
lambda *_: BytesIO(),

tests/unit/test_routes_api_status.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def test_status_failure_hard(
9191
(
9292
"raster-results",
9393
"vector-results",
94-
"centroid-results",
9594
),
9695
)
9796
def test_group_status_success(
@@ -114,7 +113,6 @@ def test_group_status_success(
114113
(
115114
"raster-results",
116115
"vector-results",
117-
"centroid-results",
118116
),
119117
)
120118
def test_group_status_started(
@@ -137,7 +135,6 @@ def test_group_status_started(
137135
(
138136
"raster-results",
139137
"vector-results",
140-
"centroid-results",
141138
),
142139
)
143140
@pytest.mark.parametrize(
@@ -163,7 +160,6 @@ def test_group_status_failure(client, uuid, type_, mock_group_result_failure, la
163160
(
164161
"raster-results",
165162
"vector-results",
166-
"centroid-results",
167163
),
168164
)
169165
def test_group_status_failure_hard(
@@ -189,7 +185,6 @@ def test_group_status_failure_hard(
189185
(
190186
"raster-results",
191187
"vector-results",
192-
"centroid-results",
193188
),
194189
)
195190
def test_group_status_started_success_failure(
@@ -222,7 +217,6 @@ def test_group_status_started_success_failure(
222217
(
223218
"raster-results",
224219
"vector-results",
225-
"centroid-results",
226220
),
227221
)
228222
def test_group_status_success_failure(

0 commit comments

Comments
 (0)