Skip to content

Commit

Permalink
Adding polygons_filter (#146)
Browse files Browse the repository at this point in the history
* Adding polygon_filter
  • Loading branch information
arnasbr authored Oct 23, 2024
1 parent 6bf8b67 commit 4003e5e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 13 deletions.
4 changes: 4 additions & 0 deletions traveltimepy/dto/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class LevelOfDetail(BaseModel):
square_size: Optional[int] = None


class PolygonsFilter(BaseModel):
limit: int


class TimeInfo:
def __init__(self, time_value: datetime):
self.value = time_value
Expand Down
4 changes: 3 additions & 1 deletion traveltimepy/dto/requests/distance_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CyclingPublicTransport,
LevelOfDetail,
)
from traveltimepy.dto.common import Snapping
from traveltimepy.dto.common import PolygonsFilter, Snapping
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.dto.responses.time_map import TimeMapResponse
from traveltimepy.itertools import split, flatten
Expand All @@ -38,6 +38,7 @@ class DepartureSearch(BaseModel):
]
level_of_detail: Optional[LevelOfDetail] = None
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter] = None


class ArrivalSearch(BaseModel):
Expand All @@ -56,6 +57,7 @@ class ArrivalSearch(BaseModel):
]
level_of_detail: Optional[LevelOfDetail] = None
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter] = None


class Intersection(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions traveltimepy/dto/requests/time_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CyclingPublicTransport,
LevelOfDetail,
)
from traveltimepy.dto.common import Snapping
from traveltimepy.dto.common import PolygonsFilter, Snapping
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.dto.responses.time_map import TimeMapResponse
from traveltimepy.itertools import split, flatten
Expand All @@ -40,6 +40,7 @@ class DepartureSearch(BaseModel):
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None
snapping: Optional[Snapping]
polygons_filter: Optional[PolygonsFilter]


class ArrivalSearch(BaseModel):
Expand All @@ -59,6 +60,7 @@ class ArrivalSearch(BaseModel):
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter]


class Intersection(BaseModel):
Expand All @@ -76,7 +78,6 @@ class TimeMapRequest(TravelTimeRequest[TimeMapResponse]):
arrival_searches: List[ArrivalSearch]
unions: List[Union]
intersections: List[Intersection]
snapping: Optional[Snapping] = None

def split_searches(self, window_size: int) -> List[TravelTimeRequest]:
return [
Expand Down
2 changes: 2 additions & 0 deletions traveltimepy/dto/requests/time_map_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from traveltimepy.dto.common import (
Coordinates,
LevelOfDetail,
PolygonsFilter,
Snapping,
)
from traveltimepy.dto.requests.request import TravelTimeRequest
Expand All @@ -21,6 +22,7 @@ class Search(BaseModel):
arrival_time_period: str
level_of_detail: Optional[LevelOfDetail] = None
snapping: Optional[Snapping] = None
polygons_filter: Optional[PolygonsFilter] = None


class ArrivalSearches(BaseModel):
Expand Down
45 changes: 35 additions & 10 deletions traveltimepy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Location,
Coordinates,
FullRange,
PolygonsFilter,
Property,
Range,
LevelOfDetail,
Expand Down Expand Up @@ -127,6 +128,7 @@ def create_time_map_fast(
travel_time: int,
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
one_to_many: bool = True,
) -> TimeMapFastRequest:
if one_to_many:
Expand All @@ -138,9 +140,10 @@ def create_time_map_fast(
coords=cur_coordinates,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -156,9 +159,10 @@ def create_time_map_fast(
coords=cur_coordinates,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -173,6 +177,7 @@ def create_time_map_fast_geojson(
travel_time: int,
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
one_to_many: bool = True,
) -> TimeMapFastGeojsonRequest:
if one_to_many:
Expand All @@ -184,9 +189,10 @@ def create_time_map_fast_geojson(
coords=cur_coordinates,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -202,9 +208,10 @@ def create_time_map_fast_geojson(
coords=cur_coordinates,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -235,7 +242,7 @@ def create_time_filter_fast(
arrival_location_ids=arrival_ids,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
properties=properties,
snapping=snapping,
)
Expand All @@ -255,7 +262,7 @@ def create_time_filter_fast(
departure_location_ids=departure_ids,
transportation=transportation,
travel_time=travel_time,
arrival_time_period="weekday_morning", # TODO: make customizable with enum / literal
arrival_time_period="weekday_morning",
properties=properties,
snapping=snapping,
)
Expand Down Expand Up @@ -453,6 +460,7 @@ def create_time_map(
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -466,6 +474,7 @@ def create_time_map(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -485,6 +494,7 @@ def create_time_map(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -511,7 +521,8 @@ def create_time_map_geojson(
time_info: TimeInfo,
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping] = None,
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> TimeMapRequestGeojson:
if isinstance(time_info, ArrivalTime):
return TimeMapRequestGeojson(
Expand All @@ -525,6 +536,7 @@ def create_time_map_geojson(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -542,6 +554,7 @@ def create_time_map_geojson(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -566,7 +579,8 @@ def create_time_map_wkt(
time_info: TimeInfo,
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping] = None,
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> TimeMapWKTRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapWKTRequest(
Expand All @@ -580,6 +594,7 @@ def create_time_map_wkt(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -596,6 +611,7 @@ def create_time_map_wkt(
transportation=transportation,
range=search_range,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -620,6 +636,7 @@ def create_distance_map(
time_info: TimeInfo,
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> DistanceMapRequest:
if isinstance(time_info, ArrivalTime):
return DistanceMapRequest(
Expand All @@ -632,6 +649,7 @@ def create_distance_map(
transportation=transportation,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -650,6 +668,7 @@ def create_distance_map(
transportation=transportation,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -676,7 +695,8 @@ def create_intersection(
time_info: TimeInfo,
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping] = None,
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -690,6 +710,7 @@ def create_intersection(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -714,6 +735,7 @@ def create_intersection(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -745,7 +767,8 @@ def create_union(
time_info: TimeInfo,
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
snapping: Optional[Snapping] = None,
snapping: Optional[Snapping],
polygons_filter: Optional[PolygonsFilter],
) -> TimeMapRequest:
if isinstance(time_info, ArrivalTime):
return TimeMapRequest(
Expand All @@ -759,6 +782,7 @@ def create_union(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -783,6 +807,7 @@ def create_union(
range=search_range,
level_of_detail=level_of_detail,
snapping=snapping,
polygons_filter=polygons_filter,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down
Loading

0 comments on commit 4003e5e

Please sign in to comment.