package SuMoC.backend.routing.dtos; import SuMoC.backend.geocoding.AddressDTO; import SuMoC.backend.trip.Modality; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.annotation.Nullable; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; @Getter @Setter @NoArgsConstructor @Schema(description = "This DTO represents a suggested route as a response to a requested alternative route.") public class RouteDTO { @Schema(description = "The actual address of the start location.") private AddressDTO startAddress; @Schema(description = "The name of the first stop if the route uses public transport. E.g. \"Essen West\" if the route starts with a footpath to the first train leaving there.") @Nullable private String firstStopName; @Schema(description = "The latitude of the start address.") private double startLat; @Schema(description = "The longitude of the start address.") private double startLon; @Schema(description = "The actual address of the end location.") private AddressDTO endAddress; @Schema(description = "The name of the last stop if the route uses public transport. E.g. \"Essen Hbf\" if the route ends with a train arriving there (might still contain a footpath afterwards).") @Nullable private String lastStopName; @Schema(description = "The latitude of the end address.") private double endLat; @Schema(description = "The longitude of the end address.") private double endLon; @Schema(description = "The start date and time of the route.") private Instant startDateTime; @Schema(description = "The end date and time of the route.") private Instant endDateTime; @Schema(description = "The steps the route consists of.") private List steps; @Schema(description = "Amount of CO2e savings in gramm compared to a car trip for the same route.") private double co2Savings; @Schema(description = "CO2e emission of this route.") private double co2Emissions; @Schema(description = "The temporal difference in minutes compared to the original route the user requested alternatives for.") private double timeDifferenceSeconds; public RouteDTO(AddressDTO startAddress, @Nullable String firstStopName, double startLat, double startLon, AddressDTO endAddress, @Nullable String lastStopName, double endLat, double endLon, Instant startDateTime, Instant endDateTime, List steps, double co2Savings, double timeDifferenceSeconds, double co2Emissions) { this.startAddress = startAddress; this.firstStopName = firstStopName; this.startLat = startLat; this.startLon = startLon; this.endAddress = endAddress; this.lastStopName = lastStopName; this.endLat = endLat; this.endLon = endLon; this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.steps = steps; this.co2Savings = co2Savings; this.co2Emissions = co2Emissions; this.timeDifferenceSeconds = timeDifferenceSeconds; } /** * Mock method for testing purposes * * @return RouteDto with mock data */ public static RouteDTO getMockRouteDTO() { var startAddress = new AddressDTO( "28a", "Janssenstraße", "Holsterhausen", "Stadtbezirk III", "Essen", "Nordrhein-Westfalen", "DE-NW", "45147", "Deutschland", "de" ); var endAddress = new AddressDTO( "70", "Schützenbahn", null, null, "Essen", "Nordrhein-Westfalen", "DE-NW", "45127", "Deutschland", "de" ); var dto = new RouteDTO( startAddress, "Rubensstraße", 51.440395, 6.984785, endAddress, "Viehhofer Platz", 51.459167, 7.014928, Instant.now().minus(Duration.ofMinutes(30)), Instant.now(), new ArrayList(), 120.5f, +16.3f, 20 ); dto.steps.add(new StepDTO( Modality.WALKING, null, 400f )); dto.steps.add(new StepDTO( Modality.TRAM, "106", 5000f )); dto.steps.add(new StepDTO( Modality.WALKING, null, 300f )); return dto; } public long getDurationSeconds() { return endDateTime.getEpochSecond() - startDateTime.getEpochSecond(); } /** * We consider routes that only consist of walking and cycling steps as physical activity. */ public boolean isPhysicalActivity() { return steps.stream().allMatch(step -> step.getModality() == Modality.WALKING || step.getModality() == Modality.BICYCLE); } public boolean isCyclingRoute() { return steps.stream().allMatch(step -> step.getModality() == Modality.BICYCLE); } public boolean isWalkingRoute() { return steps.stream().allMatch(step -> step.getModality() == Modality.WALKING); } }