update modality names to align with android app + routingservice WIP
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package SuMoC.backend.routing;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(RoutingProperties.class)
|
||||
public class RoutingConfig {
|
||||
}
|
||||
@@ -33,11 +33,11 @@ public class RoutingController {
|
||||
routingAlternativeRequestDTO.setRoutingPreferencesDTO(preferences);
|
||||
}
|
||||
|
||||
//var routeDTOs = routingService.getAlternativeRoute(routingAlternativeRequestDTO);
|
||||
// var routeDTOs = routingService.getAlternativeRoute(routingAlternativeRequestDTO);
|
||||
|
||||
// Mocking response for app development
|
||||
var routeDTOs = List.of(RouteDTO.getMockRouteDTO());
|
||||
|
||||
|
||||
|
||||
return ResponseEntity.ok(routeDTOs);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package SuMoC.backend.routing;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "routing")
|
||||
@Getter
|
||||
@Setter
|
||||
public class RoutingProperties {
|
||||
private int toleratedAdditionalTravelSeconds = 15 * 60;
|
||||
private int toleratedAdditionalPhysicalActivitiesSeconds = 30 * 60;
|
||||
}
|
||||
@@ -3,10 +3,12 @@ package SuMoC.backend.routing;
|
||||
import SuMoC.backend.carta.CartaClient;
|
||||
import SuMoC.backend.routing.dtos.RouteDTO;
|
||||
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
|
||||
import SuMoC.backend.routing.exceptions.NoCarRouteFoundException;
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import sumoc.backend.carta.client.model.Direction;
|
||||
import sumoc.backend.carta.client.model.Route;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -19,9 +21,12 @@ public class RoutingService {
|
||||
|
||||
private final CartaClient cartaClient;
|
||||
|
||||
private final RoutingProperties routingProperties;
|
||||
|
||||
@Autowired
|
||||
public RoutingService(CartaClient cartaClient) {
|
||||
public RoutingService(CartaClient cartaClient, RoutingProperties routingProperties) {
|
||||
this.cartaClient = cartaClient;
|
||||
this.routingProperties = routingProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +55,11 @@ public class RoutingService {
|
||||
|
||||
/**
|
||||
* Makes concurrent direction calls to CARTA for all modes requested + car as baseline.
|
||||
* Possible keys of the returned Map:
|
||||
* - car (always)
|
||||
* - walk (optional)
|
||||
* - bike (optional)
|
||||
* - transit (optional)
|
||||
*/
|
||||
private HashMap<String, Direction> getPossibleDirectionsFromCarta(RoutingAlternativeRequestDTO requestDTO) {
|
||||
Map<String, CompletableFuture<Direction>> futuresByMode = new HashMap<>();
|
||||
@@ -62,8 +72,8 @@ public class RoutingService {
|
||||
// add request futures for all modes request by user + assemble type string for a possible transit directions request
|
||||
for (Modality modality : requestDTO.getRoutingPreferencesDTO().getModalitiesToConsider()) {
|
||||
switch (modality) {
|
||||
case WALK -> futuresByMode.put("walk", getCartaFuture(requestDTO, "walking", "", 1));
|
||||
case BIKE -> futuresByMode.put("bike", getCartaFuture(requestDTO, "cycling", "", 1));
|
||||
case WALKING -> futuresByMode.put("walk", getCartaFuture(requestDTO, "walking", "", 1));
|
||||
case BICYCLE -> futuresByMode.put("bike", getCartaFuture(requestDTO, "cycling", "", 1));
|
||||
case BUS -> {
|
||||
typeList.add("3"); // bus
|
||||
typeList.add("8"); // trolleybus
|
||||
@@ -83,7 +93,7 @@ public class RoutingService {
|
||||
typeList.add("6"); // gondola
|
||||
typeList.add("7"); // funicular
|
||||
String types = String.join(",", typeList);
|
||||
futuresByMode.put("transit", getCartaFuture(requestDTO, "transit", types, 3));
|
||||
futuresByMode.put("transit", getCartaFuture(requestDTO, "transit", types, 1));
|
||||
}
|
||||
|
||||
// return all future results as list when resvoled
|
||||
@@ -94,13 +104,40 @@ public class RoutingService {
|
||||
return directions;
|
||||
}
|
||||
|
||||
// TODO think about error handling, what if no car route found?
|
||||
public List<RouteDTO> getAlternativeRoute(RoutingAlternativeRequestDTO requestDTO) {
|
||||
HashMap<String, Direction> directionHashMap = getPossibleDirectionsFromCarta(requestDTO);
|
||||
assert requestDTO.getRoutingPreferencesDTO() != null;
|
||||
HashMap<String, Direction> directionMap = getPossibleDirectionsFromCarta(requestDTO);
|
||||
|
||||
// if consider weather
|
||||
// get weather for origin
|
||||
// if bad, remove walking and biking options
|
||||
|
||||
// filter applicable routes (car is only baseline, never suggested)
|
||||
ArrayList<RouteDTO> suggestedAlternatives = new ArrayList<>();
|
||||
int maxAdditionalTimeNonPhysical = routingProperties.getToleratedAdditionalTravelSeconds();
|
||||
int maxAdditionalTimePhysical = requestDTO.getRoutingPreferencesDTO().isPreferPhysicalActivity() ?
|
||||
routingProperties.getToleratedAdditionalPhysicalActivitiesSeconds() :
|
||||
routingProperties.getToleratedAdditionalTravelSeconds();
|
||||
|
||||
Route carRoute;
|
||||
try {
|
||||
carRoute = directionMap.get("car").getRoutes().getFirst();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoCarRouteFoundException("No car route to compare to was found.");
|
||||
}
|
||||
|
||||
if (directionMap.containsKey("walk")) {
|
||||
Direction walkDirection = directionMap.get("walk");
|
||||
if (walkDirection.getRoutes() != null && !walkDirection.getRoutes().isEmpty()) {
|
||||
Route walkRoute = walkDirection.getRoutes().getFirst();
|
||||
int durationDifferenceCar = walkRoute.getDuration() - carRoute.getDuration();
|
||||
if (durationDifferenceCar < maxAdditionalTimePhysical) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// certain threshold how much more delay is okay
|
||||
// apply physical preference if set
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RouteDTO {
|
||||
+16.3f
|
||||
);
|
||||
dto.steps.add(new StepDTO(
|
||||
Modality.WALK,
|
||||
Modality.WALKING,
|
||||
null,
|
||||
400f
|
||||
));
|
||||
@@ -79,7 +79,7 @@ public class RouteDTO {
|
||||
5000f
|
||||
));
|
||||
dto.steps.add(new StepDTO(
|
||||
Modality.WALK,
|
||||
Modality.WALKING,
|
||||
null,
|
||||
300f
|
||||
));
|
||||
|
||||
@@ -13,13 +13,13 @@ import java.time.LocalDateTime;
|
||||
@Schema(description = "This DTO represents a request for alternative routes between an origin and a destination.")
|
||||
public class RoutingAlternativeRequestDTO {
|
||||
@NotNull
|
||||
private String originLat;
|
||||
private Double originLat;
|
||||
@NotNull
|
||||
private String originLon;
|
||||
private Double originLon;
|
||||
@NotNull
|
||||
private String destinationLat;
|
||||
private Double destinationLat;
|
||||
@NotNull
|
||||
private String destinationLon;
|
||||
private Double destinationLon;
|
||||
@NotNull
|
||||
private LocalDateTime arrivalTime;
|
||||
@NotNull
|
||||
|
||||
@@ -15,6 +15,6 @@ public class RoutingPreferencesDTO {
|
||||
private boolean preferPhysicalActivity = false;
|
||||
private boolean considerWeatherConditions = true;
|
||||
private List<Modality> modalitiesToConsider = new ArrayList<>(
|
||||
List.of(Modality.WALK, Modality.BIKE, Modality.ESCOOTER, Modality.BUS, Modality.TRAM, Modality.TRAIN)
|
||||
List.of(Modality.WALKING, Modality.BICYCLE, Modality.ESCOOTER, Modality.BUS, Modality.TRAM, Modality.TRAIN)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package SuMoC.backend.routing.exceptions;
|
||||
|
||||
public class NoCarRouteFoundException extends RuntimeException {
|
||||
public NoCarRouteFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@ package SuMoC.backend.trip;
|
||||
|
||||
public enum Modality {
|
||||
IDLE,
|
||||
WALK,
|
||||
BIKE,
|
||||
WALKING,
|
||||
BICYCLE,
|
||||
ESCOOTER,
|
||||
BUS,
|
||||
TRAM,
|
||||
TRAIN,
|
||||
CAR
|
||||
CAR,
|
||||
MOTORCYCLE,
|
||||
TAXI
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user