Skip to content

Commit

Permalink
Merge branch 'master' into add-time-map-wkt
Browse files Browse the repository at this point in the history
  • Loading branch information
arnasbr authored Nov 13, 2023
2 parents ac69d10 + 63f3860 commit 7ca1d1a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 39 deletions.
4 changes: 2 additions & 2 deletions traveltimepy/dto/requests/time_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class Union(BaseModel):
class TimeMapRequest(TravelTimeRequest[TimeMapResponse]):
departure_searches: List[DepartureSearch]
arrival_searches: List[ArrivalSearch]
unions: List[Union]
intersections: List[Intersection]
unions: List[Union] = None
intersections: List[Intersection] = None

def split_searches(self, window_size: int) -> List[TravelTimeRequest]:
return [
Expand Down
6 changes: 3 additions & 3 deletions traveltimepy/dto/requests/time_map_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
LevelOfDetail,
)
from traveltimepy.dto.requests.request import TravelTimeRequest
from traveltimepy.dto.requests.time_map import TimeMapRequest
from traveltimepy.itertools import split, flatten


Expand Down Expand Up @@ -62,10 +63,9 @@ class TimeMapRequestGeojson(TravelTimeRequest[FeatureCollection]):
departure_searches: List[DepartureSearch]
arrival_searches: List[ArrivalSearch]

def split_searches(self, window_size: int) -> List[FeatureCollection]:
def split_searches(self, window_size: int) -> List[TravelTimeRequest]:
return [
FeatureCollection(
type="FeatureCollection",
TimeMapRequest(
departure_searches=departures,
arrival_searches=arrivals,
)
Expand Down
32 changes: 0 additions & 32 deletions traveltimepy/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,6 @@ async def send_post_async(
return request.merge(responses)


async def send_post_geojson_async(
response_class: Type[T],
path: str,
headers: Dict[str, str],
request: TravelTimeRequest,
sdk_params: SdkParams,
) -> T:
window_size = _window_size(sdk_params.rate_limit)
async with ClientSession(
connector=TCPConnector(ssl=False, limit_per_host=sdk_params.limit_per_host)
) as session:
retry_options = ExponentialRetry(attempts=sdk_params.retry_attempts)
async with RetryClient(
client_session=session, retry_options=retry_options
) as client:
rate_limit = AsyncLimiter(
sdk_params.rate_limit // window_size, sdk_params.time_window
)
tasks = [
send_post_request_async(
client,
response_class,
f"https://{sdk_params.host}/v4/{path}",
headers,
request,
rate_limit,
)
]
responses = await asyncio.gather(*tasks)
return request.merge(responses)


def _window_size(rate_limit: int):
if rate_limit >= DEFAULT_SPLIT_SIZE:
return DEFAULT_SPLIT_SIZE
Expand Down
3 changes: 1 addition & 2 deletions traveltimepy/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
send_get_async,
send_post_async,
SdkParams,
send_post_geojson_async,
)

from geojson_pydantic import FeatureCollection
Expand Down Expand Up @@ -509,7 +508,7 @@ async def time_map_geojson_async(
search_range: Optional[Range] = None,
level_of_detail: Optional[LevelOfDetail] = None,
) -> FeatureCollection:
resp = await send_post_geojson_async(
resp = await send_post_async(
FeatureCollection,
"time-map",
self._headers(AcceptType.GEO_JSON),
Expand Down

0 comments on commit 7ca1d1a

Please sign in to comment.