Files
sumoc-backend/src/main/java/SuMoC/backend/regulartrip/dtos/DetectedRegularTripDTO.java
T

85 lines
3.4 KiB
Java

package SuMoC.backend.regulartrip.dtos;
import SuMoC.backend.h3.H3Service;
import SuMoC.backend.trip.Modality;
import SuMoC.backend.trip.dtos.RegularTripDetectionDTO;
import lombok.*;
import java.time.*;
import java.util.List;
/**
* A DTO representing the details of a detected regular trip.
*/
@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class DetectedRegularTripDTO {
private long userId;
private Modality modality;
private DayOfWeek dayOfWeek;
private LocalTime departureWindowStart;
private LocalTime departureWindowEnd;
private LocalTime arrivalWindowStart;
private LocalTime arrivalWindowEnd;
private String startH3Center;
private String endH3Center;
private List<String> startH3neighbours;
private List<String> endH3Neighbours;
private List<RegularTripDetectionDTO> supportingTrips;
/**
* Mock dto that should trigger available alternative.
*/
public static DetectedRegularTripDTO getTriggeringMock(H3Service h3Service, Long userId) {
String h3_schutzenbahn = "8a1fa535568ffff"; // Essen Schuetzenbahn
String h3_essen_hbf = "8a1fa535020ffff"; // Essen Hbf
return DetectedRegularTripDTO.builder()
.userId(userId)
.modality(Modality.CAR)
.dayOfWeek(LocalDateTime.now().getDayOfWeek())
.departureWindowStart(LocalTime.now().plusMinutes(20))
.departureWindowEnd(LocalTime.now().plusMinutes(30))
.arrivalWindowStart(LocalTime.now().plusMinutes(60))
.arrivalWindowEnd(LocalTime.now().plusMinutes(70))
.startH3Center(h3_schutzenbahn) // Essen Schuetzenbahn
.endH3Center(h3_essen_hbf) // Essen Hbf
.startH3neighbours(h3Service.getRoutePatternNeighbors(h3_schutzenbahn))
.endH3Neighbours(h3Service.getRoutePatternNeighbors(h3_essen_hbf))
.supportingTrips(List.of(
RegularTripDetectionDTO.builder()
.tripId(userId)
.userId(userId)
.startH3Cell(h3_schutzenbahn)
.endH3Cell(h3_essen_hbf)
.startTime(LocalTime.now().plusMinutes(20).atDate(LocalDateTime.now().toLocalDate()).toInstant(ZoneOffset.UTC))
.endTime(LocalTime.now().plusMinutes(60).atDate(LocalDateTime.now().toLocalDate()).toInstant(ZoneOffset.UTC))
.mainModality(Modality.CAR)
.startH3CellKRingNeighboors(h3Service.getRoutePatternNeighbors(h3_schutzenbahn))
.endH3CellKRingNeighboors(h3Service.getRoutePatternNeighbors(h3_essen_hbf))
.build()
))
.build();
}
public Instant getAverageArrivalTime() {
long totalSeconds = 0;
for (RegularTripDetectionDTO trip : supportingTrips) {
totalSeconds += trip.getEndTime().getEpochSecond();
}
long averageSeconds = totalSeconds / supportingTrips.size();
return Instant.ofEpochSecond(averageSeconds);
}
public int getAverageDurationMinutes() {
int totalDuration = 0;
for (RegularTripDetectionDTO trip : supportingTrips) {
totalDuration += trip.getDurationMinutes();
}
return totalDuration / supportingTrips.size();
}
}