Geojson Polygon DATA Operating System Build Complete - Daniel C No.5
This commit is contained in:
@@ -2,7 +2,9 @@ package com.kamco.cd.kamcoback.inference;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.LearningModelResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.service.InferenceResultService;
|
||||
import com.kamco.cd.kamcoback.inference.service.LearningModelResultProcessor;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
@@ -10,10 +12,17 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -24,7 +33,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class InferenceResultApiController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InferenceResultApiController.class);
|
||||
|
||||
private final InferenceResultService inferenceResultService;
|
||||
private final LearningModelResultProcessor learningModelResultProcessor;
|
||||
|
||||
@Operation(summary = "추론관리 분석결과 목록 조회", description = "분석상태, 제목으로 분석결과를 조회 합니다.")
|
||||
@ApiResponses(
|
||||
@@ -132,4 +144,182 @@ public class InferenceResultApiController {
|
||||
inferenceResultService.getInferenceResultGeomList(searchGeoReq);
|
||||
return ApiResponseDto.ok(geomList);
|
||||
}
|
||||
|
||||
@Operation(summary = "학습모델 결과 처리", description = "실제 학습모델 GeoJSON 파일을 처리하여 데이터베이스에 저장합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "처리 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema =
|
||||
@Schema(implementation = LearningModelResultDto.ProcessResponse.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/learning-model/process")
|
||||
public ApiResponseDto<LearningModelResultDto.ProcessResponse> processLearningModelResult(
|
||||
@RequestBody LearningModelResultDto.ProcessRequest request) {
|
||||
try {
|
||||
logger.info("Processing learning model result file: {}", request.getFilePath());
|
||||
|
||||
Path filePath = Paths.get(request.getFilePath());
|
||||
int processedFeatures = learningModelResultProcessor.processLearningModelResult(filePath);
|
||||
|
||||
LearningModelResultDto.ProcessResponse response =
|
||||
LearningModelResultDto.ProcessResponse.builder()
|
||||
.success(true)
|
||||
.message("학습모델 결과 처리가 완료되었습니다.")
|
||||
.processedFeatures(processedFeatures)
|
||||
.filePath(request.getFilePath())
|
||||
.build();
|
||||
|
||||
logger.info(
|
||||
"Successfully processed {} features from file: {}",
|
||||
processedFeatures,
|
||||
request.getFilePath());
|
||||
return ApiResponseDto.ok(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to process learning model result: {}", request.getFilePath(), e);
|
||||
|
||||
LearningModelResultDto.ProcessResponse response =
|
||||
LearningModelResultDto.ProcessResponse.builder()
|
||||
.success(false)
|
||||
.message("학습모델 결과 처리 중 오류가 발생했습니다: " + e.getMessage())
|
||||
.processedFeatures(0)
|
||||
.filePath(request.getFilePath())
|
||||
.build();
|
||||
|
||||
return ApiResponseDto.ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "학습모델 결과 일괄 처리", description = "여러 학습모델 GeoJSON 파일을 일괄 처리하여 데이터베이스에 저장합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "처리 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema =
|
||||
@Schema(
|
||||
implementation = LearningModelResultDto.BatchProcessResponse.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/learning-model/process-batch")
|
||||
public ApiResponseDto<LearningModelResultDto.BatchProcessResponse>
|
||||
processBatchLearningModelResults(
|
||||
@RequestBody LearningModelResultDto.BatchProcessRequest request) {
|
||||
try {
|
||||
logger.info("Processing {} learning model result files", request.getFilePaths().size());
|
||||
|
||||
List<Path> filePaths = new ArrayList<>();
|
||||
for (String filePath : request.getFilePaths()) {
|
||||
filePaths.add(Paths.get(filePath));
|
||||
}
|
||||
|
||||
int totalProcessedFeatures =
|
||||
learningModelResultProcessor.processMultipleLearningModelResults(filePaths);
|
||||
|
||||
LearningModelResultDto.BatchProcessResponse response =
|
||||
LearningModelResultDto.BatchProcessResponse.builder()
|
||||
.success(true)
|
||||
.message("일괄 학습모델 결과 처리가 완료되었습니다.")
|
||||
.totalProcessedFeatures(totalProcessedFeatures)
|
||||
.processedFileCount(request.getFilePaths().size())
|
||||
.filePaths(request.getFilePaths())
|
||||
.build();
|
||||
|
||||
logger.info(
|
||||
"Successfully processed {} features from {} files",
|
||||
totalProcessedFeatures,
|
||||
request.getFilePaths().size());
|
||||
return ApiResponseDto.ok(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to process batch learning model results", e);
|
||||
|
||||
LearningModelResultDto.BatchProcessResponse response =
|
||||
LearningModelResultDto.BatchProcessResponse.builder()
|
||||
.success(false)
|
||||
.message("일괄 학습모델 결과 처리 중 오류가 발생했습니다: " + e.getMessage())
|
||||
.totalProcessedFeatures(0)
|
||||
.processedFileCount(0)
|
||||
.filePaths(request.getFilePaths())
|
||||
.build();
|
||||
|
||||
return ApiResponseDto.ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "기본 학습모델 파일 처리", description = "미리 준비된 학습모델 파일을 처리합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "처리 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema =
|
||||
@Schema(
|
||||
implementation = LearningModelResultDto.BatchProcessResponse.class))),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/learning-model/process-default")
|
||||
public ApiResponseDto<LearningModelResultDto.BatchProcessResponse>
|
||||
processDefaultLearningModelResults() {
|
||||
try {
|
||||
logger.info("Processing default learning model result files");
|
||||
|
||||
// Process the two default learning model files from upload directory
|
||||
List<String> defaultFilePaths =
|
||||
List.of(
|
||||
"/Users/deniallee/geojson/upload/캠코_2021_2022_35813023.geojson",
|
||||
"/Users/deniallee/geojson/upload/캠코_2023_2024_35810049.geojson");
|
||||
|
||||
List<Path> filePaths = new ArrayList<>();
|
||||
for (String filePath : defaultFilePaths) {
|
||||
filePaths.add(Paths.get(filePath));
|
||||
}
|
||||
|
||||
int totalProcessedFeatures =
|
||||
learningModelResultProcessor.processMultipleLearningModelResults(filePaths);
|
||||
|
||||
LearningModelResultDto.BatchProcessResponse response =
|
||||
LearningModelResultDto.BatchProcessResponse.builder()
|
||||
.success(true)
|
||||
.message("기본 학습모델 결과 파일 처리가 완료되었습니다.")
|
||||
.totalProcessedFeatures(totalProcessedFeatures)
|
||||
.processedFileCount(defaultFilePaths.size())
|
||||
.filePaths(defaultFilePaths)
|
||||
.build();
|
||||
|
||||
logger.info(
|
||||
"Successfully processed {} features from {} default files",
|
||||
totalProcessedFeatures,
|
||||
defaultFilePaths.size());
|
||||
return ApiResponseDto.ok(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to process default learning model results", e);
|
||||
|
||||
LearningModelResultDto.BatchProcessResponse response =
|
||||
LearningModelResultDto.BatchProcessResponse.builder()
|
||||
.success(false)
|
||||
.message("기본 학습모델 결과 처리 중 오류가 발생했습니다: " + e.getMessage())
|
||||
.totalProcessedFeatures(0)
|
||||
.processedFileCount(0)
|
||||
.filePaths(List.of())
|
||||
.build();
|
||||
|
||||
return ApiResponseDto.ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user