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
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user