-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: TrafficIntegrationPredictService 구현
<description> 사이클 예측 및 현재 신호등 색상, 잔여시간 계산을 모두 수행하는 서비스
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
api/src/main/java/com/walking/api/service/TrafficIntegrationPredictService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.walking.api.service; | ||
|
||
import com.walking.api.service.dto.PredictedData; | ||
import com.walking.api.service.dto.request.CurrentDetailRequestDto; | ||
import com.walking.api.service.dto.request.CyclePredictionRequestDto; | ||
import com.walking.api.service.dto.request.IntegrationPredictRequestDto; | ||
import com.walking.api.service.dto.response.CurrentDetailResponseDto; | ||
import com.walking.api.service.dto.response.IntegrationPredictResponseDto; | ||
import com.walking.data.entity.traffic.TrafficEntity; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** 신호등의 현재 잔여 시간, 현재 색상, 각 색상별 사이클을 예측한 결과를 리턴합니다. */ | ||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TrafficIntegrationPredictService { | ||
|
||
private final TrafficCyclePredictServiceImpl trafficCyclePredictService; | ||
private final TrafficCurrentDetailPredictService trafficCurrentDetailPredictService; | ||
|
||
@Value("${walking.predict.dataInterval}") | ||
private int dataInterval; | ||
|
||
public IntegrationPredictResponseDto execute(IntegrationPredictRequestDto requestDto) { | ||
List<Long> trafficIds = requestDto.getTrafficIds(); | ||
CyclePredictionRequestDto cyclePredictionRequestDto = | ||
new CyclePredictionRequestDto(trafficIds, dataInterval); | ||
Map<TrafficEntity, PredictedData> predictDataMap = | ||
trafficCyclePredictService.execute(cyclePredictionRequestDto); | ||
|
||
CurrentDetailRequestDto currentDetailRequestDto = | ||
CurrentDetailRequestDto.builder().predictedCycleMap(predictDataMap).build(); | ||
CurrentDetailResponseDto responseDto = | ||
trafficCurrentDetailPredictService.execute(currentDetailRequestDto); | ||
|
||
// 사이클 예측값과 현재시간에 대한 예측값을 모아서 리턴하도록 | ||
return IntegrationPredictResponseDto.builder() | ||
.predictedDataMap(responseDto.getCurrentDetails()) | ||
.build(); | ||
} | ||
} |