Skip to content

Commit

Permalink
feat: TrafficIntegrationPredictService 구현
Browse files Browse the repository at this point in the history
<description>
사이클 예측 및 현재 신호등 색상, 잔여시간 계산을 모두 수행하는 서비스
  • Loading branch information
nove1080 committed May 22, 2024
1 parent 1ff9869 commit d501617
Showing 1 changed file with 46 additions and 0 deletions.
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();
}
}

0 comments on commit d501617

Please sign in to comment.