모델관리 목록 API 커밋
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMgmtRepository;
|
||||
import java.time.LocalDate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ModelMgmtCoreService {
|
||||
|
||||
private final ModelMgmtRepository modelMgmtRepository;
|
||||
|
||||
public Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||
ModelMgmtDto.searchReq searchReq,
|
||||
LocalDate startDate,
|
||||
LocalDate endDate,
|
||||
String modelType,
|
||||
String searchVal) {
|
||||
return modelMgmtRepository.findModelMgmtList(
|
||||
searchReq, startDate, endDate, modelType, searchVal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_class_count")
|
||||
public class ModelClassCountEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "count_uid")
|
||||
private Integer countUid;
|
||||
|
||||
@Column(name = "model_uid")
|
||||
private Integer modelUid;
|
||||
|
||||
@Column(name = "class_cd")
|
||||
private String classCd;
|
||||
|
||||
@Column(name = "obj_cnt")
|
||||
private Integer objCnt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_dataset_mapp")
|
||||
public class ModelDatasetMappEntity {
|
||||
|
||||
@EmbeddedId private ModelDatasetMappEntityId id;
|
||||
|
||||
@Column(name = "dataset_type")
|
||||
private String datasetType;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Embeddable
|
||||
public class ModelDatasetMappEntityId implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Column(name = "model_uid", nullable = false)
|
||||
private Integer modelUid;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "dataset_uid", nullable = false)
|
||||
private Integer datasetUid;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||
return false;
|
||||
}
|
||||
ModelDatasetMappEntityId entity = (ModelDatasetMappEntityId) o;
|
||||
return Objects.equals(this.modelUid, entity.modelUid)
|
||||
&& Objects.equals(this.datasetUid, entity.datasetUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(modelUid, modelUid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_hyper_param")
|
||||
public class ModelHyperParamEntity {
|
||||
@Id
|
||||
@Column(name = "hyper_ver")
|
||||
private String hyperVer;
|
||||
|
||||
@Column(name = "learning_rate")
|
||||
private Double learningRate;
|
||||
|
||||
@Column(name = "batch_size")
|
||||
private Integer batchSize;
|
||||
|
||||
@Column(name = "dropout_ratio")
|
||||
private Double dropoutRatio;
|
||||
|
||||
@Column(name = "cnn_filter_cnt")
|
||||
private Integer cnnFilterCnt;
|
||||
|
||||
@Column(name = "memo", columnDefinition = "TEXT")
|
||||
private String memo;
|
||||
|
||||
@Column(name = "del_yn")
|
||||
private Character delYn;
|
||||
|
||||
@Column(name = "created_dttm")
|
||||
private ZonedDateTime createdDttm;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_mgmt")
|
||||
public class ModelMgmtEntity extends CommonDateEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "model_uid")
|
||||
private Integer modelUid;
|
||||
|
||||
@Column(name = "model_ver")
|
||||
private String modelVer;
|
||||
|
||||
@Column(name = "hyper_ver")
|
||||
private String hyperVer;
|
||||
|
||||
@Column(name = "epoch_ver")
|
||||
private String epochVer;
|
||||
|
||||
@Column(name = "docker_file_nm")
|
||||
private String dockerFileNm;
|
||||
|
||||
@Column(name = "create_complete_dttm")
|
||||
private ZonedDateTime createCompleteDttm;
|
||||
|
||||
@Column(name = "recent_use_dttm")
|
||||
private ZonedDateTime recentUseDttm;
|
||||
|
||||
@Column(name = "deleted")
|
||||
private Boolean deleted;
|
||||
|
||||
@Column(name = "created_uid")
|
||||
private Long createdUid;
|
||||
|
||||
@Column(name = "updated_uid")
|
||||
private Long updatedUid;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_model_train_master")
|
||||
public class ModelTrainMasterEntity extends CommonDateEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "model_uid", nullable = false)
|
||||
private Integer modelUid;
|
||||
|
||||
@Column(name = "model_ver")
|
||||
private String modelVer;
|
||||
|
||||
@Column(name = "hyper_ver")
|
||||
private String hyperVer;
|
||||
|
||||
@Column(name = "epoch_ver")
|
||||
private String epochVer;
|
||||
|
||||
@Column(name = "process_step")
|
||||
private String processStep;
|
||||
|
||||
@Column(name = "status_cd")
|
||||
private String statsusCd;
|
||||
|
||||
@Column(name = "train_start_dttm")
|
||||
private ZonedDateTime trainStartDttm;
|
||||
|
||||
@Column(name = "epoch_cnt")
|
||||
private Integer epochCnt;
|
||||
|
||||
@Column(name = "dataset_ratio")
|
||||
private String datasetRatio;
|
||||
|
||||
@Column(name = "best_epoch")
|
||||
private Integer bestEpoch;
|
||||
|
||||
@Column(name = "step1_end_dttm")
|
||||
private ZonedDateTime step1EndDttm;
|
||||
|
||||
@Column(name = "step1_duration")
|
||||
private String step1Duration;
|
||||
|
||||
@Column(name = "step2_end_dttm")
|
||||
private ZonedDateTime step2EndDttm;
|
||||
|
||||
@Column(name = "step2_duration")
|
||||
private String step2Duration;
|
||||
|
||||
@Column(name = "del_yn")
|
||||
private Character delYn;
|
||||
|
||||
@Column(name = "created_uid")
|
||||
private Long createdUid;
|
||||
|
||||
@Column(name = "updated_uid")
|
||||
private Long updatedUid;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMgmtEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ModelMgmtRepository
|
||||
extends JpaRepository<ModelMgmtEntity, Integer>, ModelMgmtRepositoryCustom {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||
import java.time.LocalDate;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface ModelMgmtRepositoryCustom {
|
||||
|
||||
Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||
ModelMgmtDto.searchReq searchReq,
|
||||
LocalDate startDate,
|
||||
LocalDate endDate,
|
||||
String modelType,
|
||||
String searchVal);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||
import com.kamco.cd.kamcoback.postgres.QuerydslOrderUtil;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.ModelMgmtEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.StringExpression;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelMgmtEntity.modelMgmtEntity;
|
||||
|
||||
public class ModelMgmtRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements ModelMgmtRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
|
||||
|
||||
public ModelMgmtRepositoryImpl(JPAQueryFactory queryFactory) {
|
||||
super(ModelMgmtEntity.class);
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||
ModelMgmtDto.searchReq searchReq,
|
||||
LocalDate startDate,
|
||||
LocalDate endDate,
|
||||
String modelType,
|
||||
String searchVal) {
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
Sort sort = pageable.getSort();
|
||||
String property = "createCompleteDttm"; // 기본으로 생성완료일 기준
|
||||
|
||||
Map<String, Expression<?>> sortColumnMap =
|
||||
Map.of(
|
||||
"createCompleteDttm", modelMgmtEntity.createCompleteDttm,
|
||||
"recentUseDttm", modelMgmtEntity.recentUseDttm);
|
||||
|
||||
if (sort.isSorted()) {
|
||||
Sort.Order order = sort.iterator().next();
|
||||
property = order.getProperty();
|
||||
}
|
||||
|
||||
Expression<?> sortColumn = sortColumnMap.get(property);
|
||||
|
||||
List<ModelMgmtDto.ModelList> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
ModelMgmtDto.ModelList.class,
|
||||
Expressions.numberTemplate(
|
||||
Integer.class, "row_number() over(order by {0} desc)", sortColumn),
|
||||
modelMgmtEntity.modelVer,
|
||||
modelMgmtEntity.dockerFileNm,
|
||||
modelMgmtEntity.modelVer.as("modelType"),
|
||||
Expressions.stringTemplate(
|
||||
"to_char({0}, 'YYYY-MM-DD')", modelMgmtEntity.createCompleteDttm),
|
||||
Expressions.stringTemplate(
|
||||
"to_char({0}, 'YYYY-MM-DD')", modelMgmtEntity.recentUseDttm),
|
||||
modelMgmtEntity.deleted))
|
||||
.from(modelMgmtEntity)
|
||||
.where(
|
||||
eventEndedAtBetween(startDate, endDate, property),
|
||||
searchModelVersion(modelType, searchVal))
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
.orderBy(
|
||||
QuerydslOrderUtil.getOrderSpecifiers(
|
||||
pageable, ModelMgmtEntity.class, "modelMgmtEntity"))
|
||||
.fetch();
|
||||
|
||||
Long countQuery =
|
||||
queryFactory
|
||||
.select(modelMgmtEntity.modelUid.count())
|
||||
.from(modelMgmtEntity)
|
||||
.where(
|
||||
eventEndedAtBetween(startDate, endDate, property),
|
||||
searchModelVersion(modelType, searchVal))
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
private BooleanExpression eventEndedAtBetween(
|
||||
LocalDate startDate, LocalDate endDate, String sortColumn) {
|
||||
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
|
||||
return null;
|
||||
}
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
|
||||
|
||||
if (sortColumn.equals("createCompleteDttm")) {
|
||||
return modelMgmtEntity
|
||||
.createCompleteDttm
|
||||
.goe(startDateTime.atZone(zone))
|
||||
.and(modelMgmtEntity.createCompleteDttm.lt(endDateTime.atZone(zone)));
|
||||
} else {
|
||||
return modelMgmtEntity
|
||||
.recentUseDttm
|
||||
.goe(startDateTime.atZone(zone))
|
||||
.and(modelMgmtEntity.recentUseDttm.lt(endDateTime.atZone(zone)));
|
||||
}
|
||||
}
|
||||
|
||||
private BooleanBuilder searchModelVersion(String modelType, String searchVal) {
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
|
||||
if (Objects.nonNull(modelType)) {
|
||||
builder.and(modelMgmtEntity.modelVer.eq(modelType));
|
||||
}
|
||||
|
||||
if (Objects.nonNull(searchVal)) {
|
||||
builder.and(modelMgmtEntity.dockerFileNm.likeIgnoreCase("%" + searchVal + "%"));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user