Added new setting for calculating group scores by adding user's scores#1041
Added new setting for calculating group scores by adding user's scores#1041SzBeni2003 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a server-side boolean setting ChangesGROUP Leaderboard USER-Ownership Contribution
Sequence DiagramssequenceDiagram
participant Recalc as LeaderBoardService.recalculate()
participant UserCache as forceRecalculateForUsers()
participant UserMap as userIdToGroup_mapping
participant TaskAgg as Task_aggregation
participant RiddleAgg as Riddle_aggregation
participant ChallengeAgg as Challenge_aggregation
participant TokenAgg as Token_aggregation
participant GroupCache as forceRecalculateForGroups() / Group cache
Recalc->>UserCache: recompute user cache
Recalc->>UserMap: build userIdToGroup lookup
Recalc->>TaskAgg: aggregate USER-owned task scores (if enabled)
TaskAgg->>GroupCache: add task contributions by group
Recalc->>RiddleAgg: aggregate USER-owned riddle scores (if enabled)
RiddleAgg->>GroupCache: add riddle contributions by group
Recalc->>ChallengeAgg: aggregate USER-owned challenge scores (if enabled)
ChallengeAgg->>GroupCache: add challenge contributions by group
Recalc->>TokenAgg: aggregate USER-owned token scores (if enabled)
TokenAgg->>GroupCache: add token contributions and rarities by group
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt (1)
171-185: 💤 Low valueConsider avoiding
!!assertions by restructuring the filter.The
!!onit.key(lines 178-179) is safe here because the filter on line 175 ensures null keys are excluded. However, using non-null assertions is a code smell that bypasses compile-time null safety. A safer pattern would usefilterNotNull()on keys or restructure to make nullability explicit.Also, line 175 has inconsistent spacing:
it.key?.races?:falseshould beit.key?.races ?: falsefor consistency with line 199.♻️ Suggested improvement
OwnershipType.USER -> { if (leaderBoardComponent.addUserScoresForGroupScore) { taskSubmissions.map { it.findAll() }.orElse(mutableListOf()) .groupBy { userIdToGroup[it.userId ?: 0] } - .filter { it.key?.races?:false } - .map { - LeaderBoardAsGroupEntryDto( - it.key!!.id, - it.key!!.name, - taskScore = (it.value.sumOf { s -> s.score } * tasksPercent).toInt()) - } + .mapNotNull { (group, submissions) -> + group?.takeIf { it.races }?.let { + LeaderBoardAsGroupEntryDto( + it.id, + it.name, + taskScore = (submissions.sumOf { s -> s.score } * tasksPercent).toInt()) + } + } } else { listOf() } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt` around lines 171 - 185, In the OwnershipType.USER branch of LeaderBoardService (the addUserScoresForGroupScore path), avoid using the non-null assertion on it.key by filtering entries with non-null keys and races first (e.g., use filter { (k, _) -> k?.races == true } or mapNotNull { (k, v) -> if (k?.races == true) LeaderBoardAsGroupEntryDto(k.id, k.name, taskScore = (v.sumOf { s -> s.score } * tasksPercent).toInt()) else null } ), and update the ternary spacing to "k?.races ?: false" for consistency; keep references to taskSubmissions.map { it.findAll() }.orElse(...), groupBy, and LeaderBoardAsGroupEntryDto when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt`:
- Around line 286-316: The GROUP ownership branch in forceRecalculateForGroups
(OwnershipType.GROUP) currently groups tokenSubmissions by ownerGroup without
excluding non-racing groups; mirror the USER branch behavior by inserting a
filter after tokenSubmissions.groupBy { it.ownerGroup } to only keep entries
where it.key?.races ?: false, then proceed to map/sum tokenScore and build
LeaderBoardAsGroupEntryDto as done in the USER branch; update the grouping chain
that starts with tokenSubmissions.map { it.findAll()
}.orElse(mutableListOf()).groupBy { it.ownerGroup } to include .filter {
it.key?.races ?: false } before mapping.
---
Nitpick comments:
In
`@backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt`:
- Around line 171-185: In the OwnershipType.USER branch of LeaderBoardService
(the addUserScoresForGroupScore path), avoid using the non-null assertion on
it.key by filtering entries with non-null keys and races first (e.g., use filter
{ (k, _) -> k?.races == true } or mapNotNull { (k, v) -> if (k?.races == true)
LeaderBoardAsGroupEntryDto(k.id, k.name, taskScore = (v.sumOf { s -> s.score } *
tasksPercent).toInt()) else null } ), and update the ternary spacing to
"k?.races ?: false" for consistency; keep references to taskSubmissions.map {
it.findAll() }.orElse(...), groupBy, and LeaderBoardAsGroupEntryDto when making
the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5a8a7826-a93d-4625-b2b9-c5723f218d5e
📒 Files selected for processing (2)
backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardComponent.ktbackend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt
Summary by CodeRabbit