Skip to content

Commit

Permalink
[#51] fix : 점수 분석모델 사용 API 수정
Browse files Browse the repository at this point in the history
- 점수가 없는 히스토리는 노출하지 않도록 했습니다.
- 음정 분석점수와 유사도 분석 점수를 구분했습니다.
  • Loading branch information
JakePark929 committed Aug 1, 2024
1 parent 15a7149 commit 72f85a9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public ModelScore toEntity(User userEntity, Song songEntity, String recordedFile

public ModelScoreResponse toResponse(String recordedFilename, ScoreResult scoreResult) {
final Integer score = ConvertUtils.stringToInteger(scoreResult.getNormalizedScore());
final Double similarity = ConvertUtils.stringToDouble(scoreResult.getCombinedSimilarity());
final Double tune = ConvertUtils.stringToDouble(scoreResult.getMeanChromaSimilarity());
final Double similarity = ConvertUtils.stringToDouble(scoreResult.getMeanMfccSimilarity());

return ModelScoreResponse.of(recordedFilename, score, similarity);
return ModelScoreResponse.of(recordedFilename, score, tune, similarity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ModelScoreListResponse {
private Long id;
private SongDto song;
private Integer score;
private Double tune;
private Double similarity;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
Expand All @@ -22,6 +23,7 @@ public static ModelScoreListResponse of(
Long id,
SongDto song,
Integer score,
Double tune,
Double similarity,
LocalDateTime createdAt,
LocalDateTime updatedAt
Expand All @@ -30,6 +32,7 @@ public static ModelScoreListResponse of(
id,
song,
score,
tune,
similarity,
createdAt,
updatedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
public class ModelScoreResponse {
String recordedFilename;
Integer score;
Double tune;
Double similarity;

public static ModelScoreResponse of(String recordedFilename, Integer score, Double similarity) {
public static ModelScoreResponse of(String recordedFilename, Integer score, Double tune, Double similarity) {

return new ModelScoreResponse(
recordedFilename,
score,
tune,
similarity
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<ModelScoreListResponse> getScoreList(UserDto userDto) {
User userEntity = userRepository.findFirstByIdAndStatusOrderByIdDesc(userDto.getId(), UserStatus.ACTIVE)
.orElseThrow(() -> new CoreApiException(ErrorType.USER_NOT_FOUND));

final List<ModelScoreProjection> projections = modelScoreRepository.findAllByUserOrderByCreatedAtDesc(userEntity);
final List<ModelScoreProjection> projections = modelScoreRepository.findAllByUserAndScoreIsNotNullOrderByCreatedAtDesc(userEntity);

return projections.stream().map(projection -> {
SongProjection song = projection.getSong();
Expand All @@ -46,6 +46,7 @@ public List<ModelScoreListResponse> getScoreList(UserDto userDto) {
projection.getId(),
SongDto.of(song.getId(), song.getTitle(), song.getArtist(), song.getAlbumPictureUrl()),
projection.getScore(),
projection.getTune(),
projection.getSimilarity(),
projection.getCreatedAt(),
projection.getUpdatedAt()
Expand All @@ -70,12 +71,13 @@ public Long saveRecord(UserDto userDto, Long songId, String recordedFilename) {
@Transactional
public void saveScore(Long modelScoreId, ScoreResult scoreResult, long analysisTime) {
final Integer score = ConvertUtils.stringToInteger(scoreResult.getNormalizedScore());
final Double similarity = ConvertUtils.stringToDouble(scoreResult.getCombinedSimilarity());
final Double tune = ConvertUtils.stringToDouble(scoreResult.getMeanChromaSimilarity());
final Double similarity = ConvertUtils.stringToDouble(scoreResult.getMeanMfccSimilarity());

final ModelScore entity = modelScoreRepository.findById(modelScoreId)
.orElseThrow(() -> new CoreApiException(ErrorType.NOT_FOUND));

entity.applyUpdates(score, similarity, analysisTime);
entity.applyUpdates(score, tune, similarity, analysisTime);

modelScoreRepository.save(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,35 @@ public class ModelScore extends BaseEntity {
@Comment("분석 대상 이름")
private String recordedFilename;

@Comment("분석 점수")
@Comment(" 점수")
private Integer score;

@Comment("분석 유사도")
@Comment("음정 분석치")
private Double tune;

@Comment("유사도 분석치")
private Double similarity;

@Comment("분석 소요 시간")
private long analysisTime;

@Builder
public ModelScore(User user, Song song, String recordedFilename, Integer score, Double similarity, long analysisTime) {
public ModelScore(User user, Song song, String recordedFilename, Integer score, Double tune, Double similarity, long analysisTime) {
this.user = user;
this.song = song;
this.recordedFilename = recordedFilename;
this.score = score;
this.tune = tune;
this.similarity = similarity;
this.analysisTime = analysisTime;
}

public void updateScore(Integer score) {
this.score = score;
}
public void updateTune(Double tune) {
this.tune = tune;
}

public void updateSimilarity(Double similarity) {
this.similarity = similarity;
Expand All @@ -68,11 +75,15 @@ public void updateAnalysisTime(long analysisTime) {
this.analysisTime = analysisTime;
}

public void applyUpdates(Integer score, Double similarity, long analysisTime) {
public void applyUpdates(Integer score, Double tune, Double similarity, long analysisTime) {
if (!ObjectUtils.isEmpty(score)) {
updateScore(score);
}

if (!ObjectUtils.isEmpty(tune)) {
updateTune(tune);
}

if (!ObjectUtils.isEmpty(similarity)) {
updateSimilarity(similarity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
public interface ModelScoreProjection extends BaseProjection {
SongProjection getSong();
Integer getScore();
Double getTune();
Double getSimilarity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import java.util.List;

public interface ModelScoreRepository extends JpaRepository<ModelScore, Long> {
List<ModelScoreProjection> findAllByUserOrderByCreatedAtDesc(User userEntity);
List<ModelScoreProjection> findAllByUserAndScoreIsNotNullOrderByCreatedAtDesc(User userEntity);
}

0 comments on commit 72f85a9

Please sign in to comment.