Skip to content

Bu 24 update sdk for beam saved location support #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions predicthq/endpoints/v1/beam/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
CreateAnalysisGroupResponse,
AnalysisGroup,
AnalysisGroupResultSet,
GeoJson,
Place
)
from predicthq.endpoints.decorators import accepts, returns
from typing import overload, List, Optional, TextIO, Union
Expand All @@ -29,6 +31,7 @@ def create(
location__unit: Optional[str] = None,
location__google_place_id: Optional[str] = None,
location__geoscope_paths: Optional[List[str]] = None,
location__saved_location_id: Optional[str] = None,
rank__type: Optional[str] = None,
rank__levels__phq: Optional[dict] = None,
rank__levels__local: Optional[dict] = None,
Expand Down Expand Up @@ -70,6 +73,7 @@ def search(
limit: Optional[int] = None,
external_id: Optional[List[str]] = None,
label: Optional[List[str]] = None,
location__saved_location_id: Optional[List[str]] = None,
**params,
): ...
@accepts()
Expand Down Expand Up @@ -102,6 +106,7 @@ def update(
location__unit: Optional[str] = None,
location__google_place_id: Optional[str] = None,
location__geoscope_paths: Optional[List[str]] = None,
location__saved_location_id: Optional[str] = None,
rank__type: Optional[str] = None,
rank__levels__phq: Optional[dict] = None,
rank__levels__local: Optional[dict] = None,
Expand Down
75 changes: 75 additions & 0 deletions predicthq/endpoints/v1/beam/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
from predicthq.endpoints.schemas import ArgKwargResultSet
from typing import Optional, List

# Python < 3.11 does not have StrEnum in the enum module
import sys
if sys.version_info < (3, 11):
import enum

class StrEnum(str, enum.Enum):
pass
else:
from enum import StrEnum

# Python < 3.9 does not have Annotated
if sys.version_info < (3, 9):
from typing_extensions import Annotated
else:
from typing import Annotated

# Python < 3.8 does not have Literal
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


class BeamPaginationResultSet(ArgKwargResultSet):
def has_next(self):
Expand Down Expand Up @@ -113,6 +135,58 @@ class DemandType(DemandTypeGroup):
currency_code: str


class RadiusUnit(StrEnum):
m = "m"
km = "km"
mi = "mi"
ft = "ft"


class GeoJsonGeometryType(StrEnum):
POINT = "Point"
POLYGON = "Polygon"
MULTI_POLYGON = "MultiPolygon"
LINE_STRING = "LineString"
MULTI_LINE_STRING = "MultiLineString"


class GeoJsonProperties(BaseModel):
radius: Annotated[float, Field(gt=0)]
radius_unit: RadiusUnit


class GeoJsonGeometry(BaseModel):
type: GeoJsonGeometryType
coordinates: Annotated[list, Field(min_length=1)]


class GeoJson(BaseModel):
type: Literal["Feature"]
properties: Optional[GeoJsonProperties] = None
geometry: GeoJsonGeometry


class Place(BaseModel):
place_id: int
type: str
name: str
county: Optional[str] = None
region: Optional[str] = None
country: Optional[str] = None
geojson: GeoJson


class SavedLocation(BaseModel):
name: Optional[str] = None
formatted_address: Optional[str] = None
geojson: Optional[GeoJson] = None
h3: Optional[List[str]] = None
place_ids: Optional[List[int]] = None
place_hierarchies: Optional[List[str]] = None
places: Optional[List[Place]] = None
location_id: str


class Analysis(BaseModel):
model_config: ConfigDict = ConfigDict(extra="allow")

Expand All @@ -134,6 +208,7 @@ class Analysis(BaseModel):
processed_dt: Optional[datetime] = None
external_id: Optional[str] = None
label: Optional[List[str]] = None
saved_location: Optional[SavedLocation] = None


class AnalysisResultSet(BeamPaginationResultSet):
Expand Down
12 changes: 12 additions & 0 deletions tests/endpoints/v1/test_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_search_params_underscores(self, client):
limit=10,
external_id="external_id",
label=["label1", "label2"],
location__saved_location_id="saved_location_id",
)

client.request.assert_called_once_with(
Expand All @@ -72,6 +73,7 @@ def test_search_params_underscores(self, client):
"limit": 10,
"external_id": "external_id",
"label": "label1,label2",
"location.saved_location_id": "saved_location_id",
},
verify=True,
)
Expand All @@ -98,6 +100,7 @@ def test_search_params_dicts(self, client):
limit=10,
external_id="external_id",
label=["label1", "label2"],
location__saved_location_id="saved_location_id",
)

client.request.assert_called_once_with(
Expand All @@ -120,6 +123,7 @@ def test_search_params_dicts(self, client):
"limit": 10,
"external_id": "external_id",
"label": "label1,label2",
"location.saved_location_id": "saved_location_id",
},
verify=True,
)
Expand All @@ -135,6 +139,7 @@ def test_create_params_underscores(self, client):
location__unit="km",
location__google_place_id="google_place_id",
location__geoscope_paths=["geoscope_path1", "geoscope_path2"],
location__saved_location_id="saved_location_id",
rank__type="type",
rank__levels__phq={"min": 1.0, "max": 2.0},
rank__levels__local={"min": 3.0, "max": 4.0},
Expand All @@ -158,6 +163,7 @@ def test_create_params_underscores(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
"rank": {
"type": "type",
Expand Down Expand Up @@ -192,6 +198,7 @@ def test_create_params_dicts(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
rank={
"type": "type",
Expand Down Expand Up @@ -222,6 +229,7 @@ def test_create_params_dicts(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
"rank": {
"type": "type",
Expand Down Expand Up @@ -255,6 +263,7 @@ def test_update_params_underscores(self, client):
location__unit="km",
location__google_place_id="google_place_id",
location__geoscope_paths=["geoscope_path1", "geoscope_path2"],
location__saved_location_id="saved_location_id",
rank__type="type",
rank__levels__phq={"min": 1.0, "max": 2.0},
rank__levels__local={"min": 3.0, "max": 4.0},
Expand All @@ -278,6 +287,7 @@ def test_update_params_underscores(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
"rank": {
"type": "type",
Expand Down Expand Up @@ -310,6 +320,7 @@ def test_update_params_dicts(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
rank={
"type": "type",
Expand Down Expand Up @@ -340,6 +351,7 @@ def test_update_params_dicts(self, client):
"unit": "km",
"google_place_id": "google_place_id",
"geoscope_paths": ["geoscope_path1", "geoscope_path2"],
"saved_location_id": "saved_location_id",
},
"rank": {
"type": "type",
Expand Down