추론 실행 수정 및 추석 추가 작업중

This commit is contained in:
2026-02-26 11:52:56 +09:00
parent cefacb291b
commit a44e93c234
6 changed files with 139 additions and 55 deletions

View File

@@ -246,15 +246,15 @@ public class InferenceResultDto {
@NotBlank
private String title;
@Schema(description = "G1", example = "b40e0f68-c1d8-49fc-93f9-a36270093861")
@Schema(description = "G1", example = "643adead-f3d2-4f10-9037-862bee919399")
@NotNull
private UUID model1Uuid;
@Schema(description = "G2", example = "ec92b7d2-b5a3-4915-9bdf-35fb3ca8ad27")
@Schema(description = "G2", example = "dd86b4ef-28e3-4e3d-9ee4-f60d9cb54e13")
@NotNull
private UUID model2Uuid;
@Schema(description = "G3", example = "37f45782-8ccf-4cf6-911c-a055a1510d39")
@Schema(description = "G3", example = "58c1153e-dec6-4424-82a1-189083a9d9dc")
@NotNull
private UUID model3Uuid;

View File

@@ -47,14 +47,12 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@@ -67,6 +65,7 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/** 추론 관리 */
@Service
@Log4j2
@RequiredArgsConstructor
@@ -199,7 +198,7 @@ public class InferenceResultService {
// target 목록 조회
List<MngListDto> targetDtoList = mapSheetMngCoreService.getHstMapSheetList(req);
// target 도엽번호 리스트 추출
// target 도엽번호 리스트 추출 중복 제거
List<String> targetList =
targetDtoList.stream()
.map(MngListDto::getMapSheetNum)
@@ -207,9 +206,6 @@ public class InferenceResultService {
.distinct()
.toList();
// target 포함 여부 판단
Set<String> targetSet = new HashSet<>(targetList);
// compare 목록 조회
List<MapSheetFallbackYearDto> compareDtoList =
new ArrayList<>(mapSheetMngCoreService.getMapSheetNumDtoByHst(req.getCompareYyyy()));
@@ -221,34 +217,21 @@ public class InferenceResultService {
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// arget에는 있으나 compare에는 없는 도엽 추출
// target에는 있으나 compare에는 없는 도엽 추출
List<String> remainingTargetList =
targetList.stream().filter(s -> !compareSet.contains(s)).toList();
// fallback년도 도엽 조회
// compare에 없을때 이전 년도 사용 가능여부 조회
List<MapSheetFallbackYearDto> fallbackYearDtoList =
mapSheetMngCoreService.findFallbackCompareYearByMapSheets(
req.getTargetYyyy(), // 대상년도 기준
remainingTargetList // compare에 없는 도엽들
);
// 기존 compare , fallback 합치기
// 기존 compare , 사용가능 이전년도 정보 합치기
compareDtoList.addAll(fallbackYearDtoList);
// mapSheetNum 기준 중복 제거 (기존 compare 우선 유지)
compareDtoList =
new ArrayList<>(
compareDtoList.stream()
.filter(d -> d.getMapSheetNum() != null)
.collect(
Collectors.toMap(
MapSheetFallbackYearDto::getMapSheetNum,
Function.identity(),
(existing, replacement) -> existing, // 기존 우선
LinkedHashMap::new))
.values());
// 최종 compare 도엽 Set 구성
// 중복제거하여 사용할 compare 도엽 목록
Set<String> availableCompareSheets =
compareDtoList.stream()
.map(MapSheetFallbackYearDto::getMapSheetNum)
@@ -256,35 +239,11 @@ public class InferenceResultService {
.collect(Collectors.toSet());
// 최종 추론 대상 도엽
// target compare(fallback)에 존재하는 도엽만 추출
// target 기준으로 compare 에 존재하는 도엽만 추출
List<String> filteredTargetList =
targetList.stream().filter(availableCompareSheets::contains).toList();
// compare only 계산 (target에는 없는 compare 도엽 수)
long compareOnlyCount =
compareDtoList.stream()
.map(MapSheetFallbackYearDto::getMapSheetNum)
.filter(s -> s != null && !targetSet.contains(s))
.count();
// 연도별 도엽 비교 로그 출력
log.info(
"""
===== MapSheet Year Comparison =====
target Total: {}
compare Total: {}
Intersection: {}
target Only (Excluded): {}
compare Only: {}
====================================
""",
targetList.size(), // target count
compareDtoList.size(), // compare count
filteredTargetList.size(), // target 기준으로 compare 비교하여 최종 추론할 도엽 count
targetList.size() - filteredTargetList.size(), // compare에 존재하지 않는 target 도엽 수
compareOnlyCount); // target 에 존재하지 않는 compare 도엽수
// compareDtoList도 최종 교집합 기준으로 필터
// compareDtoList도 최종 기준으로 필터
Set<String> filteredTargetSet = new HashSet<>(filteredTargetList);
List<MapSheetFallbackYearDto> filteredCompareDtoList =
@@ -293,6 +252,30 @@ public class InferenceResultService {
.filter(d -> filteredTargetSet.contains(d.getMapSheetNum()))
.toList();
// compare only 계산 (target에는 없는 compare 도엽 수) log 용
long compareOnlyCount =
compareDtoList.stream()
.map(MapSheetFallbackYearDto::getMapSheetNum)
.filter(s -> s != null && !targetList.contains(s))
.count();
// 연도별 도엽 비교 로그 출력
log.info(
"""
===== MapSheet Year Comparison =====
target Total: {}
compare Total: {}
Intersection: {}
target Only (Excluded): {}
compare Only: {}
====================================
""",
targetList.size(), // target count
compareDtoList.size(), // compare count
filteredTargetList.size(), // target 기준으로 compare 비교하여 최종 추론할 도엽 count
targetList.size() - filteredTargetList.size(), // compare에 존재하지 않는 target 도엽 수
compareOnlyCount); // target 에 존재하지 않는 compare 도엽수
// compare 기준 geojson 생성 (년도 fallback 반영)
Scene compareScene =
getSceneInference(
@@ -604,7 +587,7 @@ public class InferenceResultService {
}
/**
* 추론 AI API 호출
* 추론 AI API 호출 batch id를 리턴
*
* @param dto
*/
@@ -636,6 +619,7 @@ public class InferenceResultService {
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
// 추론 실행 API 호출
ExternalCallResult<String> result =
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
@@ -650,12 +634,14 @@ public class InferenceResultService {
objectMapper.readValue(result.body(), new TypeReference<>() {});
if (list.isEmpty()) {
throw new IllegalStateException("Inference response is empty");
throw new CustomApiException(
"NOT_FOUND", HttpStatus.NOT_FOUND, "Inference response is empty");
}
Object batchIdObj = list.get(0).get("batch_id");
if (batchIdObj == null) {
throw new IllegalStateException("batch_id not found in response");
throw new CustomApiException(
"NOT_FOUND", HttpStatus.NOT_FOUND, "batch_id not found in response");
}
return Long.valueOf(batchIdObj.toString());
@@ -674,6 +660,7 @@ public class InferenceResultService {
*/
private InferenceSendDto getModelInfo(UUID uuid) {
// 모델정보 조회
Basic modelInfo = modelMngCoreService.findByModelUuid(uuid);
String cdModelPath = "";