Merge pull request 'feat/training_260202' (#25) from feat/training_260202 into develop
Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
@@ -86,26 +86,6 @@ public class DatasetApiController {
|
|||||||
return ApiResponseDto.ok(datasetService.getDatasetDetail(uuid));
|
return ApiResponseDto.ok(datasetService.getDatasetDetail(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "학습데이터 등록", description = "학습데이터 파일 업로드")
|
|
||||||
@ApiResponses(
|
|
||||||
value = {
|
|
||||||
@ApiResponse(
|
|
||||||
responseCode = "201",
|
|
||||||
description = "등록 성공",
|
|
||||||
content =
|
|
||||||
@Content(
|
|
||||||
mediaType = "application/json",
|
|
||||||
schema = @Schema(implementation = Long.class))),
|
|
||||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
|
||||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
|
||||||
})
|
|
||||||
@PostMapping("/register")
|
|
||||||
public ApiResponseDto<Long> registerDataset(
|
|
||||||
@RequestBody @Valid DatasetDto.RegisterReq registerReq) {
|
|
||||||
Long id = datasetService.registerDataset(registerReq);
|
|
||||||
return ApiResponseDto.createOK(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "학습데이터 수정", description = "학습데이터 제목, 메모 수정")
|
@Operation(summary = "학습데이터 수정", description = "학습데이터 제목, 메모 수정")
|
||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
value = {
|
value = {
|
||||||
@@ -157,15 +137,11 @@ public class DatasetApiController {
|
|||||||
})
|
})
|
||||||
@GetMapping("/obj-list")
|
@GetMapping("/obj-list")
|
||||||
public ApiResponseDto<Page<DatasetObjDto.Basic>> searchDatasetObjectList(
|
public ApiResponseDto<Page<DatasetObjDto.Basic>> searchDatasetObjectList(
|
||||||
@Parameter(description = "회차 uuid", example = "35e20bb2-9014-4c9d-abe2-9046db5f930c")
|
@Parameter(description = "회차 uuid", example = "e9a6774b-4f81-4402-b080-51d27fac1f01")
|
||||||
@RequestParam(required = true)
|
@RequestParam(required = true)
|
||||||
UUID uuid,
|
UUID uuid,
|
||||||
@Parameter(description = "비교년도", example = "2021") @RequestParam(required = false)
|
|
||||||
Integer compareYyyy,
|
|
||||||
@Parameter(description = "비교년도분류", example = "container") @RequestParam(required = false)
|
@Parameter(description = "비교년도분류", example = "container") @RequestParam(required = false)
|
||||||
String compareClassCd,
|
String compareClassCd,
|
||||||
@Parameter(description = "기준년도", example = "2022") @RequestParam(required = false)
|
|
||||||
Integer targetYyyy,
|
|
||||||
@Parameter(description = "기준년도분류", example = "waste") @RequestParam(required = false)
|
@Parameter(description = "기준년도분류", example = "waste") @RequestParam(required = false)
|
||||||
String targetClassCd,
|
String targetClassCd,
|
||||||
@Parameter(description = "도엽번호", example = "36713060") @RequestParam(required = false)
|
@Parameter(description = "도엽번호", example = "36713060") @RequestParam(required = false)
|
||||||
@@ -174,9 +150,7 @@ public class DatasetApiController {
|
|||||||
@RequestParam(defaultValue = "20") int size) {
|
@RequestParam(defaultValue = "20") int size) {
|
||||||
DatasetObjDto.SearchReq searchReq = new DatasetObjDto.SearchReq();
|
DatasetObjDto.SearchReq searchReq = new DatasetObjDto.SearchReq();
|
||||||
searchReq.setUuid(uuid);
|
searchReq.setUuid(uuid);
|
||||||
searchReq.setCompareYyyy(compareYyyy);
|
|
||||||
searchReq.setCompareClassCd(compareClassCd);
|
searchReq.setCompareClassCd(compareClassCd);
|
||||||
searchReq.setTargetYyyy(targetYyyy);
|
|
||||||
searchReq.setTargetClassCd(targetClassCd);
|
searchReq.setTargetClassCd(targetClassCd);
|
||||||
searchReq.setMapSheetNum(mapSheetNum);
|
searchReq.setMapSheetNum(mapSheetNum);
|
||||||
searchReq.setPage(page);
|
searchReq.setPage(page);
|
||||||
@@ -242,7 +216,7 @@ public class DatasetApiController {
|
|||||||
return ApiResponseDto.ok(datasetService.getUsableBytes());
|
return ApiResponseDto.ok(datasetService.getUsableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "데이터셋 등록", description = "데이터셋을 등록 합니다.")
|
@Operation(summary = "학습데이터 zip파일 등록", description = "학습데이터 zip파일 등록 합니다.")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ApiResponseDto<ApiResponseDto.ResponseObj> insertDataset(
|
public ApiResponseDto<ApiResponseDto.ResponseObj> insertDataset(
|
||||||
@RequestBody @Valid DatasetDto.AddReq addReq) {
|
@RequestBody @Valid DatasetDto.AddReq addReq) {
|
||||||
@@ -250,7 +224,7 @@ public class DatasetApiController {
|
|||||||
return ApiResponseDto.ok(datasetService.insertDataset(addReq));
|
return ApiResponseDto.ok(datasetService.insertDataset(addReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "파일 Path 조회", description = "파일 Path 조회")
|
@Operation(summary = "객체별 파일 Path 조회", description = "파일 Path 조회")
|
||||||
@GetMapping("/files")
|
@GetMapping("/files")
|
||||||
public ResponseEntity<Resource> getFile(@RequestParam UUID uuid, @RequestParam String pathType)
|
public ResponseEntity<Resource> getFile(@RequestParam UUID uuid, @RequestParam String pathType)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
@@ -313,24 +313,12 @@ public class DatasetDto {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class AddReq {
|
public static class AddReq {
|
||||||
private Long stage;
|
|
||||||
private String title;
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private Long fileSize;
|
private Long fileSize;
|
||||||
private String memo;
|
private String memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public static class DatasetFileDto {
|
|
||||||
private String fileName;
|
|
||||||
private String filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.kamco.cd.training.dataset.dto;
|
package com.kamco.cd.training.dataset.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.kamco.cd.training.common.enums.DetectionClassification;
|
import com.kamco.cd.training.common.enums.DetectionClassification;
|
||||||
import com.kamco.cd.training.common.utils.interfaces.JsonFormatDttm;
|
import com.kamco.cd.training.common.utils.interfaces.JsonFormatDttm;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
@@ -40,7 +43,8 @@ public class DatasetObjDto {
|
|||||||
private Long createdUid;
|
private Long createdUid;
|
||||||
private Boolean deleted;
|
private Boolean deleted;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private String geoJsonb;
|
@JsonIgnore private String geoJsonb;
|
||||||
|
private JsonNode geoJson;
|
||||||
|
|
||||||
public Basic(
|
public Basic(
|
||||||
Long objId,
|
Long objId,
|
||||||
@@ -75,6 +79,18 @@ public class DatasetObjDto {
|
|||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.geoJsonb = geoJsonb;
|
this.geoJsonb = geoJsonb;
|
||||||
|
|
||||||
|
JsonNode geoJsonNode = null;
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
if (geoJsonb != null) {
|
||||||
|
try {
|
||||||
|
geoJsonNode = mapper.readTree(geoJsonb);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.geoJson = geoJsonNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,18 +100,12 @@ public class DatasetObjDto {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class SearchReq {
|
public static class SearchReq {
|
||||||
@Schema(description = "회차 uuid", example = "35e20bb2-9014-4c9d-abe2-9046db5f930c")
|
@Schema(description = "회차 uuid", example = "e9a6774b-4f81-4402-b080-51d27fac1f01")
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
@Schema(description = "비교년도", example = "2021")
|
|
||||||
private Integer compareYyyy;
|
|
||||||
|
|
||||||
@Schema(description = "비교년도분류", example = "waste")
|
@Schema(description = "비교년도분류", example = "waste")
|
||||||
private String compareClassCd;
|
private String compareClassCd;
|
||||||
|
|
||||||
@Schema(description = "기준년도", example = "2022")
|
|
||||||
private Integer targetYyyy;
|
|
||||||
|
|
||||||
@Schema(description = "기준년도분류", example = "land")
|
@Schema(description = "기준년도분류", example = "land")
|
||||||
private String targetClassCd;
|
private String targetClassCd;
|
||||||
|
|
||||||
@@ -145,6 +155,7 @@ public class DatasetObjDto {
|
|||||||
private String comparePath;
|
private String comparePath;
|
||||||
private String targetPath;
|
private String targetPath;
|
||||||
private String labelPath;
|
private String labelPath;
|
||||||
|
private String geojsonPath;
|
||||||
private String mapSheetNum;
|
private String mapSheetNum;
|
||||||
private JsonNode geojson;
|
private JsonNode geojson;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.kamco.cd.training.dataset.service;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.kamco.cd.training.common.enums.LearnDataType;
|
import com.kamco.cd.training.common.enums.LearnDataType;
|
||||||
import com.kamco.cd.training.common.exception.CustomApiException;
|
import com.kamco.cd.training.common.exception.CustomApiException;
|
||||||
import com.kamco.cd.training.common.service.FormatStorage;
|
import com.kamco.cd.training.common.service.FormatStorage;
|
||||||
@@ -156,9 +158,10 @@ public class DatasetService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public ResponseObj insertDataset(@Valid AddReq addReq) {
|
public ResponseObj insertDataset(@Valid AddReq addReq) {
|
||||||
|
|
||||||
Long datasetUid = 0L; // master id 값, 등록하면서 가져올 예정
|
Long datasetUid = null; // master id 값, 등록하면서 가져올 예정
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 압축 해제
|
// 압축 해제
|
||||||
@@ -166,86 +169,135 @@ public class DatasetService {
|
|||||||
|
|
||||||
// 해제한 폴더 읽어서 데이터 저장
|
// 해제한 폴더 읽어서 데이터 저장
|
||||||
List<Map<String, Object>> list =
|
List<Map<String, Object>> list =
|
||||||
getUnzipDatasetFiles(addReq.getFilePath() + addReq.getFileName().replace(".zip", ""));
|
getUnzipDatasetFiles(
|
||||||
|
addReq.getFilePath() + addReq.getFileName().replace(".zip", ""), "train");
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (Map<String, Object> map : list) {
|
for (Map<String, Object> map : list) {
|
||||||
String comparePath = (String) map.get("input1");
|
datasetUid =
|
||||||
String targetPath = (String) map.get("input2");
|
this.insertTrainTestData(map, addReq, idx, datasetUid, "train"); // train 데이터 insert
|
||||||
String labelPath = (String) map.get("label");
|
|
||||||
JsonNode json = (JsonNode) map.get("label-json");
|
|
||||||
|
|
||||||
String fileName = Paths.get(comparePath).getFileName().toString();
|
|
||||||
String[] fileNameStr = fileName.split("_");
|
|
||||||
String compareYyyy = fileNameStr[1];
|
|
||||||
String targetYyyy = fileNameStr[2];
|
|
||||||
String mapSheetNum = fileNameStr[3];
|
|
||||||
|
|
||||||
if (idx == 0) {
|
|
||||||
String title = compareYyyy + "-" + targetYyyy;
|
|
||||||
String dataType = LearnDataType.PRODUCTION.getId(); // 만들어 넣는 건 다 제작
|
|
||||||
Long stage =
|
|
||||||
datasetCoreService.getDatasetMaxStage(
|
|
||||||
Integer.parseInt(compareYyyy), Integer.parseInt(targetYyyy))
|
|
||||||
+ 1;
|
|
||||||
String uid = Paths.get(addReq.getFilePath()).getParent().getFileName().toString();
|
|
||||||
|
|
||||||
DatasetMngRegDto mngRegDto =
|
|
||||||
DatasetMngRegDto.builder()
|
|
||||||
.uid(uid)
|
|
||||||
.dataType(dataType)
|
|
||||||
.compareYyyy(Integer.parseInt(compareYyyy))
|
|
||||||
.targetYyyy(Integer.parseInt(targetYyyy))
|
|
||||||
.title(title)
|
|
||||||
.memo(addReq.getMemo())
|
|
||||||
.roundNo(stage)
|
|
||||||
.totalSize(addReq.getFileSize())
|
|
||||||
.datasetPath(addReq.getFilePath())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
datasetUid = datasetCoreService.insertDatasetMngData(mngRegDto); // tb_dataset 에 insert
|
|
||||||
}
|
|
||||||
|
|
||||||
// datasetUid 로 obj 도 등록하기
|
|
||||||
// Json 갯수만큼 for문 돌려서 insert 해야 함
|
|
||||||
for (JsonNode feature : json.path("features")) {
|
|
||||||
JsonNode prop = feature.path("properties");
|
|
||||||
String compareClassCd = prop.path("before").asText(null);
|
|
||||||
String targetClassCd = prop.path("after").asText(null);
|
|
||||||
|
|
||||||
DatasetObjRegDto objRegDto =
|
|
||||||
DatasetObjRegDto.builder()
|
|
||||||
.datasetUid(datasetUid)
|
|
||||||
.compareYyyy(Integer.parseInt(compareYyyy))
|
|
||||||
.compareClassCd(compareClassCd)
|
|
||||||
.targetYyyy(Integer.parseInt(targetYyyy))
|
|
||||||
.targetClassCd(targetClassCd)
|
|
||||||
.comparePath(comparePath)
|
|
||||||
.targetPath(targetPath)
|
|
||||||
.labelPath(labelPath)
|
|
||||||
.mapSheetNum(mapSheetNum)
|
|
||||||
.geojson(feature)
|
|
||||||
.fileName(fileName)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
datasetCoreService.insertDatasetObj(objRegDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> testList =
|
||||||
|
getUnzipDatasetFiles(
|
||||||
|
addReq.getFilePath() + addReq.getFileName().replace(".zip", ""), "test");
|
||||||
|
|
||||||
|
int testIdx = 0;
|
||||||
|
for (Map<String, Object> test : testList) {
|
||||||
|
datasetUid =
|
||||||
|
this.insertTrainTestData(test, addReq, testIdx, datasetUid, "test"); // test 데이터 insert
|
||||||
|
testIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return new ResponseObj(ApiResponseCode.INTERNAL_SERVER_ERROR, e.getMessage());
|
return new ResponseObj(ApiResponseCode.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datasetCoreService.updateDatasetUploadStatus(datasetUid);
|
||||||
return new ResponseObj(ApiResponseCode.OK, "업로드 성공하였습니다.");
|
return new ResponseObj(ApiResponseCode.OK, "업로드 성공하였습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, Object>> getUnzipDatasetFiles(String unzipRootPath) {
|
@Transactional
|
||||||
|
public Long insertTrainTestData(
|
||||||
|
Map<String, Object> map, AddReq addReq, int idx, Long datasetUid, String subDir) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String comparePath = (String) map.get("input1");
|
||||||
|
String targetPath = (String) map.get("input2");
|
||||||
|
String labelPath = (String) map.get("label");
|
||||||
|
String geojsonPath = (String) map.get("geojson_path");
|
||||||
|
Object labelJson = map.get("label-json");
|
||||||
|
JsonNode json;
|
||||||
|
|
||||||
Path root = Paths.get(unzipRootPath).resolve("train");
|
if (labelJson instanceof JsonNode jn) {
|
||||||
|
json = jn;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
json = mapper.readTree(labelJson.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("label_json parse error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = Paths.get(comparePath).getFileName().toString();
|
||||||
|
String[] fileNameStr = fileName.split("_");
|
||||||
|
String compareYyyy = fileNameStr[1];
|
||||||
|
String targetYyyy = fileNameStr[2];
|
||||||
|
String mapSheetNum = fileNameStr[3];
|
||||||
|
|
||||||
|
if (idx == 0 && subDir.equals("train")) {
|
||||||
|
String title = compareYyyy + "-" + targetYyyy; // 제목 : 비교년도-기준년도
|
||||||
|
String dataType = LearnDataType.PRODUCTION.getId(); // 만들어 넣는 건 다 제작
|
||||||
|
Long stage =
|
||||||
|
datasetCoreService.getDatasetMaxStage(
|
||||||
|
Integer.parseInt(compareYyyy), Integer.parseInt(targetYyyy))
|
||||||
|
+ 1;
|
||||||
|
String uid = addReq.getFileName().replace(".zip", "");
|
||||||
|
|
||||||
|
DatasetMngRegDto mngRegDto =
|
||||||
|
DatasetMngRegDto.builder()
|
||||||
|
.uid(uid)
|
||||||
|
.dataType(dataType)
|
||||||
|
.compareYyyy(Integer.parseInt(compareYyyy))
|
||||||
|
.targetYyyy(Integer.parseInt(targetYyyy))
|
||||||
|
.title(title)
|
||||||
|
.memo(addReq.getMemo())
|
||||||
|
.roundNo(stage)
|
||||||
|
.totalSize(addReq.getFileSize())
|
||||||
|
.datasetPath(addReq.getFilePath())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
datasetUid = datasetCoreService.insertDatasetMngData(mngRegDto); // tb_dataset 에 insert
|
||||||
|
}
|
||||||
|
|
||||||
|
// datasetUid 로 obj 도 등록하기
|
||||||
|
// Json 갯수만큼 for문 돌려서 insert 해야 함, features에 빈값
|
||||||
|
if (json != null && json.path("features") != null && !json.path("features").isEmpty()) {
|
||||||
|
|
||||||
|
for (JsonNode feature : json.path("features")) {
|
||||||
|
JsonNode prop = feature.path("properties");
|
||||||
|
String compareClassCd = prop.path("before").asText(null);
|
||||||
|
String targetClassCd = prop.path("after").asText(null);
|
||||||
|
|
||||||
|
// 한 개씩 자른 geojson을 FeatureCollection 으로 만들어서 넣기
|
||||||
|
ObjectNode root = mapper.createObjectNode();
|
||||||
|
root.put("type", "FeatureCollection");
|
||||||
|
ArrayNode features = mapper.createArrayNode();
|
||||||
|
features.add(feature);
|
||||||
|
root.set("features", features);
|
||||||
|
|
||||||
|
DatasetObjRegDto objRegDto =
|
||||||
|
DatasetObjRegDto.builder()
|
||||||
|
.datasetUid(datasetUid)
|
||||||
|
.compareYyyy(Integer.parseInt(compareYyyy))
|
||||||
|
.compareClassCd(compareClassCd)
|
||||||
|
.targetYyyy(Integer.parseInt(targetYyyy))
|
||||||
|
.targetClassCd(targetClassCd)
|
||||||
|
.comparePath(comparePath)
|
||||||
|
.targetPath(targetPath)
|
||||||
|
.labelPath(labelPath)
|
||||||
|
.mapSheetNum(mapSheetNum)
|
||||||
|
.geojson(root)
|
||||||
|
.geojsonPath(geojsonPath)
|
||||||
|
.fileName(fileName)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
if (subDir.equals("train")) {
|
||||||
|
datasetCoreService.insertDatasetObj(objRegDto);
|
||||||
|
} else {
|
||||||
|
datasetCoreService.insertDatasetTestObj(objRegDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return datasetUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> getUnzipDatasetFiles(String unzipRootPath, String subDir) {
|
||||||
|
|
||||||
|
Path root = Paths.get(unzipRootPath).resolve(subDir);
|
||||||
Map<String, Map<String, Object>> grouped = new HashMap<>();
|
Map<String, Map<String, Object>> grouped = new HashMap<>();
|
||||||
long total_file_cnt = 0;
|
|
||||||
|
|
||||||
for (String dirName : LABEL_DIRS) {
|
for (String dirName : LABEL_DIRS) {
|
||||||
Path dir = root.resolve(dirName);
|
Path dir = root.resolve(dirName);
|
||||||
@@ -254,15 +306,6 @@ public class DatasetService {
|
|||||||
throw new IllegalStateException("폴더가 존재하지 않습니다 : " + dir);
|
throw new IllegalStateException("폴더가 존재하지 않습니다 : " + dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 파일 갯수는 같아서 비교년도일 때만 file_cnt 를 가지고 오기
|
|
||||||
// if(dirName.equals("input1")){
|
|
||||||
// try (Stream<Path> stream = Files.list(dir)) {
|
|
||||||
// total_file_cnt = stream.filter(Files::isRegularFile).count();
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
try (Stream<Path> stream = Files.list(dir)) {
|
try (Stream<Path> stream = Files.list(dir)) {
|
||||||
stream
|
stream
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
@@ -282,8 +325,8 @@ public class DatasetService {
|
|||||||
if ("label-json".equals(dirName)) {
|
if ("label-json".equals(dirName)) {
|
||||||
// json 파일이면 파싱
|
// json 파일이면 파싱
|
||||||
data.put("label-json", readJson(path));
|
data.put("label-json", readJson(path));
|
||||||
|
data.put("geojson_path", path.toAbsolutePath().toString());
|
||||||
} else {
|
} else {
|
||||||
// 나머지는 경로 or 파일명
|
|
||||||
data.put(dirName, path.toAbsolutePath().toString());
|
data.put(dirName, path.toAbsolutePath().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -229,4 +229,17 @@ public class DatasetCoreService
|
|||||||
public String getFilePathByUUIDPathType(UUID uuid, String pathType) {
|
public String getFilePathByUUIDPathType(UUID uuid, String pathType) {
|
||||||
return datasetObjRepository.getFilePathByUUIDPathType(uuid, pathType);
|
return datasetObjRepository.getFilePathByUUIDPathType(uuid, pathType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertDatasetTestObj(DatasetObjRegDto objRegDto) {
|
||||||
|
datasetObjRepository.insertDatasetTestObj(objRegDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDatasetUploadStatus(Long datasetUid) {
|
||||||
|
DatasetEntity entity =
|
||||||
|
datasetRepository
|
||||||
|
.findById(datasetUid)
|
||||||
|
.orElseThrow(() -> new NotFoundException("데이터셋을 찾을 수 없습니다. ID: " + datasetUid));
|
||||||
|
|
||||||
|
entity.setStatus(LearnDataRegister.COMPLETED.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -18,6 +17,7 @@ import lombok.Setter;
|
|||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
import org.hibernate.annotations.JdbcTypeCode;
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
import org.hibernate.type.SqlTypes;
|
import org.hibernate.type.SqlTypes;
|
||||||
|
import org.locationtech.jts.geom.Geometry;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -86,19 +86,16 @@ public class DatasetObjEntity {
|
|||||||
@Column(name = "uid")
|
@Column(name = "uid")
|
||||||
private String uid;
|
private String uid;
|
||||||
|
|
||||||
@Column(precision = 5, scale = 2)
|
|
||||||
private BigDecimal chnDtctP;
|
|
||||||
|
|
||||||
@Column(precision = 5, scale = 2)
|
|
||||||
private BigDecimal bfClsPro;
|
|
||||||
|
|
||||||
@Column(precision = 5, scale = 2)
|
|
||||||
private BigDecimal afClsPro;
|
|
||||||
|
|
||||||
@JdbcTypeCode(SqlTypes.JSON)
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
@Column(name = "geo_jsonb", columnDefinition = "jsonb")
|
@Column(name = "geo_jsonb", columnDefinition = "jsonb")
|
||||||
private String geoJsonb;
|
private String geoJsonb;
|
||||||
|
|
||||||
|
@Column(name = "file_name")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "geom", columnDefinition = "geometry")
|
||||||
|
private Geometry geom;
|
||||||
|
|
||||||
public Basic toDto() {
|
public Basic toDto() {
|
||||||
return new DatasetObjDto.Basic(
|
return new DatasetObjDto.Basic(
|
||||||
this.objId,
|
this.objId,
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package com.kamco.cd.training.postgres.entity;
|
||||||
|
|
||||||
|
import com.kamco.cd.training.dataset.dto.DatasetObjDto.Basic;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
|
import org.hibernate.type.SqlTypes;
|
||||||
|
import org.locationtech.jts.geom.Geometry;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "tb_dataset_test_obj")
|
||||||
|
public class DatasetTestObjEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "obj_id", nullable = false)
|
||||||
|
private Long objId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "dataset_uid", nullable = false)
|
||||||
|
private Long datasetUid;
|
||||||
|
|
||||||
|
@Column(name = "target_yyyy")
|
||||||
|
private Integer targetYyyy;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "target_class_cd")
|
||||||
|
private String targetClassCd;
|
||||||
|
|
||||||
|
@Column(name = "compare_yyyy")
|
||||||
|
private Integer compareYyyy;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "compare_class_cd")
|
||||||
|
private String compareClassCd;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "target_path")
|
||||||
|
private String targetPath;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "compare_path")
|
||||||
|
private String comparePath;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "label_path")
|
||||||
|
private String labelPath;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "geojson_path")
|
||||||
|
private String geojsonPath;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "map_sheet_num")
|
||||||
|
private String mapSheetNum;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_dttm")
|
||||||
|
private ZonedDateTime createdDttm;
|
||||||
|
|
||||||
|
@Column(name = "created_uid")
|
||||||
|
private Long createdUid;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "deleted")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "uuid")
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
@Size(max = 32)
|
||||||
|
@Column(name = "uid")
|
||||||
|
private String uid;
|
||||||
|
|
||||||
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
|
@Column(name = "geo_jsonb", columnDefinition = "jsonb")
|
||||||
|
private String geoJsonb;
|
||||||
|
|
||||||
|
@Column(name = "file_name")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "geom", columnDefinition = "geometry")
|
||||||
|
private Geometry geom;
|
||||||
|
|
||||||
|
public Basic toDto() {
|
||||||
|
return new Basic(
|
||||||
|
this.objId,
|
||||||
|
this.datasetUid,
|
||||||
|
this.targetYyyy,
|
||||||
|
this.targetClassCd,
|
||||||
|
this.compareYyyy,
|
||||||
|
this.compareClassCd,
|
||||||
|
this.targetPath,
|
||||||
|
this.comparePath,
|
||||||
|
this.labelPath,
|
||||||
|
this.geojsonPath,
|
||||||
|
this.mapSheetNum,
|
||||||
|
this.createdDttm,
|
||||||
|
this.createdUid,
|
||||||
|
this.deleted,
|
||||||
|
this.uuid,
|
||||||
|
this.geoJsonb);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,4 +20,6 @@ public interface DatasetObjRepositoryCustom {
|
|||||||
void insertDatasetObj(DatasetObjRegDto objRegDto);
|
void insertDatasetObj(DatasetObjRegDto objRegDto);
|
||||||
|
|
||||||
String getFilePathByUUIDPathType(UUID uuid, String pathType);
|
String getFilePathByUUIDPathType(UUID uuid, String pathType);
|
||||||
|
|
||||||
|
void insertDatasetTestObj(DatasetObjRegDto objRegDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,15 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.locationtech.jts.geom.Geometry;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Repository
|
@Repository
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DatasetObjRepositoryImpl implements DatasetObjRepositoryCustom {
|
public class DatasetObjRepositoryImpl implements DatasetObjRepositoryCustom {
|
||||||
@@ -50,17 +53,55 @@ public class DatasetObjRepositoryImpl implements DatasetObjRepositoryCustom {
|
|||||||
.fetchOne());
|
.fetchOne());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertDatasetTestObj(DatasetObjRegDto objRegDto) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String json;
|
||||||
|
Geometry geometry;
|
||||||
|
String geometryJson;
|
||||||
|
try {
|
||||||
|
json = objectMapper.writeValueAsString(objRegDto.getGeojson());
|
||||||
|
geometryJson =
|
||||||
|
objectMapper.writeValueAsString(
|
||||||
|
objRegDto.getGeojson().path("features").get(0).path("geometry"));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
em.createNativeQuery(
|
||||||
|
"""
|
||||||
|
insert into tb_dataset_test_obj
|
||||||
|
(dataset_uid, target_yyyy, target_class_cd,
|
||||||
|
compare_yyyy, compare_class_cd,
|
||||||
|
target_path, compare_path, label_path, geo_jsonb, map_sheet_num, file_name, geom, geojson_path)
|
||||||
|
values
|
||||||
|
(?, ?, ?, ?, ?, ?, ?, ?, cast(? as jsonb), ?, ?, ST_SetSRID(ST_GeomFromGeoJSON(?), 5186), ?)
|
||||||
|
""")
|
||||||
|
.setParameter(1, objRegDto.getDatasetUid())
|
||||||
|
.setParameter(2, objRegDto.getTargetYyyy())
|
||||||
|
.setParameter(3, objRegDto.getTargetClassCd())
|
||||||
|
.setParameter(4, objRegDto.getCompareYyyy())
|
||||||
|
.setParameter(5, objRegDto.getCompareClassCd())
|
||||||
|
.setParameter(6, objRegDto.getTargetPath())
|
||||||
|
.setParameter(7, objRegDto.getComparePath())
|
||||||
|
.setParameter(8, objRegDto.getLabelPath())
|
||||||
|
.setParameter(9, json)
|
||||||
|
.setParameter(10, objRegDto.getMapSheetNum())
|
||||||
|
.setParameter(11, objRegDto.getFileName())
|
||||||
|
.setParameter(12, geometryJson)
|
||||||
|
.setParameter(13, objRegDto.getGeojsonPath())
|
||||||
|
.executeUpdate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<DatasetObjEntity> searchDatasetObjectList(SearchReq searchReq) {
|
public Page<DatasetObjEntity> searchDatasetObjectList(SearchReq searchReq) {
|
||||||
Pageable pageable = searchReq.toPageable();
|
Pageable pageable = searchReq.toPageable();
|
||||||
BooleanBuilder builder = new BooleanBuilder();
|
BooleanBuilder builder = new BooleanBuilder();
|
||||||
|
|
||||||
if (searchReq.getCompareYyyy() != null) {
|
|
||||||
builder.and(datasetObjEntity.compareYyyy.eq(searchReq.getCompareYyyy()));
|
|
||||||
}
|
|
||||||
if (searchReq.getTargetYyyy() != null) {
|
|
||||||
builder.and(datasetObjEntity.targetYyyy.eq(searchReq.getTargetYyyy()));
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(searchReq.getCompareClassCd())) {
|
if (StringUtils.isNotBlank(searchReq.getCompareClassCd())) {
|
||||||
builder.and(datasetObjEntity.compareClassCd.eq(searchReq.getCompareClassCd()));
|
builder.and(datasetObjEntity.compareClassCd.eq(searchReq.getCompareClassCd()));
|
||||||
}
|
}
|
||||||
@@ -137,55 +178,43 @@ public class DatasetObjRepositoryImpl implements DatasetObjRepositoryCustom {
|
|||||||
public void insertDatasetObj(DatasetObjRegDto objRegDto) {
|
public void insertDatasetObj(DatasetObjRegDto objRegDto) {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String json;
|
String json;
|
||||||
|
String geometryJson;
|
||||||
try {
|
try {
|
||||||
json = objectMapper.writeValueAsString(objRegDto.getGeojson());
|
json = objectMapper.writeValueAsString(objRegDto.getGeojson());
|
||||||
|
geometryJson =
|
||||||
|
objectMapper.writeValueAsString(
|
||||||
|
objRegDto.getGeojson().path("features").get(0).path("geometry"));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
// queryFactory
|
|
||||||
// .insert(datasetObjEntity)
|
|
||||||
// .columns(
|
|
||||||
// datasetObjEntity.datasetUid,
|
|
||||||
// datasetObjEntity.targetYyyy,
|
|
||||||
// datasetObjEntity.targetClassCd,
|
|
||||||
// datasetObjEntity.compareYyyy,
|
|
||||||
// datasetObjEntity.compareClassCd,
|
|
||||||
// datasetObjEntity.targetPath,
|
|
||||||
// datasetObjEntity.comparePath,
|
|
||||||
// datasetObjEntity.labelPath,
|
|
||||||
// datasetObjEntity.geoJsonb)
|
|
||||||
// .values(
|
|
||||||
// objRegDto.getDatasetUid(),
|
|
||||||
// objRegDto.getTargetYyyy(),
|
|
||||||
// objRegDto.getTargetClassCd(),
|
|
||||||
// objRegDto.getCompareYyyy(),
|
|
||||||
// objRegDto.getCompareClassCd(),
|
|
||||||
// objRegDto.getTargetPath(),
|
|
||||||
// objRegDto.getComparePath(),
|
|
||||||
// objRegDto.getLabelPath(),
|
|
||||||
// Expressions.stringTemplate("cast({0} as jsonb)", json))
|
|
||||||
// .execute();
|
|
||||||
|
|
||||||
em.createNativeQuery(
|
try {
|
||||||
"""
|
em.createNativeQuery(
|
||||||
insert into tb_dataset_obj
|
"""
|
||||||
(dataset_uid, target_yyyy, target_class_cd,
|
insert into tb_dataset_obj
|
||||||
compare_yyyy, compare_class_cd,
|
(dataset_uid, target_yyyy, target_class_cd,
|
||||||
target_path, compare_path, label_path, geo_jsonb, map_sheet_num)
|
compare_yyyy, compare_class_cd,
|
||||||
values
|
target_path, compare_path, label_path, geo_jsonb, map_sheet_num, file_name, geom, geojson_path)
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?, cast(? as jsonb), ?)
|
values
|
||||||
""")
|
(?, ?, ?, ?, ?, ?, ?, ?, cast(? as jsonb), ?, ?, ST_SetSRID(ST_GeomFromGeoJSON(?), 5186), ?)
|
||||||
.setParameter(1, objRegDto.getDatasetUid())
|
""")
|
||||||
.setParameter(2, objRegDto.getTargetYyyy())
|
.setParameter(1, objRegDto.getDatasetUid())
|
||||||
.setParameter(3, objRegDto.getTargetClassCd())
|
.setParameter(2, objRegDto.getTargetYyyy())
|
||||||
.setParameter(4, objRegDto.getCompareYyyy())
|
.setParameter(3, objRegDto.getTargetClassCd())
|
||||||
.setParameter(5, objRegDto.getCompareClassCd())
|
.setParameter(4, objRegDto.getCompareYyyy())
|
||||||
.setParameter(6, objRegDto.getTargetPath())
|
.setParameter(5, objRegDto.getCompareClassCd())
|
||||||
.setParameter(7, objRegDto.getComparePath())
|
.setParameter(6, objRegDto.getTargetPath())
|
||||||
.setParameter(8, objRegDto.getLabelPath())
|
.setParameter(7, objRegDto.getComparePath())
|
||||||
.setParameter(9, json)
|
.setParameter(8, objRegDto.getLabelPath())
|
||||||
.setParameter(10, objRegDto.getMapSheetNum())
|
.setParameter(9, json)
|
||||||
.executeUpdate();
|
.setParameter(10, objRegDto.getMapSheetNum())
|
||||||
|
.setParameter(11, objRegDto.getFileName())
|
||||||
|
.setParameter(12, geometryJson)
|
||||||
|
.setParameter(13, objRegDto.getGeojsonPath())
|
||||||
|
.executeUpdate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -233,12 +233,10 @@ public class DatasetRepositoryImpl implements DatasetRepositoryCustom {
|
|||||||
mngRegDto.getDatasetPath())
|
mngRegDto.getDatasetPath())
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
Long datasetUid =
|
return queryFactory
|
||||||
queryFactory
|
.select(dataset.id)
|
||||||
.select(dataset.id)
|
.from(dataset)
|
||||||
.from(dataset)
|
.where(dataset.uid.eq(mngRegDto.getUid()))
|
||||||
.where(dataset.uid.eq(mngRegDto.getUid()))
|
.fetchOne();
|
||||||
.fetchOne();
|
|
||||||
return datasetUid;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user