-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from hotosm/feature/yaml-support
Feature : Custom Exports YAML support
- Loading branch information
Showing
5 changed files
with
1,430 additions
and
1,288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,13 @@ | |
# <[email protected]> | ||
"""Page contains validation models for application""" | ||
# Standard library imports | ||
import json | ||
from enum import Enum | ||
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 | ||
from pydantic import Field, validator | ||
from typing_extensions import TypedDict | ||
|
||
# Reader imports | ||
from src.config import ( | ||
|
@@ -560,32 +556,19 @@ def validate_frequency(cls, value): | |
return value.strip() | ||
|
||
|
||
class DynamicCategoriesModel(BaseModel, GeometryValidatorMixin): | ||
""" | ||
Model for dynamic categories. | ||
Fields: | ||
- iso3 (Optional[str]): ISO3 Country Code. | ||
- dataset (Optional[DatasetConfig]): Dataset Configurations for HDX Upload. | ||
- meta (bool): Dumps Meta db in parquet format & HDX config JSON to S3. | ||
- hdx_upload (bool): Enable/Disable uploading the dataset to HDX. | ||
- categories (List[Dict[str, CategoryModel]]): List of dynamic categories. | ||
- geometry (Optional[Union[Polygon, MultiPolygon]]): Custom polygon geometry. | ||
""" | ||
|
||
iso3: Optional[str] = Field( | ||
default=None, | ||
description="ISO3 Country Code", | ||
min_length=3, | ||
max_length=3, | ||
example="USA", | ||
) | ||
class CategoriesBase(BaseModel): | ||
hdx_upload: bool = Field( | ||
default=False, | ||
description="Enable/Disable uploading dataset to hdx, False by default", | ||
) | ||
dataset: Optional[DatasetConfig] = Field( | ||
default=None, description="Dataset Configurations for HDX Upload" | ||
default=None, | ||
description="Dataset Configurations for HDX Upload", | ||
example={ | ||
"dataset_prefix": "hotosm_project_1", | ||
"dataset_folder": "TM", | ||
"dataset_title": "Tasking Manger Project 1", | ||
}, | ||
) | ||
queue: Optional[str] = Field( | ||
default="raw_ondemand", | ||
|
@@ -607,12 +590,33 @@ class DynamicCategoriesModel(BaseModel, GeometryValidatorMixin): | |
}, | ||
"types": ["lines", "polygons"], | ||
"select": ["name", "highway"], | ||
"where": "highway IS NOT NULL", | ||
"where": "tags['highway'] IS NOT NULL", | ||
"formats": ["geojson"], | ||
} | ||
} | ||
], | ||
) | ||
|
||
class DynamicCategoriesModel(CategoriesBase, GeometryValidatorMixin): | ||
""" | ||
Model for dynamic categories. | ||
Fields: | ||
- iso3 (Optional[str]): ISO3 Country Code. | ||
- dataset (Optional[DatasetConfig]): Dataset Configurations for HDX Upload. | ||
- meta (bool): Dumps Meta db in parquet format & HDX config JSON to S3. | ||
- hdx_upload (bool): Enable/Disable uploading the dataset to HDX. | ||
- categories (List[Dict[str, CategoryModel]]): List of dynamic categories. | ||
- geometry (Optional[Union[Polygon, MultiPolygon]]): Custom polygon geometry. | ||
""" | ||
|
||
iso3: Optional[str] = Field( | ||
default=None, | ||
description="ISO3 Country Code", | ||
min_length=3, | ||
max_length=3, | ||
example="USA", | ||
) | ||
geometry: Optional[ | ||
Union[Polygon, MultiPolygon, Feature, FeatureCollection] | ||
] = Field( | ||
|
@@ -653,3 +657,21 @@ def set_geometry_or_iso3(cls, value, values): | |
if item is None: | ||
raise ValueError(f"Missing, Dataset config : {item}") | ||
return value | ||
|
||
|
||
class CustomRequestsYaml(CategoriesBase): | ||
geometry: Union[Polygon, MultiPolygon, Feature, FeatureCollection] = Field( | ||
default=None, | ||
example={ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[83.96919250488281, 28.194446860487773], | ||
[83.99751663208006, 28.194446860487773], | ||
[83.99751663208006, 28.214869548073377], | ||
[83.96919250488281, 28.214869548073377], | ||
[83.96919250488281, 28.194446860487773], | ||
] | ||
], | ||
}, | ||
) |
Oops, something went wrong.