추론실행 수정, develop pull 반영, 국유인 파일경로 dir 하드코딩 수정 #103

Merged
teddy merged 14 commits from feat/infer_dev_260211 into develop 2026-02-26 12:21:06 +09:00
2 changed files with 96 additions and 109 deletions
Showing only changes of commit 9197819340 - Show all commits

View File

@@ -24,11 +24,11 @@ public class InferenceSendDto {
private Double priority; private Double priority;
public String getCd_model_path() { public String getCd_model_path() {
return cd_model_path==null?null:cd_model_path.replace("kamcd-nfs", "data"); return cd_model_path == null ? null : cd_model_path.replace("kamcd-nfs", "data");
} }
public String getCls_model_path() { public String getCls_model_path() {
return cls_model_path==null?null:cls_model_path.replace("kamcd-nfs", "data"); return cls_model_path == null ? null : cls_model_path.replace("kamcd-nfs", "data");
} }
@Getter @Getter
@@ -45,11 +45,11 @@ public class InferenceSendDto {
public String getInput1_scene_path() { public String getInput1_scene_path() {
return input1_scene_path==null?null:input1_scene_path.replace("kamcd-nfs", "data"); return input1_scene_path == null ? null : input1_scene_path.replace("kamcd-nfs", "data");
} }
public String getInput2_scene_path() { public String getInput2_scene_path() {
return input2_scene_path==null?null:input2_scene_path.replace("kamcd-nfs", "data"); return input2_scene_path == null ? null : input2_scene_path.replace("kamcd-nfs", "data");
} }
} }
} }

View File

@@ -27,7 +27,6 @@ import java.nio.file.Paths;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -236,84 +235,22 @@ public class MapSheetMngCoreService {
} }
/** /**
* 추론 실행에 필요한 geojson 파일 생성 * geojson 생성
* *
* @param yyyy 영상관리 파일별 년도 * @param yyyy
* @param scenes 5k 도엽 번호 리스트 * @param scenes
* @param mapSheetScope EXCL : 추론제외, PREV 이전 년도 도엽 사용 * @param mapSheetScope
* @param detectOption
* @return * @return
*/ */
public Scene getSceneInference( public Scene getSceneInference(
String yyyy, List<String> scenes, String mapSheetScope, String detectOption) { String yyyy, List<String> scenes, String mapSheetScope, String detectOption) {
List<ImageFeature> features = loadSceneInferenceBySheets(yyyy, scenes);
Map<String, Object> result = new HashMap<>(); return writeSceneGeoJson(yyyy, mapSheetScope, detectOption, features);
boolean isAll = MapSheetScope.ALL.getId().equals(mapSheetScope);
String optionSuffix = "";
if (DetectOption.EXCL.getId().equals(detectOption)) {
optionSuffix = "_EXCL";
} else if (DetectOption.PREV.getId().equals(detectOption)) {
optionSuffix = "_PREV";
}
// 1) 경로/파일명 결정
String targetDir =
"local".equals(activeEnv) ? System.getProperty("user.home") + "/geojson" : inferenceDir;
String filename =
isAll
? String.format("%s_%s_ALL%s.geojson", yyyy, activeEnv, optionSuffix)
: String.format("%s_%s%s.geojson", yyyy, activeEnv, optionSuffix);
Path outputPath = Paths.get(targetDir, filename);
// 2) ALL일 때만 재사용
// if (isAll && Files.exists(outputPath)) {
// return outputPath.toString();
// }
// 3) 데이터 조회
List<ImageFeature> sceneInference = mapSheetMngRepository.getSceneInference(yyyy, scenes);
if (sceneInference == null || sceneInference.isEmpty()) {
log.warn(
"NOT_FOUND_TARGET_YEAR: yyyy={}, isAll={}, scenesSize={}",
yyyy,
isAll,
scenes == null ? 0 : scenes.size());
throw new CustomApiException("NOT_FOUND_TARGET_YEAR", HttpStatus.NOT_FOUND);
}
// 4) 파일 생성
try {
log.info("create Directories outputPath: {}", outputPath);
log.info(
"activeEnv={}, inferenceDir={}, targetDir={}, filename={}",
activeEnv,
inferenceDir,
targetDir,
filename);
log.info("outputPath={}, parent={}", outputPath.toAbsolutePath(), outputPath.getParent());
Files.createDirectories(outputPath.getParent());
new GeoJsonFileWriter()
.exportToFile(sceneInference, "scene_inference_" + yyyy, 5186, outputPath.toString());
log.info("GeoJsonFileWriter: {}", "scene_inference_" + yyyy);
Scene scene = new Scene();
scene.setFeatures(sceneInference);
scene.setFilePath(outputPath.toString());
return scene;
} catch (IOException e) {
log.error(
"FAIL_CREATE_MAP_SHEET_FILE: yyyy={}, isAll={}, path={}", yyyy, isAll, outputPath, e);
throw new CustomApiException("INTERNAL_SERVER_ERROR", HttpStatus.INTERNAL_SERVER_ERROR, e);
}
} }
/** /**
* 년도별로 추론 실행에 필요한 geojson 파일 생성 * geojson 생성
* *
* @param yearDtos * @param yearDtos
* @param yyyy * @param yyyy
@@ -326,17 +263,24 @@ public class MapSheetMngCoreService {
String yyyy, String yyyy,
String mapSheetScope, String mapSheetScope,
String detectOption) { String detectOption) {
Map<String, Object> result = new HashMap<>(); List<ImageFeature> features = loadSceneInferenceByFallbackYears(yearDtos);
return writeSceneGeoJson(yyyy, mapSheetScope, detectOption, features);
}
/**
* 파일 경로/이름 , 파일 생성 , 도엽번호 반환
*
* @param yyyy
* @param mapSheetScope
* @param detectOption
* @param sceneInference
* @return Scene
*/
private Scene writeSceneGeoJson(
String yyyy, String mapSheetScope, String detectOption, List<ImageFeature> sceneInference) {
boolean isAll = MapSheetScope.ALL.getId().equals(mapSheetScope); boolean isAll = MapSheetScope.ALL.getId().equals(mapSheetScope);
String optionSuffix = buildOptionSuffix(detectOption);
String optionSuffix = "";
if (DetectOption.EXCL.getId().equals(detectOption)) {
optionSuffix = "_EXCL";
} else if (DetectOption.PREV.getId().equals(detectOption)) {
optionSuffix = "_PREV";
}
// 1) 경로/파일명 결정
String targetDir = String targetDir =
"local".equals(activeEnv) ? System.getProperty("user.home") + "/geojson" : inferenceDir; "local".equals(activeEnv) ? System.getProperty("user.home") + "/geojson" : inferenceDir;
@@ -347,33 +291,11 @@ public class MapSheetMngCoreService {
Path outputPath = Paths.get(targetDir, filename); Path outputPath = Paths.get(targetDir, filename);
// 3) 데이터 조회
Map<Integer, List<MapSheetFallbackYearDto>> groupedByYear =
yearDtos.stream().collect(Collectors.groupingBy(MapSheetFallbackYearDto::getMngYyyy));
List<ImageFeature> sceneInference = new ArrayList<>();
// 년도별로 루프 돌리기
for (Map.Entry<Integer, List<MapSheetFallbackYearDto>> entry : groupedByYear.entrySet()) {
Integer compareYear = entry.getKey();
List<MapSheetFallbackYearDto> listByYear = entry.getValue();
// 도엽번호만 추출
List<String> sheetNums =
listByYear.stream().map(MapSheetFallbackYearDto::getMapSheetNum).toList();
List<ImageFeature> tempSceneInference =
mapSheetMngRepository.getSceneInference(compareYear.toString(), sheetNums);
tempSceneInference.addAll(sceneInference);
}
if (sceneInference == null || sceneInference.isEmpty()) { if (sceneInference == null || sceneInference.isEmpty()) {
log.warn("NOT_FOUND_TARGET_YEAR: yyyy={}, isAll={}, scenesSize={}", yyyy, isAll, 0); log.warn("NOT_FOUND_TARGET_YEAR: yyyy={}, isAll={}, featuresSize={}", yyyy, isAll, 0);
throw new CustomApiException("NOT_FOUND_TARGET_YEAR", HttpStatus.NOT_FOUND); throw new CustomApiException("NOT_FOUND_TARGET_YEAR", HttpStatus.NOT_FOUND);
} }
// 4) 파일 생성
try { try {
log.info("create Directories outputPath: {}", outputPath); log.info("create Directories outputPath: {}", outputPath);
log.info( log.info(
@@ -383,15 +305,15 @@ public class MapSheetMngCoreService {
targetDir, targetDir,
filename); filename);
log.info("outputPath={}, parent={}", outputPath.toAbsolutePath(), outputPath.getParent()); log.info("outputPath={}, parent={}", outputPath.toAbsolutePath(), outputPath.getParent());
Files.createDirectories(outputPath.getParent()); Files.createDirectories(outputPath.getParent());
new GeoJsonFileWriter() new GeoJsonFileWriter()
.exportToFile(sceneInference, "scene_inference_" + yyyy, 5186, outputPath.toString()); .exportToFile(sceneInference, "scene_inference_" + yyyy, 5186, outputPath.toString());
log.info("GeoJsonFileWriter: {}", "scene_inference_" + yyyy);
Scene scene = new Scene(); Scene scene = new Scene();
scene.setFeatures(sceneInference); scene.setFeatures(sceneInference);
scene.setFilePath(outputPath.toString()); scene.setFilePath(outputPath.toString());
return scene; return scene;
} catch (IOException e) { } catch (IOException e) {
@@ -401,6 +323,71 @@ public class MapSheetMngCoreService {
} }
} }
private String buildOptionSuffix(String detectOption) {
if (DetectOption.EXCL.getId().equals(detectOption)) return "_EXCL";
if (DetectOption.PREV.getId().equals(detectOption)) return "_PREV";
return "";
}
/**
* 년도, 도엽번호로 조회
*
* @param yyyy
* @param scenes
* @return ImageFeature
*/
private List<ImageFeature> loadSceneInferenceBySheets(String yyyy, List<String> scenes) {
List<ImageFeature> sceneInference = mapSheetMngRepository.getSceneInference(yyyy, scenes);
if (sceneInference == null || sceneInference.isEmpty()) {
log.warn(
"NOT_FOUND_TARGET_YEAR: yyyy={}, scenesSize={}",
yyyy,
scenes == null ? 0 : scenes.size());
throw new CustomApiException("NOT_FOUND_TARGET_YEAR", HttpStatus.NOT_FOUND);
}
return sceneInference;
}
/**
* 년도별로 나눠 조회
*
* @param yearDtos
* @return ImageFeature
*/
private List<ImageFeature> loadSceneInferenceByFallbackYears(
List<MapSheetFallbackYearDto> yearDtos) {
if (yearDtos == null || yearDtos.isEmpty()) {
return List.of();
}
Map<Integer, List<MapSheetFallbackYearDto>> groupedByYear =
yearDtos.stream()
.filter(d -> d.getMngYyyy() != null && d.getMapSheetNum() != null)
.collect(Collectors.groupingBy(MapSheetFallbackYearDto::getMngYyyy));
List<ImageFeature> sceneInference = new ArrayList<>();
for (Map.Entry<Integer, List<MapSheetFallbackYearDto>> entry : groupedByYear.entrySet()) {
Integer year = entry.getKey();
List<String> sheetNums =
entry.getValue().stream()
.map(MapSheetFallbackYearDto::getMapSheetNum)
.filter(Objects::nonNull)
.distinct()
.toList();
List<ImageFeature> temp = mapSheetMngRepository.getSceneInference(year.toString(), sheetNums);
if (temp != null && !temp.isEmpty()) {
sceneInference.addAll(temp);
}
}
return sceneInference;
}
/** /**
* 변화탐지 실행 가능 기준 년도 조회 * 변화탐지 실행 가능 기준 년도 조회
* *