File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
domain/src/main/kotlin/com/gotchai/domain/user/adapter/in Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,12 @@ class UserQueryService(
1616) : UserQueryUseCase {
1717 override fun getUserRanking (userId : Long ): GetUserRankingResult {
1818 val profile = profileQueryPort.getProfileByUserId(userId) ? : throw ProfileNotFoundException ()
19- val allHistories = examHistoryQueryPort.getAllExamHistoriesWithQuizIds()
19+ val allSolvedHistories =
20+ examHistoryQueryPort
21+ .getAllExamHistoriesWithQuizIds()
22+ .filter { it.isSolved }
2023
21- val rating = calculateUserRating(userId, allHistories )
24+ val rating = calculateUserRating(userId, allSolvedHistories )
2225 return GetUserRankingResult .of(profile, rating)
2326 }
2427
@@ -38,10 +41,17 @@ class UserQueryService(
3841 }
3942
4043 val userScore = userScores[userId] ? : return 100
41- if (userScores.size == 1 ) return 0
44+ if (userScores.size == 1 ) return 1
4245
4346 val usersWithHigherScore = userScores.values.count { it > userScore }
44- val rating = (usersWithHigherScore.toDouble() / userScores.size.toDouble()) * 100
45- return ceil(rating).toInt()
47+
48+ return when {
49+ usersWithHigherScore == 0 && userScores.values.all { it == userScore } -> 50
50+ usersWithHigherScore == 0 -> 1
51+ else -> {
52+ val rating = (usersWithHigherScore.toDouble() / userScores.size.toDouble()) * 100
53+ ceil(rating).toInt().coerceAtLeast(1 ) // 최소 1% 보장
54+ }
55+ }
4656 }
4757}
You can’t perform that action at this time.
0 commit comments