Skip to content

Commit

Permalink
fix(stats): adds area threshold in the stats api along with timeout r…
Browse files Browse the repository at this point in the history
…educed to 30 second
  • Loading branch information
kshitijrajsharma committed Mar 28, 2024
1 parent 012f7ce commit 85fb634
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion API/raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def get_osm_current_snapshot_as_plain_geojson(
"""
area_m2 = area(json.loads(params.geometry.model_dump_json()))
area_km2 = area_m2 * 1e-6
if area_km2 > 10:
if area_km2 > 5:
raise HTTPException(
status_code=400,
detail=[
Expand Down
7 changes: 4 additions & 3 deletions src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import Dict, List, Optional, Union

# Third party imports
from area import area
from geojson_pydantic import Feature, FeatureCollection, MultiPolygon, Polygon
from geojson_pydantic.types import BBox
from pydantic import BaseModel as PydanticModel
Expand Down Expand Up @@ -331,12 +332,12 @@ def set_geometry_or_iso3(cls, value, values):
def validate_geometry_area(cls, value):
"""Validate that the geometry area does not exceed threshold."""
if value is not None:
geometry_json = json.loads(value.model_dump_json())
area_m2 = cls.calculate_geometry_area(geometry_json)
geometry_json = value
area_m2 = area(geometry_json)
max_area = 10000
if area_m2 * 1e-6 > max_area:
raise ValueError(
f"The area of the geometry should not exceed {max_area} square km."
f"The area {area_m2 * 1e-6} sqkm of the geometry should not exceed {max_area} square km."
)
return value

Expand Down

0 comments on commit 85fb634

Please sign in to comment.