add testing endpoint for regular trip detection (very slow yet)
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-30 16:11:55 +01:00
parent e41fff0840
commit 39e385cac3
4 changed files with 48 additions and 5 deletions
@@ -251,4 +251,9 @@ public class DevController {
}
}
@PostMapping("/test-detection-and-notification-regular-trips")
public void testDetectionAndNotificationOfRegularTrips() {
regularTripSuggestionService.detectAndNotifyRegularTripsForTodaysDayOfWeek();
}
}
@@ -7,6 +7,7 @@ import SuMoC.backend.trip.Modality;
import SuMoC.backend.trip.TripMapper;
import SuMoC.backend.trip.TripRepository;
import SuMoC.backend.trip.dtos.RegularTripDetectionDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.DayOfWeek;
@@ -16,15 +17,16 @@ import java.util.HashMap;
import java.util.List;
@Service
@RequiredArgsConstructor
public class RegularTripDetectionService {
RegularTripDetectionProperties properties;
private final RegularTripDetectionProperties properties;
TripRepository tripRepository;
private final TripRepository tripRepository;
TripMapper tripMapper;
private final TripMapper tripMapper;
Detector tripDetector;
private final Detector tripDetector;
/**
* Detects regular trips for the current day of the week for all users based on saved trip data and RegularTripDetectionProperties.
@@ -28,9 +28,18 @@ public class DevTripSeeder implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// Iterate over all users and create 5 random trips for each of the last 5 weeks
// Iterate over all users and create 5 random trips for each of the last 5 weeks + adds car trips for every day at same time
userRepository.findAll().forEach(user -> {
for (int week = 0; week < 5; week++) {
for (int day = 0; day < 7; day++) {
NewTripDTO carTrip = TripFactory.newCarTripDTO(
java.time.Instant.now()
.minus(java.time.Duration.ofDays(week * 7 + day))
);
tripService.addTrip(user, carTrip);
}
// Create 5 trips per week
for (int i = 0; i < 5; i++) {
// Create trips within each week's time range
long daysAgo = week * 7 + (long) (Math.random() * 7);
@@ -23,6 +23,33 @@ public class TripFactory {
return modalities[ThreadLocalRandom.current().nextInt(modalities.length)];
}
public static NewTripDTO newCarTripDTO(Instant startTime) {
String startPlace = "Cologne";
String endPlace = "Düsseldorf";
Set<NewTripSegmentDTO> segments = Set.of(
NewTripSegmentDTO.builder()
.modality(Modality.CAR)
.startTime(startTime)
.distanceMeters(50000)
.build()
);
return NewTripDTO.builder()
.startPlace(startPlace)
.endPlace(endPlace)
.startLatitude(51.4617108)
.startLongitude(7.0170745)
.endLatitude(51.2277411)
.endLongitude(6.7734556)
.co2Emissions(120.0)
.startTime(startTime)
.endTime(startTime.plus(Duration.ofMinutes(45)))
.mobilityScore(75.0f)
.tripSegments(segments)
.build();
}
/**
* Generates a random NewTripDTO that always consists of two random segments that start at the given startTime,
* take 2 hours in total, and have random start and end places from a predefined list of NRW cities.