Skip to content

Added new setting for calculating group scores by adding user's scores#1041

Open
SzBeni2003 wants to merge 2 commits into
stagingfrom
feature/team-leaderboard-with-user-tasks
Open

Added new setting for calculating group scores by adding user's scores#1041
SzBeni2003 wants to merge 2 commits into
stagingfrom
feature/team-leaderboard-with-user-tasks

Conversation

@SzBeni2003

@SzBeni2003 SzBeni2003 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added a server-side setting to include individual user points in group leaderboard calculations; when enabled, user-owned tasks, riddles, challenges and tokens contribute to group scores.
    • Group score recalculation now aggregates user contributions and (when enabled) updates per-rarity token counts visible in group leaderboards.

@SzBeni2003 SzBeni2003 requested a review from Isti01 June 9, 2026 09:44
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db5ceae2-937c-43d8-801d-86120bebcee1

📥 Commits

Reviewing files that changed from the base of the PR and between fac8b71 and e63af66.

📒 Files selected for processing (1)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt

📝 Walkthrough

Walkthrough

Adds a server-side boolean setting addUserScoresForGroupScore and updates group leaderboard recomputation to optionally aggregate USER-owned task, riddle, challenge, and token scores into the owning user's group, after building a userId->group mapping and running user cache recomputation first.

Changes

GROUP Leaderboard USER-Ownership Contribution

Layer / File(s) Summary
Configuration setting for USER-ownership inclusion
backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardComponent.kt, backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt
Introduces the server-side boolean setting addUserScoresForGroupScore and adds an import used by the service.
Group score recalculation with USER-ownership aggregation
backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt
Reorders recompute to run users first, builds userIdToGroup lookup, and implements USER-ownership aggregation for tasks, riddles (with hint handling), challenges, and tokens (including per-rarity counts when enabled), each gated by the new setting.

Sequence Diagrams

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped through code with nimble paws,
A toggle born for group-score laws,
USER points now march into the fold,
Tasks, riddles, tokens — counts and gold,
The cache recomputes and tales are told.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Added new setting for calculating group scores by adding user's scores' directly and accurately describes the main change: introducing a new boolean setting (addUserScoresForGroupScore) that controls whether user-ownership points are included in group score calculations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/team-leaderboard-with-user-tasks

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmsch-cst Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-felezobal Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-golyakorte Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-seniortabor Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-skktv Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-snyt Ready Ready Preview, Comment Jun 13, 2026 8:52am
cmsch-vitorlaskupa Ready Ready Preview, Comment Jun 13, 2026 8:52am

Request Review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt (1)

171-185: 💤 Low value

Consider avoiding !! assertions by restructuring the filter.

The !! on it.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 use filterNotNull() on keys or restructure to make nullability explicit.

Also, line 175 has inconsistent spacing: it.key?.races?:false should be it.key?.races ?: false for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 83d72aa and fac8b71.

📒 Files selected for processing (2)
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardComponent.kt
  • backend/src/main/kotlin/hu/bme/sch/cmsch/component/leaderboard/LeaderBoardService.kt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant