-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Analysis): 취약점 분석 알고리즘 개선 (#75)
* Fix(Problem): 북마크 조회 시 카운트 쿼리와 내용 쿼리가 서로 다른 현상 수정 * Feat(Analysis): 취약점 분석 알고리즘 개선 - 기존에 N일 경과 시 1/(N+1)의 가중치를 부과하던 것에서, 경과일과 최근에 푼 순서에 따라 단기/중기/장기로 나눠 가중치 부과 * Test(Analysis): 변경된 알고리즘에 따른 테스트 코드 수정 * Feat(Analysis): ProblemSolvingAnalysisType 관련 코드를 직관적으로 이해하기 쉽도록 변경 및 주석 추가 - maxPeriod를 maxPeriodDay로 변경 - getLongestAnalysisType을 고정된 값으로 반환하도록 변경 * Feat(Analysis): 취약벡터 계산 시 이해하기 쉽도록 주석을 추가 * Test(Analysis): 경계값 테스트에 더 적합한 수치로 변경
- Loading branch information
Showing
7 changed files
with
259 additions
and
76 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
jabiseo-domain/src/main/java/com/jabiseo/analysis/domain/ProblemSolvingAnalysisType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.jabiseo.analysis.domain; | ||
|
||
import com.jabiseo.analysis.exception.AnalysisBusinessException; | ||
import com.jabiseo.analysis.exception.AnalysisErrorCode; | ||
import lombok.Getter; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
|
||
@Getter | ||
public enum ProblemSolvingAnalysisType { | ||
|
||
// maxPeriodDay가 커지면 maxCount도 증가해야 함 | ||
// 단기 분석 타입: 최근 14일 이내에 최대 200개의 문제 풀이에 가중치 0.5 적용 | ||
SHORT_TERM( 0.5, 14, 200), | ||
// 중기 분석 타입: 최근 30일 이내에 최대 300개의 문제 풀이에 가중치 0.3 적용 | ||
MID_TERM( 0.3, 30, 300), | ||
// 단기 분석 타입: 최근 90일 이내에 최대 500개의 문제 풀이에 가중치 0.2 적용 | ||
LONG_TERM( 0.2, 90, 500); | ||
|
||
final double weight; | ||
final int maxPeriodDay; | ||
final int maxCount; | ||
|
||
ProblemSolvingAnalysisType(double weight, int maxPeriodDay, int maxCount) { | ||
this.weight = weight; | ||
this.maxPeriodDay = maxPeriodDay; | ||
this.maxCount = maxCount; | ||
} | ||
|
||
public static ProblemSolvingAnalysisType getLongestPeriodAnalysisType() { | ||
return LONG_TERM; | ||
} | ||
|
||
// 푼 기간과 최근 푼 순서가 주어지면 그에 맞는 ProblemSolvingAnalysisType을 반환한다. | ||
public static ProblemSolvingAnalysisType fromPeriodAndCount(int period, int sequence) { | ||
return Arrays.stream(ProblemSolvingAnalysisType.values()) | ||
.sorted(Comparator.comparingInt(ProblemSolvingAnalysisType::getMaxPeriodDay)) | ||
.filter(type -> period <= type.getMaxPeriodDay() && sequence <= type.getMaxCount()) | ||
.findFirst() | ||
.orElseThrow(() -> new AnalysisBusinessException(AnalysisErrorCode.CANNOT_ANALYSE_PROBLEM_SOLVING)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
jabiseo-domain/src/test/java/com/jabiseo/analysis/domain/ProblemSolvingAnalysisTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.jabiseo.analysis.domain; | ||
|
||
import com.jabiseo.analysis.exception.AnalysisBusinessException; | ||
import com.jabiseo.analysis.exception.AnalysisErrorCode; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@DisplayName("ProblemSolvingAnalysisType 테스트") | ||
@ExtendWith(MockitoExtension.class) | ||
class ProblemSolvingAnalysisTypeTest { | ||
|
||
@DisplayName("기간과 문제 수에 따른 분석 타입을 반환한다.") | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"0, 0, SHORT_TERM", | ||
"13, 199, SHORT_TERM", | ||
"14, 200, SHORT_TERM", | ||
"30, 300, MID_TERM", | ||
"90, 500, LONG_TERM" | ||
}) | ||
void fromPeriodAndCount(int period, int count, ProblemSolvingAnalysisType expected) { | ||
// when | ||
ProblemSolvingAnalysisType actual = ProblemSolvingAnalysisType.fromPeriodAndCount(period, count); | ||
|
||
// then | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@DisplayName("기간과 문제 수가 올바르지 않을 경우 예외처리한다.") | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"91, 100", | ||
"89, 501", | ||
"91, 501" | ||
}) | ||
void fromPeriodAndCountWithDefault(int period, int count) { | ||
// when & then | ||
assertThatThrownBy(() -> ProblemSolvingAnalysisType.fromPeriodAndCount(period, count)) | ||
.isInstanceOf(AnalysisBusinessException.class) | ||
.hasFieldOrPropertyWithValue("errorCode", AnalysisErrorCode.CANNOT_ANALYSE_PROBLEM_SOLVING); | ||
} | ||
} |
Oops, something went wrong.