remove unnecessary geocoding for regular trip centers -> we already have address of alternative route -> saves on geocoding calls
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user