remove unnecessary geocoding for regular trip centers -> we already have address of alternative route -> saves on geocoding calls

This commit is contained in:
2026-02-10 13:39:30 +01:00
parent 18e8d10f6b
commit 1b549cc5fc
2 changed files with 2 additions and 33 deletions
@@ -8,16 +8,12 @@ import SuMoC.backend.carrousel.dto.RouteAlternativeContext;
import SuMoC.backend.carrousel.enums.CarrouselCandidateType;
import SuMoC.backend.carrousel.models.CarrouselCandidate;
import SuMoC.backend.carrousel.repository.CarrouselCandidateRepository;
import SuMoC.backend.geocoding.AddressDTO;
import SuMoC.backend.geocoding.GeoCodingService;
import SuMoC.backend.h3.H3Service;
import SuMoC.backend.regulartrip.dtos.DetectedRegularTripDTO;
import SuMoC.backend.regulartrip.dtos.MinimalDetectedRegularTripDTO;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.trip.models.Trip;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.time.Instant;
@@ -32,10 +28,6 @@ public class CarrouselService {
private final CarrouselProperties carrouselProperties;
private final H3Service h3Service;
private final GeoCodingService geoCodingService;
public void addAdHocTripCandidates(Trip trip, List<RouteDTO> suggestedAlternatives) {
for (var alternative : suggestedAlternatives) {
CarrouselCandidate candidate = CarrouselCandidate.builder()
@@ -107,24 +99,9 @@ public class CarrouselService {
private RouteAlternativeContext fromRegularTripCandidate(CarrouselCandidate candidate) {
var minRegularTrip = candidate.getDetectedRegularTrip();
var startLatLong = h3Service.cellToLatLng(minRegularTrip.getStartH3Center());
var endLatLong = h3Service.cellToLatLng(minRegularTrip.getEndH3Center());
// TODO we might want to remove the center addresses, we already have the start and end place names from the original trip - could save compute time and API calls here
// Fetch origin and destination addresses concurrently
var addressesMono = Mono.zip(
geoCodingService.getAddress(startLatLong.lat, startLatLong.lng),
geoCodingService.getAddress(endLatLong.lat, endLatLong.lng)
);
var addressesTuple = addressesMono.block();
AddressDTO startCenterAddress = addressesTuple.getT1();
AddressDTO endCenterAddress = addressesTuple.getT2();
return new RegularTripAlternativeContext(
candidate.getSuggestedAlternative(),
minRegularTrip,
startCenterAddress,
endCenterAddress
minRegularTrip
);
}
}