Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TodayQuizService {
private final MailLogRepository mailLogRepository;
private final SesMailService mailService;

@Transactional
@Transactional(readOnly = true)
public Quiz getTodayQuizBySubscription(Subscription subscription) {
// 1. 구독자 정보 및 카테고리 조회
Long parentCategoryId = subscription.getCategory().getId(); // 대분류 ID
Expand All @@ -55,6 +55,10 @@ public Quiz getTodayQuizBySubscription(Subscription subscription) {
? QuizFormatType.SUBJECTIVE
: QuizFormatType.MULTIPLE_CHOICE;

QuizFormatType alterType = isEssayDay
? QuizFormatType.MULTIPLE_CHOICE
: QuizFormatType.SUBJECTIVE;

// 3. 정답률 기반 난이도 바운더리 설정
List<QuizLevel> allowedDifficulties = getAllowedDifficulties(accuracy);

Expand All @@ -64,7 +68,7 @@ public Quiz getTodayQuizBySubscription(Subscription subscription) {

// 7. 필터링 조건으로 문제 조회(대분류, 난이도, 내가푼문제 제외, 제외할 카테고리 제외하고, 문제 타입 전부 조건으로)

Quiz todayQuiz = quizRepository.findAvailableQuizzesUnderParentCategory(
/* Quiz todayQuiz = quizRepository.findAvailableQuizzesUnderParentCategory(
parentCategoryId,
allowedDifficulties,
sentQuizIds,
Expand All @@ -82,8 +86,17 @@ public Quiz getTodayQuizBySubscription(Subscription subscription) {
targetType,
0
);
}
}*/

int[] offsetsToTry = (offset > 0) ? new int[]{offset, 0} : new int[]{0};
QuizFormatType[] typesToTry = new QuizFormatType[]{targetType, alterType};

Quiz todayQuiz = tryFindQuiz(
parentCategoryId, allowedDifficulties, sentQuizIds, typesToTry, offsetsToTry
);

if (todayQuiz == null) {
log.info("subscription_id {} - 문제 출제 실패, targetType {}", subscriptionId, targetType);
throw new QuizException(QuizExceptionCode.QUIZ_VALIDATION_FAILED_ERROR);
}

Expand All @@ -103,6 +116,22 @@ private List<QuizLevel> getAllowedDifficulties(double accuracy) {
}
}

private Quiz tryFindQuiz(Long parentCategoryId,
List<QuizLevel> difficulties,
Set<Long> sentQuizIds,
QuizFormatType[] types,
int[] offsets) {
for (QuizFormatType type : types) {
for (int off : offsets) {
Quiz q = quizRepository.findAvailableQuizzesUnderParentCategory(
parentCategoryId, difficulties, sentQuizIds, type, off
);
if (q != null) return q;
}
}
return null;
}

// private double calculateAccuracy(List<UserQuizAnswer> answers) {
// if (answers.isEmpty()) {
// return 100.0;
Expand Down