diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceDetailDto.java b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceDetailDto.java index 3dd7922d..d30d5ce8 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceDetailDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceDetailDto.java @@ -29,20 +29,22 @@ public class InferenceDetailDto { private String dataName; private Long mapSheepNum; private Long detectingCnt; - @JsonFormatDttm private ZonedDateTime analStrtDttm; - @JsonFormatDttm private ZonedDateTime analEndDttm; + @JsonFormatDttm + private ZonedDateTime analStrtDttm; + @JsonFormatDttm + private ZonedDateTime analEndDttm; private Long analSec; private String analState; public Basic( - Long id, - String dataName, - Long mapSheepNum, - Long detectingCnt, - ZonedDateTime analStrtDttm, - ZonedDateTime analEndDttm, - Long analSec, - String analState) { + Long id, + String dataName, + Long mapSheepNum, + Long detectingCnt, + ZonedDateTime analStrtDttm, + ZonedDateTime analEndDttm, + Long analSec, + String analState) { this.id = id; this.dataName = dataName; this.mapSheepNum = mapSheepNum; @@ -61,8 +63,10 @@ public class InferenceDetailDto { private Long id; private String analTitle; private Long detectingCnt; - @JsonFormatDttm private ZonedDateTime analStrtDttm; - @JsonFormatDttm private ZonedDateTime analEndDttm; + @JsonFormatDttm + private ZonedDateTime analStrtDttm; + @JsonFormatDttm + private ZonedDateTime analEndDttm; private Long analSec; private Long analPredSec; private String analState; @@ -70,16 +74,16 @@ public class InferenceDetailDto { private String gukyuinUsed; public AnalResList( - Long id, - String analTitle, - Long detectingCnt, - ZonedDateTime analStrtDttm, - ZonedDateTime analEndDttm, - Long analSec, - Long analPredSec, - String analState, - String analStateNm, - String gukyuinUsed) { + Long id, + String analTitle, + Long detectingCnt, + ZonedDateTime analStrtDttm, + ZonedDateTime analEndDttm, + Long analSec, + Long analPredSec, + String analState, + String analStateNm, + String gukyuinUsed) { this.id = id; this.analTitle = analTitle; this.detectingCnt = detectingCnt; @@ -102,8 +106,10 @@ public class InferenceDetailDto { private String modelInfo; private Integer targetYyyy; private Integer compareYyyy; - @JsonFormatDttm private ZonedDateTime analStrtDttm; - @JsonFormatDttm private ZonedDateTime analEndDttm; + @JsonFormatDttm + private ZonedDateTime analStrtDttm; + @JsonFormatDttm + private ZonedDateTime analEndDttm; private Long analSec; private Long analPredSec; private String resultUrl; @@ -113,20 +119,20 @@ public class InferenceDetailDto { private String analStateNm; public AnalResSummary( - Long id, - String analTitle, - String modelInfo, - Integer targetYyyy, - Integer compareYyyy, - ZonedDateTime analStrtDttm, - ZonedDateTime analEndDttm, - Long analSec, - Long analPredSec, - String resultUrl, - Long detectingCnt, - Double accuracy, - String analState, - String analStateNm) { + Long id, + String analTitle, + String modelInfo, + Integer targetYyyy, + Integer compareYyyy, + ZonedDateTime analStrtDttm, + ZonedDateTime analEndDttm, + Long analSec, + Long analPredSec, + String resultUrl, + Long detectingCnt, + Double accuracy, + String analState, + String analStateNm) { this.id = id; this.analTitle = analTitle; this.modelInfo = modelInfo; @@ -183,16 +189,17 @@ public class InferenceDetailDto { private Clazzes target; private MapSheet mapSheet; private Coordinate center; - @JsonFormatDttm private ZonedDateTime updatedDttm; + @JsonFormatDttm + private ZonedDateTime updatedDttm; public DetailListEntity( - UUID uuid, - Double detectionScore, - Clazzes compare, - Clazzes target, - MapSheet mapSheet, - Coordinate center, - ZonedDateTime updatedDttm) { + UUID uuid, + Double detectionScore, + Clazzes compare, + Clazzes target, + MapSheet mapSheet, + Coordinate center, + ZonedDateTime updatedDttm) { this.code = new Uid(uuid); this.detectionScore = detectionScore; this.compare = compare; @@ -233,7 +240,8 @@ public class InferenceDetailDto { private String code; private String name; - @JsonIgnore private Double score; + @JsonIgnore + private Double score; public Clazz(String code, Double score) { this.code = code; @@ -300,21 +308,23 @@ public class InferenceDetailDto { String classAfterName; Double classAfterProb; Long mapSheetNum; - @JsonIgnore String gemoStr; - @JsonIgnore String geomCenterStr; + @JsonIgnore + String gemoStr; + @JsonIgnore + String geomCenterStr; JsonNode gemo; JsonNode geomCenter; public Geom( - Integer compareYyyy, - Integer targetYyyy, - String classBeforeCd, - Double classBeforeProb, - String classAfterCd, - Double classAfterProb, - Long mapSheetNum, - String gemoStr, - String geomCenterStr) { + Integer compareYyyy, + Integer targetYyyy, + String classBeforeCd, + Double classBeforeProb, + String classAfterCd, + Double classAfterProb, + Long mapSheetNum, + String gemoStr, + String geomCenterStr) { this.compareYyyy = compareYyyy; this.targetYyyy = targetYyyy; this.classBeforeCd = classBeforeCd; @@ -385,7 +395,7 @@ public class InferenceDetailDto { String[] sortParams = sort.split(","); String property = sortParams[0]; Sort.Direction direction = - sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC; + sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC; return PageRequest.of(page, size, Sort.by(direction, property)); } return PageRequest.of(page, size); @@ -399,10 +409,14 @@ public class InferenceDetailDto { public static class InferenceBatchSheet { private Long id; + private UUID uuid; private Long m1BatchId; private Long m2BatchId; private Long m3BatchId; private String status; private String runningModelType; + private UUID m1ModelUuid; + private UUID m2ModelUuid; + private UUID m3ModelUuid; } } diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceProgressDto.java b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceProgressDto.java index 63c073e1..adf564c4 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceProgressDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceProgressDto.java @@ -11,36 +11,36 @@ import lombok.Setter; public class InferenceProgressDto { private InferenceProgressDto.pred_requests_areas pred_requests_areas; - private String model1_version; - private String model2_version; - private String model3_version; - private String cd_model_path; - private String cd_model_config; - private String cls_model_path; - private String cls_model_version; - private String cd_model_type; + private String modelVersion; + private String cdModelPath; + private String cdModelFileName; + private String cdModelConfigPath; + private String cdModelConfigFileName; + private String cdModelClsPath; + private String cdModelClsFileName; + private String clsModelVersion; private Integer priority; public InferenceProgressDto( - InferenceProgressDto.pred_requests_areas pred_requests_areas, - String model1_version, - String model2_version, - String model3_version, - String cd_model_path, - String cd_model_config, - String cls_model_path, - String cls_model_version, - String cd_model_type, - Integer priority) { + InferenceProgressDto.pred_requests_areas pred_requests_areas, + String modelVersion, + String cdModelPath, + String cdModelFileName, + String cdModelConfigPath, + String cdModelConfigFileName, + String cdModelClsPath, + String cdModelClsFileName, + String clsModelVersion, + Integer priority) { this.pred_requests_areas = pred_requests_areas; - this.model1_version = model1_version; - this.model2_version = model2_version; - this.model3_version = model3_version; - this.cd_model_path = cd_model_path; - this.cd_model_config = cd_model_config; - this.cls_model_path = cls_model_path; - this.cls_model_version = cls_model_version; - this.cd_model_type = cd_model_type; + this.modelVersion = modelVersion; + this.cdModelPath = cdModelPath; + this.cdModelFileName = cdModelFileName; + this.cdModelConfigPath = cdModelConfigPath; + this.cdModelConfigFileName = cdModelConfigFileName; + this.cdModelClsPath = cdModelClsPath; + this.cdModelClsFileName = cdModelClsFileName; + this.clsModelVersion = clsModelVersion; this.priority = priority; } diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java index 154fed2d..adce8244 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java @@ -23,7 +23,9 @@ import org.springframework.data.domain.Pageable; public class InferenceResultDto { - /** 목록조회 dto */ + /** + * 목록조회 dto + */ @Getter @Setter @AllArgsConstructor @@ -35,11 +37,15 @@ public class InferenceResultDto { private String status; private String mapSheetCnt; private Long detectingCnt; - @JsonFormatDttm private ZonedDateTime startTime; - @JsonFormatDttm private ZonedDateTime endTime; - @JsonFormatDttm private ZonedDateTime elapsedTime; + @JsonFormatDttm + private ZonedDateTime startTime; + @JsonFormatDttm + private ZonedDateTime endTime; + @JsonFormatDttm + private ZonedDateTime elapsedTime; private Boolean applyYn; - @JsonFormatDttm private ZonedDateTime applyDttm; + @JsonFormatDttm + private ZonedDateTime applyDttm; @JsonProperty("statusName") public String statusName() { @@ -47,7 +53,9 @@ public class InferenceResultDto { } } - /** 목록조회 검색 조건 dto */ + /** + * 목록조회 검색 조건 dto + */ @Getter @Setter @NoArgsConstructor @@ -201,6 +209,7 @@ public class InferenceResultDto { @NoArgsConstructor @AllArgsConstructor public static class InferenceStatusDetailDto { + private String title; private Integer compareYyyy; private Integer targetYyyy; @@ -337,9 +346,12 @@ public class InferenceResultDto { public static class InferenceServerStatusDto { private String serverName; - @JsonIgnore private float cpu_user; - @JsonIgnore private float cpu_system; - @JsonIgnore private float memused; + @JsonIgnore + private float cpu_user; + @JsonIgnore + private float cpu_system; + @JsonIgnore + private float memused; private Long kbmemused; private float gpuUtil; @@ -444,7 +456,13 @@ public class InferenceResultDto { private String status; private String type; private ZonedDateTime inferStartDttm; + private ZonedDateTime inferEndDttm; + private Long detectEndCnt; private String modelComparePath; private String modelTargetPath; + private String modelModelPath; + private ZonedDateTime modelStartDttm; + private ZonedDateTime modelEndDttm; + private Long updateUid; } } diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/service/InferenceResultService.java b/src/main/java/com/kamco/cd/kamcoback/inference/service/InferenceResultService.java index 8e134a30..dc6cfccf 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/service/InferenceResultService.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/service/InferenceResultService.java @@ -96,7 +96,7 @@ public class InferenceResultService { // 기준년도 조회 List targetList = - mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds); + mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds); req.setMapSheetNum(this.createdMngDto(req, targetList)); } @@ -109,19 +109,19 @@ public class InferenceResultService { // 비교년도 탐지 제이터 옵션 별로 조회하여 req에 적용 private List createdMngDto( - InferenceResultDto.RegReq req, List targetList) { + InferenceResultDto.RegReq req, List targetList) { List mapTargetIds = new ArrayList<>(); targetList.forEach( - hstMapSheet -> { - // 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기 - mapTargetIds.add(hstMapSheet.getMapSheetNum()); - }); + hstMapSheet -> { + // 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기 + mapTargetIds.add(hstMapSheet.getMapSheetNum()); + }); // 비교년도 조회 List mapCompareIds = new ArrayList<>(); List compareList = - mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds); + mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds); for (MngListCompareDto dto : compareList) { // 추론 제외일때 이전년도 파일이 없으면 제외 @@ -136,35 +136,35 @@ public class InferenceResultService { } Set compareSet = - mapCompareIds.stream() - .filter(Objects::nonNull) - .map(String::trim) // 공백/개행 방지 - .collect(Collectors.toSet()); + mapCompareIds.stream() + .filter(Objects::nonNull) + .map(String::trim) // 공백/개행 방지 + .collect(Collectors.toSet()); // target 기준 compare 비교하여 서로 있는것만 저장 List commonIds = - mapTargetIds.stream() - .filter(Objects::nonNull) - .map(String::trim) - .filter(compareSet::contains) - .toList(); + mapTargetIds.stream() + .filter(Objects::nonNull) + .map(String::trim) + .filter(compareSet::contains) + .toList(); Set commonIdSet = - commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet()); + commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet()); // 저장하기위해 파라미터 다시 구성 List mapSheetNum = - targetList.stream() - .filter(dto -> dto.getMapSheetNum() != null) - .filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim())) - .map( - dto -> { - MapSheetNumDto mapSheetNumDto = new MapSheetNumDto(); - mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum()); - mapSheetNumDto.setMapSheetName(dto.getMapSheetName()); - return mapSheetNumDto; - }) - .toList(); + targetList.stream() + .filter(dto -> dto.getMapSheetNum() != null) + .filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim())) + .map( + dto -> { + MapSheetNumDto mapSheetNumDto = new MapSheetNumDto(); + mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum()); + mapSheetNumDto.setMapSheetName(dto.getMapSheetName()); + return mapSheetNumDto; + }) + .toList(); return mapSheetNum; } @@ -184,9 +184,9 @@ public class InferenceResultService { } String modelComparePath = - this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList); + this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList); String modelTargetPath = - this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); + this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); pred_requests_areas predRequestsAreas = new pred_requests_areas(); predRequestsAreas.setInput1_year(req.getCompareYyyy()); @@ -212,6 +212,7 @@ public class InferenceResultService { saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now()); saveInferenceAiDto.setModelComparePath(modelComparePath); saveInferenceAiDto.setModelTargetPath(modelTargetPath); + saveInferenceAiDto.setModelStartDttm(ZonedDateTime.now()); inferenceResultCoreService.update(saveInferenceAiDto); } @@ -240,7 +241,7 @@ public class InferenceResultService { } ExternalCallResult result = - externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class); + externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class); int status = result.statusCode(); String body = result.body(); @@ -253,7 +254,8 @@ public class InferenceResultService { try { List> list = - om.readValue(body, new TypeReference>>() {}); + om.readValue(body, new TypeReference>>() { + }); Integer batchIdInt = (Integer) list.get(0).get("batch_id"); batchId = batchIdInt.longValue(); @@ -352,7 +354,7 @@ public class InferenceResultService { * @return */ public Page getInferenceResultGeomList( - Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { + Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { return inferenceResultCoreService.getInferenceResultGeomList(id, searchGeoReq); } @@ -363,7 +365,7 @@ public class InferenceResultService { * @return */ public Page listInferenceResultWithGeom( - @NotNull Long id, InferenceDetailDto.SearchGeoReq searchReq) { + @NotNull Long id, InferenceDetailDto.SearchGeoReq searchReq) { return inferenceResultCoreService.listInferenceResultWithGeom(id, searchReq); } @@ -408,12 +410,15 @@ public class InferenceResultService { public InferenceStatusDetailDto getInferenceStatus(UUID uuid) { List servers = - inferenceResultCoreService.getInferenceServerStatusList(); + inferenceResultCoreService.getInferenceServerStatusList(); String serverNames = ""; for (InferenceServerStatusDto server : servers) { - if (serverNames.equals("")) serverNames = server.getServerName(); - else serverNames = serverNames + "," + server.getServerName(); + if (serverNames.equals("")) { + serverNames = server.getServerName(); + } else { + serverNames = serverNames + "," + server.getServerName(); + } } InferenceStatusDetailDto dto = inferenceResultCoreService.getInferenceStatus(uuid); diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/core/InferenceResultCoreService.java b/src/main/java/com/kamco/cd/kamcoback/postgres/core/InferenceResultCoreService.java index 70ea79b2..f71deae2 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/core/InferenceResultCoreService.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/core/InferenceResultCoreService.java @@ -6,6 +6,7 @@ import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.Dashboard; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.MapSheet; +import com.kamco.cd.kamcoback.inference.dto.InferenceProgressDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceServerStatusDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceStatusDetailDto; @@ -24,6 +25,7 @@ import com.kamco.cd.kamcoback.postgres.repository.scene.MapInkx5kRepository; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; import jakarta.validation.constraints.NotNull; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -63,11 +65,11 @@ public class InferenceResultCoreService { */ public UUID saveInferenceInfo(InferenceResultDto.RegReq req) { String mapSheetName = - req.getMapSheetNum().get(0).getMapSheetName() + " 외 " + req.getMapSheetNum().size() + "건"; + req.getMapSheetNum().get(0).getMapSheetName() + " 외 " + req.getMapSheetNum().size() + "건"; if (req.getMapSheetNum().size() == 1) { mapSheetName = - req.getMapSheetNum().get(0).getMapSheetName() + " " + req.getMapSheetNum().size() + "건"; + req.getMapSheetNum().get(0).getMapSheetName() + " " + req.getMapSheetNum().size() + "건"; } MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity(); @@ -115,22 +117,22 @@ public class InferenceResultCoreService { // 청크 번호 추출 in 조건 만들기 List chunkNums = - buffer.stream().map(e -> String.valueOf(e.getMapSheetNum())).distinct().toList(); + buffer.stream().map(e -> String.valueOf(e.getMapSheetNum())).distinct().toList(); // 추론 제외 List usedEntities = - mapInkx5kRepository.findByMapSheetNumInAndUseInference(chunkNums, CommonUseStatus.USE); + mapInkx5kRepository.findByMapSheetNumInAndUseInference(chunkNums, CommonUseStatus.USE); // TODO 추론 제외 했으면 파일 있는지도 확인 해야함 // 조회 결과에서 번호만 Set으로 Set usedSet = - usedEntities.stream() - .map(MapInkx5kEntity::getMapidcdNo) - .collect(java.util.stream.Collectors.toSet()); + usedEntities.stream() + .map(MapInkx5kEntity::getMapidcdNo) + .collect(java.util.stream.Collectors.toSet()); // 필터 후 저장 List toSave = - buffer.stream().filter(e -> usedSet.contains(String.valueOf(e.getMapSheetNum()))).toList(); + buffer.stream().filter(e -> usedSet.contains(String.valueOf(e.getMapSheetNum()))).toList(); if (!toSave.isEmpty()) { mapSheetLearn5kRepository.saveAll(toSave); @@ -150,9 +152,9 @@ public class InferenceResultCoreService { */ public InferenceDetailDto.AnalResSummary getInferenceResultSummary(Long id) { InferenceDetailDto.AnalResSummary summary = - mapSheetAnalDataRepository - .getInferenceResultSummary(id) - .orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id)); + mapSheetAnalDataRepository + .getInferenceResultSummary(id) + .orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id)); return summary; } @@ -173,7 +175,7 @@ public class InferenceResultCoreService { * @return */ public Page getInferenceResultGeomList( - Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { + Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { return mapSheetAnalDataRepository.getInferenceGeomList(id, searchGeoReq); } @@ -185,16 +187,16 @@ public class InferenceResultCoreService { */ @Transactional(readOnly = true) public Page listInferenceResultWithGeom( - @NotNull Long analyId, InferenceDetailDto.SearchGeoReq searchReq) { + @NotNull Long analyId, InferenceDetailDto.SearchGeoReq searchReq) { // 분석 ID 에 해당하는 dataids를 가져온다. List dataIds = - mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() - .mapToLong(MapSheetAnalDataInferenceEntity::getId) - .boxed() - .toList(); + mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() + .mapToLong(MapSheetAnalDataInferenceEntity::getId) + .boxed() + .toList(); // 해당데이터의 폴리곤데이터를 가져온다 Page mapSheetAnalDataGeomEntities = - mapSheetAnalDataRepository.listInferenceResultWithGeom(dataIds, searchReq); + mapSheetAnalDataRepository.listInferenceResultWithGeom(dataIds, searchReq); return mapSheetAnalDataGeomEntities.map(MapSheetAnalDataInferenceGeomEntity::toEntity); } @@ -211,34 +213,64 @@ public class InferenceResultCoreService { @Transactional(readOnly = true) public List listGetScenes5k(Long analyId) { List sceneCodes = - mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() - .mapToLong(MapSheetAnalDataInferenceEntity::getMapSheetNum) - .mapToObj(String::valueOf) - .toList(); + mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() + .mapToLong(MapSheetAnalDataInferenceEntity::getMapSheetNum) + .mapToObj(String::valueOf) + .toList(); return mapInkx5kRepository.listGetScenes5k(sceneCodes).stream() - .map(MapInkx5kEntity::toEntity) - .toList(); + .map(MapInkx5kEntity::toEntity) + .toList(); } public void update(SaveInferenceAiDto request) { MapSheetLearnEntity entity = - mapSheetLearnRepository - .getInferenceResultByUuid(request.getUuid()) - .orElseThrow(() -> new EntityNotFoundException()); + mapSheetLearnRepository + .getInferenceResultByUuid(request.getUuid()) + .orElseThrow(() -> new EntityNotFoundException()); if (request.getType().equals("M1")) { entity.setM1ModelBatchId(request.getBatchId()); + + if (request.getModelStartDttm() != null) { + entity.setM1ModelStartDttm(request.getModelStartDttm()); + } + + if (request.getModelEndDttm() != null) { + entity.setM1ModelEndDttm(request.getModelEndDttm()); + } + } else if (request.getType().equals("M2")) { entity.setM2ModelBatchId(request.getBatchId()); + + if (request.getModelStartDttm() != null) { + entity.setM2ModelStartDttm(request.getModelStartDttm()); + } + + if (request.getModelEndDttm() != null) { + entity.setM2ModelEndDttm(request.getModelEndDttm()); + } + } else if (request.getType().equals("M3")) { entity.setM3ModelBatchId(request.getBatchId()); + + if (request.getModelStartDttm() != null) { + entity.setM3ModelStartDttm(request.getModelStartDttm()); + } + + if (request.getModelEndDttm() != null) { + entity.setM3ModelEndDttm(request.getModelEndDttm()); + } } if (request.getInferStartDttm() != null) { entity.setInferStartDttm(request.getInferStartDttm()); } + if (request.getInferEndDttm() != null) { + entity.setInferEndDttm(request.getInferEndDttm()); + } + if (request.getModelComparePath() != null) { entity.setModelComparePath(request.getModelComparePath()); } @@ -247,8 +279,24 @@ public class InferenceResultCoreService { entity.setModelTargetPath(request.getModelTargetPath()); } - entity.setRunningModelType(request.getType()); - entity.setStatus(request.getStatus()); + if (request.getDetectEndCnt() != null) { + entity.setDetectEndCnt(request.getDetectEndCnt()); + } + + if (request.getType() != null) { + entity.setRunningModelType(request.getType()); + } + + if (request.getStatus() != null) { + entity.setStatus(request.getStatus()); + } + + if (request.getUpdateUid() != null) { + entity.setUpdatedUid(request.getUpdateUid()); + } + + entity.setUpdatedDttm(ZonedDateTime.now()); + } public List getInferenceServerStatusList() { @@ -257,23 +305,26 @@ public class InferenceResultCoreService { public InferenceBatchSheet getInferenceResultByStatus(String status) { MapSheetLearnEntity entity = - mapSheetLearnRepository - .getInferenceResultByStatus(status) - .orElseThrow(() -> new EntityNotFoundException(status)); + mapSheetLearnRepository + .getInferenceResultByStatus(status) + .orElseThrow(() -> new EntityNotFoundException(status)); InferenceBatchSheet inferenceBatchSheet = new InferenceBatchSheet(); inferenceBatchSheet.setId(entity.getId()); + inferenceBatchSheet.setUuid(entity.getUuid()); inferenceBatchSheet.setM1BatchId(entity.getM1ModelBatchId()); inferenceBatchSheet.setM2BatchId(entity.getM2ModelBatchId()); inferenceBatchSheet.setM3BatchId(entity.getM3ModelBatchId()); inferenceBatchSheet.setStatus(entity.getStatus()); inferenceBatchSheet.setRunningModelType(entity.getRunningModelType()); + inferenceBatchSheet.setM1ModelUuid(entity.getM1ModelUuid()); + inferenceBatchSheet.setM2ModelUuid(entity.getM2ModelUuid()); + inferenceBatchSheet.setM3ModelUuid(entity.getM3ModelUuid()); return inferenceBatchSheet; } - public SaveInferenceAiDto getInferenceAiResultById(Long id) { - - return null; + public InferenceProgressDto getInferenceAiResultById(Long id, String type, UUID modelUuid) { + return mapSheetLearnRepository.getInferenceAiResultById(id, modelUuid); } public InferenceStatusDetailDto getInferenceStatus(UUID uuid) { diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetLearnEntity.java b/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetLearnEntity.java index 54000bc1..19102d6e 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetLearnEntity.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetLearnEntity.java @@ -25,9 +25,9 @@ public class MapSheetLearnEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_sheet_learn_id_gen") @SequenceGenerator( - name = "tb_map_sheet_learn_id_gen", - sequenceName = "tb_map_sheet_learn_uid", - allocationSize = 1) + name = "tb_map_sheet_learn_id_gen", + sequenceName = "tb_map_sheet_learn_uid", + allocationSize = 1) @Column(name = "id", nullable = false) private Long id; @@ -124,17 +124,30 @@ public class MapSheetLearnEntity { @Column(name = "model_target_path") private String modelTargetPath; + @Column(name = "m1_model_start_dttm") + private ZonedDateTime m1ModelStartDttm; + @Column(name = "m2_model_start_dttm") + private ZonedDateTime m2ModelStartDttm; + @Column(name = "m3_model_start_dttm") + private ZonedDateTime m3ModelStartDttm; + @Column(name = "m1_model_end_dttm") + private ZonedDateTime m1ModelEndDttm; + @Column(name = "m2_model_end_dttm") + private ZonedDateTime m2ModelEndDttm; + @Column(name = "m3_model_end_dttm") + private ZonedDateTime m3ModelEndDttm; + public InferenceResultDto.ResultList toDto() { return new InferenceResultDto.ResultList( - this.uuid, - this.title, - this.status, - this.mapSheetCnt, - this.detectingCnt, - this.inferStartDttm, - this.inferEndDttm, - this.elapsedTime, - this.applyYn, - this.applyDttm); + this.uuid, + this.title, + this.status, + this.mapSheetCnt, + this.detectingCnt, + this.inferStartDttm, + this.inferEndDttm, + this.elapsedTime, + this.applyYn, + this.applyDttm); } } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryCustom.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryCustom.java index 6b19c288..8b8ecac5 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryCustom.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryCustom.java @@ -20,7 +20,7 @@ public interface MapSheetLearnRepositoryCustom { Optional getInferenceResultByStatus(String status); - Optional getInferenceAiResultById(Long id); + InferenceProgressDto getInferenceAiResultById(Long id, UUID modelUuid); public InferenceStatusDetailDto getInferenceStatus(UUID uuid); } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryImpl.java index f5b541b2..fe6c21f4 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/Inference/MapSheetLearnRepositoryImpl.java @@ -172,11 +172,9 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto mapSheetLearnEntity.inferEndDttm, mapSheetLearnEntity.detectingCnt, mapSheetLearnEntity.detectEndCnt, - m1Model.modelVer.as("model1Ver"), m2Model.modelVer.as("model2Ver"), m3Model.modelVer.as("model3Ver"))) - .from(mapSheetLearnEntity) .leftJoin(m1Model) .on(m1Model.uuid.eq(mapSheetLearnEntity.m1ModelUuid)) diff --git a/src/main/java/com/kamco/cd/kamcoback/scheduler/service/MapSheetInferenceJobService.java b/src/main/java/com/kamco/cd/kamcoback/scheduler/service/MapSheetInferenceJobService.java index 4599d04d..eb889559 100644 --- a/src/main/java/com/kamco/cd/kamcoback/scheduler/service/MapSheetInferenceJobService.java +++ b/src/main/java/com/kamco/cd/kamcoback/scheduler/service/MapSheetInferenceJobService.java @@ -1,19 +1,30 @@ package com.kamco.cd.kamcoback.scheduler.service; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.kamco.cd.kamcoback.common.exception.CustomApiException; import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient; import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet; +import com.kamco.cd.kamcoback.inference.dto.InferenceProgressDto; +import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.SaveInferenceAiDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status; +import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto; +import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto.pred_requests_areas; import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService; import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto; +import jakarta.transaction.Transactional; +import java.time.ZonedDateTime; import java.util.List; +import java.util.Map; +import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -31,7 +42,14 @@ public class MapSheetInferenceJobService { @Value("${inference.batch-url}") private String batchUrl; + @Value("${spring.profiles.active}") + private String profile; + + @Value("${inference.url}") + private String inferenceUrl; + @Scheduled(fixedDelay = 60_000) + @Transactional public void runBatch() { log.info("1분 배치 시작"); @@ -39,7 +57,7 @@ public class MapSheetInferenceJobService { // TODO: 배치 로직 작성 InferenceBatchSheet batchSheet = - inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId()); + inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId()); if (batchSheet == null) { return; @@ -66,7 +84,7 @@ public class MapSheetInferenceJobService { String url = batchUrl + "/" + batchId; ExternalCallResult result = - externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class); + externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class); int status = result.statusCode(); if (status < 200 || status >= 300) { @@ -80,19 +98,34 @@ public class MapSheetInferenceJobService { String type = batchSheet.getRunningModelType(); if (type.equals("M1")) { - + // M1 완료되었으면 M2 실행 + this.startInference(batchSheet.getId(), batchSheet.getUuid(), "M2", batchSheet.getM2ModelUuid()); + // 종료시간 + this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M1"); } else if (type.equals("M2")) { - + // M1 완료되었으면 M3 실행 + this.startInference(batchSheet.getId(), batchSheet.getUuid(), "M3", batchSheet.getM3ModelUuid()); + // 종료시간 + this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M2"); } else if (type.equals("M3")) { - + // 완료 + SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); + saveInferenceAiDto.setUuid(batchSheet.getUuid()); + saveInferenceAiDto.setStatus(Status.END.getId()); + saveInferenceAiDto.setInferEndDttm(ZonedDateTime.now()); + inferenceResultCoreService.update(saveInferenceAiDto); + // 종료시간 + this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M3"); } + } else { + SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); + saveInferenceAiDto.setUuid(batchSheet.getUuid()); + saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId()); + saveInferenceAiDto.setDetectEndCnt(dto.getCompletedJobs().longValue()); + inferenceResultCoreService.update(saveInferenceAiDto); } - System.out.println(dto); - - Thread.sleep(3000); // 예시: 처리 시간 3초 - - } catch (InterruptedException | JsonProcessingException e) { + } catch (JsonProcessingException e) { Thread.currentThread().interrupt(); log.error("배치 중 인터럽트 발생", e); } @@ -100,44 +133,92 @@ public class MapSheetInferenceJobService { log.info("1분 배치 종료"); } - private void startInference(Long id, String type) { - // InferenceResultDto.SaveInferenceAiDto req - // inferenceResultCoreService.getInferenceResultByU - // - // List mapSheetNum = req.getMapSheetNum(); - // List mapSheetNumList = new ArrayList<>(); - // - // for (MapSheetNumDto mapSheetDto : mapSheetNum) { - // mapSheetNumList.add(mapSheetDto.getMapSheetNum()); - // } - // - // String modelComparePath = - // this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList); - // String modelTargetPath = - // this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); - // - // pred_requests_areas predRequestsAreas = new pred_requests_areas(); - // predRequestsAreas.setInput1_year(req.getCompareYyyy()); - // predRequestsAreas.setInput2_year(req.getTargetYyyy()); - // predRequestsAreas.setInput1_scene_path(modelComparePath); - // predRequestsAreas.setInput2_scene_path(modelTargetPath); - // - // InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid()); - // InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid()); - // InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid()); - // - // m1.setPred_requests_areas(predRequestsAreas); - // m2.setPred_requests_areas(predRequestsAreas); - // m3.setPred_requests_areas(predRequestsAreas); - // - // Long batchId = this.ensureAccepted(m1); - // - // SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); - // saveInferenceAiDto.setUuid(uuid); - // saveInferenceAiDto.setBatchId(batchId); - // saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId()); - // saveInferenceAiDto.setType("M1"); - // saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now()); - // inferenceResultCoreService.update(saveInferenceAiDto); + private void startInference(Long id, UUID uuid, String type, UUID modelUuid) { + + InferenceProgressDto progressDto = inferenceResultCoreService.getInferenceAiResultById(id, type, modelUuid); + + pred_requests_areas predRequestsAreas = new pred_requests_areas(); + predRequestsAreas.setInput1_year(progressDto.getPred_requests_areas().getInput1_year()); + predRequestsAreas.setInput2_year(progressDto.getPred_requests_areas().getInput2_year()); + predRequestsAreas.setInput1_scene_path(progressDto.getPred_requests_areas().getInput1_scene_path()); + predRequestsAreas.setInput2_scene_path(progressDto.getPred_requests_areas().getInput2_scene_path()); + + InferenceSendDto m = new InferenceSendDto(); + m.setModel_version(progressDto.getModelVersion()); + m.setCd_model_path(progressDto.getCdModelPath() + "/" + progressDto.getCdModelFileName()); + m.setCd_model_config(progressDto.getCdModelConfigPath() + "/" + progressDto.getCdModelConfigFileName()); + m.setCls_model_path(progressDto.getCdModelClsPath() + "/" + progressDto.getCdModelClsFileName()); + m.setCls_model_version(progressDto.getClsModelVersion()); + m.setCd_model_type(type); + m.setPriority(progressDto.getPriority()); + + // 추론 다음모델 실행 + Long batchId = this.ensureAccepted(m); + + SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); + saveInferenceAiDto.setUuid(uuid); + saveInferenceAiDto.setBatchId(batchId); + saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId()); + saveInferenceAiDto.setType(type); + saveInferenceAiDto.setModelStartDttm(ZonedDateTime.now()); + inferenceResultCoreService.update(saveInferenceAiDto); + } + + private Long ensureAccepted(InferenceSendDto dto) { + log.info("dto null? {}", dto == null); + ObjectMapper om = new ObjectMapper(); + try { + log.info("dto json={}", om.writeValueAsString(dto)); + } catch (Exception e) { + log.error(e.getMessage()); + } + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + + // TODO 추후 삭제 + if ("local".equals(profile)) { + dto.getPred_requests_areas().setInput1_scene_path("/kamco-nfs/requests/2023_local.geojson"); + dto.getPred_requests_areas().setInput2_scene_path("/kamco-nfs/requests/2024_local.geojson"); + } + + ExternalCallResult result = + externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class); + + int status = result.statusCode(); + String body = result.body(); + + if (status < 200 || status >= 300) { + throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY); + } + + Long batchId = 0L; + + try { + List> list = + om.readValue(body, new TypeReference>>() { + }); + + Integer batchIdInt = (Integer) list.get(0).get("batch_id"); + batchId = batchIdInt.longValue(); + if (list.isEmpty()) { + throw new IllegalStateException("Inference response is empty"); + } + + } catch (Exception e) { + log.error(e.getMessage()); + } + + return batchId; + } + + private void updateProcessingEndTimeByModel(UUID uuid, ZonedDateTime dateTime, String type) { + SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); + saveInferenceAiDto.setUuid(uuid); + saveInferenceAiDto.setUpdateUid(0L); + saveInferenceAiDto.setModelEndDttm(dateTime); + saveInferenceAiDto.setType(type); + inferenceResultCoreService.update(saveInferenceAiDto); } }