-
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.
Merge pull request #79 from traveltime-dev/add-time-map-geojson
Added support for time-map geojson response
- Loading branch information
Showing
6 changed files
with
231 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
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,63 @@ | ||
import typing | ||
from datetime import datetime | ||
|
||
from typing import List, Optional | ||
|
||
from geojson_pydantic import FeatureCollection | ||
from pydantic.main import BaseModel | ||
|
||
from traveltimepy import ( | ||
Coordinates, | ||
Range, | ||
PublicTransport, | ||
Driving, | ||
Ferry, | ||
Walking, | ||
Cycling, | ||
DrivingTrain, | ||
) | ||
from traveltimepy.dto.requests.request import TravelTimeRequest | ||
from traveltimepy.itertools import split, flatten | ||
|
||
|
||
class DepartureSearch(BaseModel): | ||
id: str | ||
coords: Coordinates | ||
departure_time: datetime | ||
travel_time: int | ||
transportation: typing.Union[ | ||
PublicTransport, Driving, Ferry, Walking, Cycling, DrivingTrain | ||
] | ||
range: Optional[Range] = None | ||
|
||
|
||
class ArrivalSearch(BaseModel): | ||
id: str | ||
coords: Coordinates | ||
arrival_time: datetime | ||
travel_time: int | ||
transportation: typing.Union[ | ||
PublicTransport, Driving, Ferry, Walking, Cycling, DrivingTrain | ||
] | ||
range: Optional[Range] = None | ||
|
||
|
||
class TimeMapRequestGeojson(TravelTimeRequest[FeatureCollection]): | ||
departure_searches: List[DepartureSearch] | ||
arrival_searches: List[ArrivalSearch] | ||
|
||
def split_searches(self, window_size: int) -> List[FeatureCollection]: | ||
return [ | ||
FeatureCollection( | ||
type="FeatureCollection", | ||
departure_searches=departures, | ||
arrival_searches=arrivals, | ||
) | ||
for departures, arrivals in split( | ||
self.departure_searches, self.arrival_searches, 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
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