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
51 changes: 23 additions & 28 deletions apps/project/graphql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TestValidateAoiObjectsResponse,
TestValidateTaskingManagerProjectResponse,
)
from apps.project.models import Organization, Project, ProjectAsset, ProjectTypeEnum
from apps.project.models import Organization, Project, ProjectAsset, ProjectAssetInputTypeEnum, ProjectTypeEnum
from project_types.base.project import ValidationException
from project_types.validate.project import ValidateProject
from utils import fields
Expand Down Expand Up @@ -47,6 +47,7 @@ def _get_raster_tile_server_type(enum: RasterTileServerNameEnumWithoutCustom):
credits=config["credits"],
min_zoom=config["min_zoom"],
max_zoom=config["max_zoom"],
disabled=config["disabled"],
)

def _get_vector_tile_server_type(enum: VectorTileServerNameEnumWithoutCustom):
Expand All @@ -65,9 +66,8 @@ def _get_vector_tile_server_type(enum: VectorTileServerNameEnumWithoutCustom):
raster=[
_get_raster_tile_server_type(RasterTileServerNameEnum.BING),
_get_raster_tile_server_type(RasterTileServerNameEnum.MAPBOX),
# NOTE: Disabled because it's not working for 2+ years
# _get_raster_tile_server_type(RasterTileServerNameEnum.MAXAR_STANDARD),
# _get_raster_tile_server_type(RasterTileServerNameEnum.MAXAR_PREMIUM),
_get_raster_tile_server_type(RasterTileServerNameEnum.MAXAR_STANDARD),
_get_raster_tile_server_type(RasterTileServerNameEnum.MAXAR_PREMIUM),
_get_raster_tile_server_type(RasterTileServerNameEnum.ESRI),
_get_raster_tile_server_type(RasterTileServerNameEnum.ESRI_BETA),
],
Expand All @@ -93,29 +93,30 @@ def default_custom_options(self, project_type: ProjectTypeEnum) -> list[CustomOp
@strawberry.field(extensions=[IsAuthenticated()])
def test_aoi_objects(
self,
project_id: strawberry.ID | None,
asset_id: strawberry.ID | None,
ohsome_filter: str | None,
project_id: strawberry.ID,
asset_id: strawberry.ID,
ohsome_filter: str,
) -> TestValidateAoiObjectsResponse:
response = TestValidateAoiObjectsResponse(
project_id=project_id,
asset_id=asset_id,
ohsome_filter=ohsome_filter,
)

if project_id is None:
return response.generate_error("project_id is required to test aoi elements")

if asset_id is None:
return response.generate_error("asset_id is required to test aoi elements")

if ohsome_filter is None:
return response.generate_error("ohsome_filter is required to test aoi elements")

try:
object_count = ValidateProject.test_ohsome_objects_from_aoi_asset(
project_id,
asset_id,
aoi_asset = (
ProjectAsset.usable_objects()
.filter(
id=asset_id,
type=ProjectAsset.Type.INPUT,
input_type=ProjectAssetInputTypeEnum.AOI_GEOMETRY,
project_id=project_id,
)
.first()
)

object_count, _ = ValidateProject.test_ohsome_objects_from_aoi_asset(
aoi_asset,
ohsome_filter,
)

Expand All @@ -129,22 +130,16 @@ def test_aoi_objects(
@strawberry.field(extensions=[IsAuthenticated()])
def test_tasking_manager_project(
self,
hot_tm_id: fields.PydanticId | None,
ohsome_filter: str | None,
hot_tm_id: fields.PydanticId,
ohsome_filter: str,
) -> TestValidateTaskingManagerProjectResponse:
response = TestValidateTaskingManagerProjectResponse(
hot_tm_id=hot_tm_id,
ohsome_filter=ohsome_filter,
)

if hot_tm_id is None:
return response.generate_error("hot_tm_id is required to test HOT project aoi elements")

if ohsome_filter is None:
return response.generate_error("ohsome_filter is required to test HOT project aoi elements")

try:
object_count = ValidateProject.test_tasking_manager_project(
object_count, _, _ = ValidateProject.test_tasking_manager_project(
hot_tm_id,
ohsome_filter,
)
Expand Down
1 change: 1 addition & 0 deletions apps/project/graphql/types/project_types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RasterTileServerType:
min_zoom: int | None
max_zoom: int | None
credits: str
disabled: bool


@strawberry.type
Expand Down
1 change: 1 addition & 0 deletions apps/project/graphql/types/project_types/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ValidateTestAoiResponse:
object_count: int | None = None
ohsome_filter: str | None = None

# TODO(tnagorra): This needs to be generic. Create a base response class.
def generate_error(self, message: str = DEFAULT_TEST_RESPONSE_ERROR_MESSAGE):
self.ok = False
self.error = message
Expand Down
4 changes: 2 additions & 2 deletions apps/project/tests/e2e_create_validate_project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class Mutation:

class Query:
TEST_AOI_OBJECTS = """
query TestAoiObjects($assetId: ID, $projectId: ID, $ohsomeFilter: String) {
query TestAoiObjects($assetId: ID!, $projectId: ID!, $ohsomeFilter: String!) {
testAoiObjects(assetId: $assetId, projectId: $projectId, ohsomeFilter: $ohsomeFilter) {
ok
error
Expand All @@ -309,7 +309,7 @@ class Query:
"""

TEST_TASKING_MANAGER_PROJECT = """
query TestTaskingManagerProject($hotTmId: String, $ohsomeFilter: String) {
query TestTaskingManagerProject($hotTmId: String!, $ohsomeFilter: String!) {
testTaskingManagerProject(hotTmId: $hotTmId, ohsomeFilter: $ohsomeFilter) {
ok
error
Expand Down
6 changes: 3 additions & 3 deletions project_types/street/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def validate(self) -> Grouping[StreetFeature]:
raise Exception("Could not find AOI geometry asset")

asset_specific_data = AoiGeometryAssetProperty.model_validate(aoi_asset.asset_type_specifics)
allowed_area = 20
if asset_specific_data.area > allowed_area:
raise base_project.ValidationException(f"Area for AOI Geometry must be less than {allowed_area} sq. km")
MAX_AOI_AREA = 20
if asset_specific_data.area > MAX_AOI_AREA:
raise base_project.ValidationException(f"Area for AOI Geometry must be less than {MAX_AOI_AREA} sq. km")

with aoi_asset.file.open() as aoi_file:
aoi_geojson = json.loads(aoi_file.read())
Expand Down
6 changes: 3 additions & 3 deletions project_types/tile_map_service/base/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ def validate(self):
raise Exception("Could not find AOI geometry asset")

asset_specific_data = AoiGeometryAssetProperty.model_validate(aoi_asset.asset_type_specifics)
allowed_area = 5 * (4 ** (23 - self.project_type_specifics.zoom_level))
if asset_specific_data.area > allowed_area:
raise base_project.ValidationException(f"Area for AOI Geometry must be less than {allowed_area} sq. km")
max_aoi_area = 5 * (4 ** (23 - self.project_type_specifics.zoom_level))
if asset_specific_data.area > max_aoi_area:
raise base_project.ValidationException(f"Area for AOI Geometry must be less than {max_aoi_area} sq. km")

extension = Path(aoi_asset.file.name).suffix
with tempfile.NamedTemporaryFile(suffix=extension, dir=Config.TEMP_DIR) as temp_file:
Expand Down
Loading
Loading