rename service

This commit is contained in:
2026-01-07 13:45:12 +01:00
parent c010f34479
commit ec0615f6df
3 changed files with 13 additions and 15 deletions
@@ -1,9 +1,8 @@
package SuMoC.backend.dev;
import SuMoC.backend.scheduling.ScheduledTasks;
import SuMoC.backend.trenddetection.services.UpdateStatsTablesService;
import SuMoC.backend.trenddetection.services.StatTableUpdateService;
import lombok.RequiredArgsConstructor;
import org.springframework.cglib.core.Local;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,15 +18,15 @@ public class DevController {
private final ScheduledTasks scheduledTasks;
private final UpdateStatsTablesService updateStatsTablesService;
private final StatTableUpdateService statTableUpdateService;
@PostMapping("/trigger-trend-calculation")
public void triggerTrendCalculation() {
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
LocalDate day2WeeksAgo = LocalDate.now().minusDays(14);
LocalDate day3WeeksAgo = LocalDate.now().minusDays(21);
updateStatsTablesService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
updateStatsTablesService.updateWeeklyMobilityStatsForAllUsers(day2WeeksAgo);
updateStatsTablesService.updateWeeklyMobilityStatsForAllUsers(day3WeeksAgo);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(day2WeeksAgo);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(day3WeeksAgo);
}
}
@@ -1,6 +1,6 @@
package SuMoC.backend.scheduling;
import SuMoC.backend.trenddetection.services.UpdateStatsTablesService;
import SuMoC.backend.trenddetection.services.StatTableUpdateService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -17,14 +17,14 @@ public class ScheduledTasks {
private final SchedulingProperties properties;
private final UpdateStatsTablesService updateStatsTablesService;
private final StatTableUpdateService statTableUpdateService;
@Scheduled(cron = "#{@schedulingProperties.calculateWeeklyMobilityStats}")
public void scheduleCalculateWeeklyMobilityStats() {
logger.info("Scheduled task triggered: calculateWeeklyMobilityStatsForAllUsers");
try{
try {
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
updateStatsTablesService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
} catch (Exception e) {
logger.error("Error calculating weekly mobility stats.", e);
}
@@ -1,14 +1,13 @@
package SuMoC.backend.trenddetection.services;
import SuMoC.backend.trenddetection.statcalculation.WeeklyMobilityStatsCalculator;
import SuMoC.backend.trenddetection.WeeklyMobilityStatsRepository;
import SuMoC.backend.trenddetection.statcalculation.WeeklyMobilityStatsCalculator;
import SuMoC.backend.trip.TripRepository;
import SuMoC.backend.trip.models.Trip;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.DayOfWeek;
@@ -21,9 +20,9 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Transactional
public class UpdateStatsTablesService {
public class StatTableUpdateService {
private static final Logger logger = LoggerFactory.getLogger(UpdateStatsTablesService.class);
private static final Logger logger = LoggerFactory.getLogger(StatTableUpdateService.class);
private final TripRepository tripRepository;
@@ -33,7 +32,7 @@ public class UpdateStatsTablesService {
/**
* Calculates weekly mobility stats for the week of a given LocalDate.
*/
public void updateWeeklyMobilityStatsForAllUsers(LocalDate week) {
public void updateWeeklyMobilityStatsForAllUsers(LocalDate week) {
logger.info("Starting calculation of weekly mobility stats for all users.");
// Get all trips of the last full week
LocalDate weekStart = week.with(DayOfWeek.MONDAY);