Skip to content

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

Merged
SzBeni2003 merged 2 commits into
stagingfrom
feature/team-leaderboard-with-user-tasks
Jun 27, 2026
Merged

Added new setting for calculating group scores by adding user's scores#1041
SzBeni2003 merged 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 that controls whether user-owned points are included when calculating group/team leaderboard scores.
    • When enabled, group leaderboards now include contributions for tasks, riddles, challenges, and tokens; token scoring can also update per-rarity token counts where applicable.

@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

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d4594eb-2a49-432c-abe6-0f246f1258e0

📥 Commits

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

📒 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

📝 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.

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.

@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 27, 2026 2:52pm
cmsch-felezobal Ready Ready Preview, Comment Jun 27, 2026 2:52pm
cmsch-golyakorte Ready Ready Preview, Comment Jun 27, 2026 2:52pm
cmsch-seniortabor Ready Ready Preview, Comment Jun 27, 2026 2:52pm
cmsch-skktv Ready Ready Preview, Comment Jun 27, 2026 2:52pm
cmsch-snyt Ready Ready Preview, Comment Jun 27, 2026 2:52pm
cmsch-vitorlaskupa Ready Ready Preview, Comment Jun 27, 2026 2:52pm

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

@SzBeni2003 SzBeni2003 force-pushed the feature/team-leaderboard-with-user-tasks branch from e63af66 to d24eece Compare June 27, 2026 14:51
@SzBeni2003 SzBeni2003 merged commit 9a65ee7 into staging Jun 27, 2026
3 of 14 checks passed
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.

2 participants