From 686c4ff9470691ce70d6bce49540561031c9f2c6 Mon Sep 17 00:00:00 2001 From: Arnas Bradauskas Date: Tue, 31 Oct 2023 16:39:18 +0200 Subject: [PATCH 1/2] Fixed partially wrong GEOJSON implementation --- traveltimepy/dto/requests/time_map.py | 4 +-- traveltimepy/dto/requests/time_map_geojson.py | 6 ++-- traveltimepy/http.py | 32 ------------------- traveltimepy/sdk.py | 3 +- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/traveltimepy/dto/requests/time_map.py b/traveltimepy/dto/requests/time_map.py index f224b95..cab9656 100644 --- a/traveltimepy/dto/requests/time_map.py +++ b/traveltimepy/dto/requests/time_map.py @@ -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 [ diff --git a/traveltimepy/dto/requests/time_map_geojson.py b/traveltimepy/dto/requests/time_map_geojson.py index 4834000..681de89 100644 --- a/traveltimepy/dto/requests/time_map_geojson.py +++ b/traveltimepy/dto/requests/time_map_geojson.py @@ -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 @@ -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, ) diff --git a/traveltimepy/http.py b/traveltimepy/http.py index c838131..b0ff969 100644 --- a/traveltimepy/http.py +++ b/traveltimepy/http.py @@ -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 diff --git a/traveltimepy/sdk.py b/traveltimepy/sdk.py index 768af48..3be202a 100644 --- a/traveltimepy/sdk.py +++ b/traveltimepy/sdk.py @@ -69,7 +69,6 @@ send_get_async, send_post_async, SdkParams, - send_post_geojson_async, ) from geojson_pydantic import FeatureCollection @@ -505,7 +504,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), From 2273bd2b3839935bf8e8f47eda9f2c0d1ccd24b4 Mon Sep 17 00:00:00 2001 From: Arnas Bradauskas Date: Mon, 6 Nov 2023 14:58:57 +0200 Subject: [PATCH 2/2] Bump version --- traveltimepy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traveltimepy/version.py b/traveltimepy/version.py index 46f67e7..975f691 100644 --- a/traveltimepy/version.py +++ b/traveltimepy/version.py @@ -1 +1 @@ -__version__ = "3.7.0" +__version__ = "3.7.1"