32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
package SuMoC.backend.trend.services;
|
|
|
|
import SuMoC.backend.notification.enums.NotificationType;
|
|
import SuMoC.backend.notification.services.NotificationSchedulerService;
|
|
import SuMoC.backend.trend.config.TrendProperties;
|
|
import SuMoC.backend.trend.enums.StatAttribute;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class TrendNotificationService {
|
|
|
|
private final TrendDetectorService trendDetectorService;
|
|
|
|
private final NotificationSchedulerService notificationSchedulerService;
|
|
|
|
private final TrendProperties trendProperties;
|
|
|
|
/**
|
|
* Detects trends for the given year and week number and sends notifications to users.
|
|
*/
|
|
public void detectAndNotifyTrends(int year, int weekNumber) {
|
|
// TODO for now we only consider CAR_DISTANCE, but this can be extended later
|
|
var detectedTrends = trendDetectorService.detectWeeklyTrends(year, weekNumber, StatAttribute.CAR_DISTANCE);
|
|
// we create a new list so the java type system is happy
|
|
notificationSchedulerService.scheduleAll(new ArrayList<>(detectedTrends), NotificationType.TREND, trendProperties.getEarliestTrendNotificationTimeOfDay());
|
|
}
|
|
}
|