Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/feat: Default Route #621

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ data RouteV2 = RouteV2
viewport :: ViewPort,
distanceMeters :: Int,
duration :: Text,
staticDuration :: Maybe Text
staticDuration :: Maybe Text,
routeLabels :: Maybe [Text]
}
deriving (Generic, ToJSON, FromJSON, ToSchema)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ mkRoute' req route = do
if null route.legs
then do
logTagWarning "GoogleMapsDirections" ("Empty route.legs, " <> show req)
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] []
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] [] False
else do
when (length route.legs > 1) $
logTagWarning "GoogleMapsDirections" ("More than one element in route.legs, " <> show req)
Expand All @@ -203,8 +203,9 @@ mkRoute' req route = do
allSteps = foldr (\leg acc -> acc ++ leg.steps) [] route.legs
polylinePoints = concatMap (\step -> decode step.polyline.encodedPolyline) allSteps
totalStaticDuration = durationInS =<< route.staticDuration
isDefaultRoute = maybe False (any (== "DEFAULT_ROUTE")) route.routeLabels
totalDuration <- durationInS route.duration & fromMaybeM (InternalError "No duration value provided in advanced directions API response")
return $ RouteInfo (Just totalDuration) totalStaticDuration (Just totalDistance) (Just distanceWithUnit) bound [] polylinePoints
return $ RouteInfo (Just totalDuration) totalStaticDuration (Just totalDistance) (Just distanceWithUnit) bound [] polylinePoints isDefaultRoute
where
mkBounds :: GoogleMaps.ViewPort -> BoundingBoxWithoutCRS
mkBounds viewport =
Expand All @@ -227,7 +228,7 @@ mkRoute req route = do
if null route.legs
then do
logTagWarning "GoogleMapsDirections" ("Empty route.legs, " <> show req)
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] []
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] [] False
else do
when (length route.legs > 1) $
logTagWarning "GoogleMapsDirections" ("More than one element in route.legs, " <> show req)
Expand All @@ -240,7 +241,7 @@ mkRoute req route = do
-- TODO: Fix snappedWayPoints: the waypoint passed in request which are snapped to road
-- snappedWayPoints = (\step -> (LatLong step.start_location.lat step.start_location.lng, LatLong step.end_location.lat step.end_location.lng)) <$> steps

return $ RouteInfo (Just totalDuration) Nothing (Just totalDistance) (Just distanceWithUnit) bound [] polylinePoints
return $ RouteInfo (Just totalDuration) Nothing (Just totalDistance) (Just distanceWithUnit) bound [] polylinePoints False
where
mkBounds :: GoogleMaps.Bounds -> BoundingBoxWithoutCRS
mkBounds gBound =
Expand Down
4 changes: 2 additions & 2 deletions lib/mobility-core/src/Kernel/External/Maps/Interface/MMI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mkRoute req resp route = do
if null route.legs
then do
logTagWarning "MMIRoutes" ("Empty route.legs, " <> show req)
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] []
return $ RouteInfo Nothing Nothing Nothing Nothing bound [] [] False
else do
when (length route.legs > 1) $
logTagWarning "MMIRoutes" ("More than one element in route.legs, " <> show req)
Expand All @@ -205,7 +205,7 @@ mkRoute req resp route = do
distanceInM = Just $ Meters $ double2Int route.distance
distanceWithUnit = Just $ Distance (toHighPrecDistance route.distance) Meter
durationInS = Just $ Seconds $ double2Int route.duration
return $ RouteInfo durationInS Nothing distanceInM distanceWithUnit boundBox snappedWayPoints points
return $ RouteInfo durationInS Nothing distanceInM distanceWithUnit boundBox snappedWayPoints points False
where
createAcc = Acc {minLat = 91.0, maxLat = -91.0, minLon = 180.0, maxLon = -180.0}
boundingBoxCal points = foldl' compareLatLong createAcc points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ convertToRoute route =
distanceWithUnit = Just $ Distance (toHighPrecDistance route.distance) Meter,
boundingBox = Nothing,
snappedWaypoints = [],
points = PP.decode $ route.geometry
points = PP.decode $ route.geometry,
isDefaultRoute = False
}

latLongToPlace :: LatLong -> GoogleMaps.Place
Expand Down
3 changes: 2 additions & 1 deletion lib/mobility-core/src/Kernel/External/Maps/Interface/OSRM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ convertRouteToRouteInfo osrmRouteRoutes =
staticDuration = Nothing,
points = map (.getLatLong) osrmRouteRoutes.geometry.coordinates,
snappedWaypoints = map (\steps -> getLatLong $ head steps.geometry.coordinates) $ OSRM.steps $ head osrmRouteRoutes.legs,
boundingBox = Nothing
boundingBox = Nothing,
isDefaultRoute = False
}

getOSRMRoute ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ data RouteInfo = RouteInfo
distanceWithUnit :: Maybe Distance,
boundingBox :: Maybe BoundingBoxWithoutCRS,
snappedWaypoints :: [LatLong],
points :: [LatLong]
points :: [LatLong],
isDefaultRoute :: Bool
}
deriving (Generic, ToJSON, FromJSON, ToSchema, Show, Eq, Ord)

Expand Down
Loading