add weekly schedulded task that calculates weekly mobility statistics for each user that made a trip in that week -> basis for deteting trend changes in mobility behaviour
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-06 17:55:04 +01:00
parent 17636f0b65
commit c010f34479
14 changed files with 374 additions and 7 deletions
@@ -0,0 +1,32 @@
package SuMoC.backend.scheduling;
import SuMoC.backend.trenddetection.services.UpdateStatsTablesService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
@Component
@RequiredArgsConstructor
public class ScheduledTasks {
private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
private final SchedulingProperties properties;
private final UpdateStatsTablesService updateStatsTablesService;
@Scheduled(cron = "#{@schedulingProperties.calculateWeeklyMobilityStats}")
public void scheduleCalculateWeeklyMobilityStats() {
logger.info("Scheduled task triggered: calculateWeeklyMobilityStatsForAllUsers");
try{
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
updateStatsTablesService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
} catch (Exception e) {
logger.error("Error calculating weekly mobility stats.", e);
}
}
}