implement full service chain where scheduled task detects regular trips every day and schedules notifications with better alternatives if available
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-16 13:19:19 +01:00
parent b08d9dd22d
commit d099909aab
13 changed files with 299 additions and 24 deletions
@@ -9,6 +9,7 @@ import SuMoC.backend.trip.TripRepository;
import SuMoC.backend.trip.dtos.RegularTripDetectionDTO;
import org.springframework.stereotype.Service;
import java.time.DayOfWeek;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,14 +27,13 @@ public class RegularTripDetectionService {
Detector tripDetector;
/**
* Detects regular trips for all users based on saved trip data and RegularTripDetectionProperties.
* Detects regular trips for the current day of the week for all users based on saved trip data and RegularTripDetectionProperties.
* This is the main method that orchestrates the detection process and should be used to detect trips
* we want to suggest alternatives for.
*/
public HashMap<Long, List<DetectedRegularTripDTO>> detectRegularCarTrips() {
var tripsByUser = getTripsByUser(Modality.CAR);
public HashMap<Long, List<DetectedRegularTripDTO>> detectRegularCarTripsByUserForDayOfWeek(DayOfWeek dayOfWeek) {
var tripsByUser = getTripsByUser(Modality.CAR, dayOfWeek);
// TODO this could be parallelized in the future
HashMap<Long, List<DetectedRegularTripDTO>> results = new HashMap<>();
for (Long userId : tripsByUser.keySet()) {
results.put(userId, tripDetector.detectRegularTrips(tripsByUser.get(userId)));
@@ -42,9 +42,9 @@ public class RegularTripDetectionService {
return results;
}
private HashMap<Long, List<RegularTripDetectionDTO>> getTripsByUser(Modality modality) {
private HashMap<Long, List<RegularTripDetectionDTO>> getTripsByUser(Modality modality, DayOfWeek dayOfWeek) {
Instant fromDate = Instant.now().minusSeconds(properties.getDetectionTimeWindowDays() * 24 * 60 * 60);
List<RegularTripDetectionDTO> dtoList = tripMapper.toRegularTripDetectionDTOS(tripRepository.findAllValidFromDateWithMainModality(fromDate, modality));
List<RegularTripDetectionDTO> dtoList = tripMapper.toRegularTripDetectionDTOS(tripRepository.findAllValidFromDateWithMainModalityOnCertainWeekday(fromDate, modality, dayOfWeek));
HashMap<Long, List<RegularTripDetectionDTO>> tripsByUser = new HashMap<>();
for (RegularTripDetectionDTO dto : dtoList) {