-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding time-map-fast json and geojson
- Loading branch information
Showing
5 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from typing import List, Optional | ||
from typing_extensions import Literal | ||
|
||
from pydantic import BaseModel | ||
|
||
from traveltimepy.dto.common import ( | ||
Coordinates, | ||
LevelOfDetail, | ||
Snapping, | ||
) | ||
from traveltimepy.dto.requests.request import TravelTimeRequest | ||
from traveltimepy.dto.responses.time_map import TimeMapResponse | ||
from traveltimepy.itertools import split, flatten | ||
|
||
|
||
class Transportation(BaseModel): | ||
type: Literal[ | ||
"public_transport", | ||
"walking+ferry", | ||
"cycling+ferry", | ||
"driving+ferry", | ||
"driving+public_transport", | ||
] | ||
|
||
|
||
class Search(BaseModel): | ||
id: str | ||
coords: Coordinates | ||
transportation: Transportation | ||
travel_time: int | ||
arrival_time_period: str | ||
level_of_detail: Optional[LevelOfDetail] = None | ||
snapping: Optional[Snapping] = None | ||
|
||
|
||
class ArrivalSearches(BaseModel): | ||
many_to_one: List[Search] | ||
one_to_many: List[Search] | ||
|
||
|
||
class TimeMapFastRequest(TravelTimeRequest[TimeMapResponse]): | ||
arrival_searches: ArrivalSearches | ||
|
||
def split_searches(self, window_size: int) -> List[TravelTimeRequest]: | ||
return [ | ||
TimeMapFastRequest( | ||
arrival_searches=ArrivalSearches( | ||
one_to_many=one_to_many, many_to_one=many_to_one | ||
), | ||
) | ||
for one_to_many, many_to_one in split( | ||
self.arrival_searches.one_to_many, | ||
self.arrival_searches.many_to_one, | ||
window_size, | ||
) | ||
] | ||
|
||
def merge(self, responses: List[TimeMapResponse]) -> TimeMapResponse: | ||
return TimeMapResponse( | ||
results=flatten([response.results for response in responses]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import List | ||
from geojson_pydantic import FeatureCollection | ||
|
||
from traveltimepy.dto.requests.request import TravelTimeRequest | ||
from traveltimepy.dto.requests.time_map_fast import ArrivalSearches | ||
from traveltimepy.itertools import split, flatten | ||
|
||
|
||
class TimeMapFastGeojsonRequest(TravelTimeRequest[FeatureCollection]): | ||
arrival_searches: ArrivalSearches | ||
|
||
def split_searches(self, window_size: int) -> List[TravelTimeRequest]: | ||
return [ | ||
TimeMapFastGeojsonRequest( | ||
arrival_searches=ArrivalSearches( | ||
one_to_many=one_to_many, many_to_one=many_to_one | ||
), | ||
) | ||
for one_to_many, many_to_one in split( | ||
self.arrival_searches.one_to_many, | ||
self.arrival_searches.many_to_one, | ||
window_size, | ||
) | ||
] | ||
|
||
def merge(self, responses: List[FeatureCollection]) -> FeatureCollection: | ||
merged_features = flatten([response.features for response in responses]) | ||
return FeatureCollection(type="FeatureCollection", features=merged_features) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters