Skip to content

Commit

Permalink
Merge pull request #88 from traveltime-dev/add-level-of-detail
Browse files Browse the repository at this point in the history
Added support for choosing level_of_detail in time-map
  • Loading branch information
arnasbr authored Oct 23, 2023
2 parents 54b35cb + 69d2c8e commit 0e4962e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Given origin coordinates, find shapes of zones reachable within corresponding tr
* transportation: Union - Transportation mode and related parameters.
* search_range: Range - When enabled, range adds an arrival window to the arrival time, and results are returned for any
journeys that arrive during this window.
* level_of_detail: LevelOfDetail - When enabled, allows the user to specify how detailed the isochrones should be.

### JSON response

Expand Down
14 changes: 13 additions & 1 deletion tests/time_map_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from datetime import datetime

from traveltimepy import Coordinates, Driving
from traveltimepy import Coordinates, Driving, LevelOfDetail, Range


@pytest.mark.asyncio
Expand All @@ -14,6 +14,8 @@ async def test_departures(sdk):
departure_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(results) == 2

Expand All @@ -28,6 +30,8 @@ async def test_departures_geojson(sdk):
departure_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(results) == 2

Expand All @@ -42,6 +46,8 @@ async def test_arrivals(sdk):
arrival_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(results) == 2

Expand All @@ -56,6 +62,8 @@ async def test_arrivals_geojson(sdk):
arrival_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(results) == 2

Expand All @@ -70,6 +78,8 @@ async def test_union_departures(sdk):
departure_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(result.shapes) > 0

Expand All @@ -84,5 +94,7 @@ async def test_intersection_arrivals(sdk):
arrival_time=datetime.now(),
travel_time=900,
transportation=Driving(),
search_range=Range(enabled=True, width=1800),
level_of_detail=LevelOfDetail(scale_type="simple", level="lowest"),
)
assert len(result.shapes) > 0
2 changes: 2 additions & 0 deletions traveltimepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
FullRange,
Range,
Rectangle,
LevelOfDetail,
)

from traveltimepy.sdk import TravelTimeSdk
Expand All @@ -45,6 +46,7 @@
"FullRange",
"Range",
"Rectangle",
"LevelOfDetail",
"TravelTimeSdk",
"Transportation",
"ZonesProperty",
Expand Down
6 changes: 6 additions & 0 deletions traveltimepy/dto/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ class FullRange(BaseModel):
class Range(BaseModel):
enabled: bool
width: int


class LevelOfDetail(BaseModel):
scale_type: Literal["simple", "simple_numeric", "coarse_grid"] = "simple"
level: Optional[Union[int, str]]
square_size: Optional[int]
3 changes: 3 additions & 0 deletions traveltimepy/dto/requests/time_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Cycling,
DrivingTrain,
CyclingPublicTransport,
LevelOfDetail,
)
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.dto.responses.time_map import TimeMapResponse
Expand All @@ -36,6 +37,7 @@ class DepartureSearch(BaseModel):
CyclingPublicTransport,
]
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None


class ArrivalSearch(BaseModel):
Expand All @@ -53,6 +55,7 @@ class ArrivalSearch(BaseModel):
CyclingPublicTransport,
]
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None


class Intersection(BaseModel):
Expand Down
3 changes: 3 additions & 0 deletions traveltimepy/dto/requests/time_map_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Cycling,
DrivingTrain,
CyclingPublicTransport,
LevelOfDetail,
)
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.itertools import split, flatten
Expand All @@ -36,6 +37,7 @@ class DepartureSearch(BaseModel):
CyclingPublicTransport,
]
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None


class ArrivalSearch(BaseModel):
Expand All @@ -53,6 +55,7 @@ class ArrivalSearch(BaseModel):
CyclingPublicTransport,
]
range: Optional[Range] = None
level_of_detail: Optional[LevelOfDetail] = None


class TimeMapRequestGeojson(TravelTimeRequest[FeatureCollection]):
Expand Down
21 changes: 20 additions & 1 deletion traveltimepy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from traveltimepy.errors import ApiError
from traveltimepy import TimeFilterFastRequest_pb2

from traveltimepy.dto.common import Location, Coordinates, FullRange, Property, Range
from traveltimepy.dto.common import (
Location,
Coordinates,
FullRange,
Property,
Range,
LevelOfDetail,
)
from traveltimepy.dto.transportation import (
PublicTransport,
Driving,
Expand Down Expand Up @@ -353,6 +360,7 @@ def create_time_map(
departure_time: Optional[datetime],
arrival_time: Optional[datetime],
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
) -> TimeMapRequest:
if arrival_time is not None and departure_time is not None:
raise ApiError("arrival_time and departure_time cannot be both specified")
Expand All @@ -367,6 +375,7 @@ def create_time_map(
arrival_time=arrival_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -384,6 +393,7 @@ def create_time_map(
departure_time=departure_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -410,6 +420,7 @@ def create_time_map_geojson(
departure_time: Optional[datetime],
arrival_time: Optional[datetime],
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
) -> TimeMapRequestGeojson:
if arrival_time is not None and departure_time is not None:
raise ApiError("arrival_time and departure_time cannot be both specified")
Expand All @@ -424,6 +435,7 @@ def create_time_map_geojson(
arrival_time=arrival_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -439,6 +451,7 @@ def create_time_map_geojson(
departure_time=departure_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -463,6 +476,7 @@ def create_intersection(
departure_time: Optional[datetime],
arrival_time: Optional[datetime],
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
) -> TimeMapRequest:
if arrival_time is not None and departure_time is not None:
raise ApiError("arrival_time and departure_time cannot be both specified")
Expand All @@ -477,6 +491,7 @@ def create_intersection(
arrival_time=arrival_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -499,6 +514,7 @@ def create_intersection(
departure_time=departure_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down Expand Up @@ -530,6 +546,7 @@ def create_union(
departure_time: Optional[datetime],
arrival_time: Optional[datetime],
search_range: Optional[Range],
level_of_detail: Optional[LevelOfDetail],
) -> TimeMapRequest:
if arrival_time is not None and departure_time is not None:
raise ApiError("arrival_time and departure_time cannot be both specified")
Expand All @@ -544,6 +561,7 @@ def create_union(
arrival_time=arrival_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand All @@ -566,6 +584,7 @@ def create_union(
departure_time=departure_time,
transportation=transportation,
range=search_range,
level_of_detail=level_of_detail,
)
for ind, cur_coordinates in enumerate(coordinates)
],
Expand Down
9 changes: 9 additions & 0 deletions traveltimepy/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Property,
FullRange,
Range,
LevelOfDetail,
)
from traveltimepy.dto.transportation import (
PublicTransport,
Expand Down Expand Up @@ -388,6 +389,7 @@ async def intersection_async(
departure_time: Optional[datetime] = None,
travel_time: int = 3600,
search_range: Optional[Range] = None,
level_of_detail: Optional[LevelOfDetail] = None,
) -> TimeMapResult:
resp = await send_post_async(
TimeMapResponse,
Expand All @@ -400,6 +402,7 @@ async def intersection_async(
arrival_time,
departure_time,
search_range,
level_of_detail,
),
self._sdk_params,
)
Expand All @@ -421,6 +424,7 @@ async def union_async(
departure_time: Optional[datetime] = None,
travel_time: int = 3600,
search_range: Optional[Range] = None,
level_of_detail: Optional[LevelOfDetail] = None,
) -> TimeMapResult:
resp = await send_post_async(
TimeMapResponse,
Expand All @@ -433,6 +437,7 @@ async def union_async(
arrival_time,
departure_time,
search_range,
level_of_detail,
),
self._sdk_params,
)
Expand All @@ -455,6 +460,7 @@ async def time_map_async(
departure_time: Optional[datetime] = None,
travel_time: int = 3600,
search_range: Optional[Range] = None,
level_of_detail: Optional[LevelOfDetail] = None,
) -> List[TimeMapResult]:
resp = await send_post_async(
TimeMapResponse,
Expand All @@ -467,6 +473,7 @@ async def time_map_async(
arrival_time,
departure_time,
search_range,
level_of_detail,
),
self._sdk_params,
)
Expand All @@ -488,6 +495,7 @@ async def time_map_geojson_async(
departure_time: Optional[datetime] = None,
travel_time: int = 3600,
search_range: Optional[Range] = None,
level_of_detail: Optional[LevelOfDetail] = None,
) -> FeatureCollection:
resp = await send_post_geojson_async(
FeatureCollection,
Expand All @@ -500,6 +508,7 @@ async def time_map_geojson_async(
arrival_time,
departure_time,
search_range,
level_of_detail,
),
self._sdk_params,
)
Expand Down

0 comments on commit 0e4962e

Please sign in to comment.