Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add lecturer course leaderboards containing collected points rolling over last 7 or 14 days #4521

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

sjschlapbach
Copy link
Member

@sjschlapbach sjschlapbach commented Feb 20, 2025

Summary by CodeRabbit

  • New Features
    • Added options for rolling leaderboards, enabling users to view performance over the past 7 or 14 days.
    • Enhanced visual presentation of leaderboard filters and updated display of date ranges for rolling views.
    • Improved localization with new language entries reflecting the rolling leaderboard options.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 20, 2025
Copy link

coderabbitai bot commented Feb 20, 2025

📝 Walkthrough

Walkthrough

This pull request extends the leaderboard functionality by introducing two new leaderboard types—7rolling and 14rolling. The changes update state types, UI select components, and logic in both the Individual and Suspended Course Leaderboard components. Additionally, the GraphQL query and service functions have been modified to handle additional parameters for rolling leaderboard calculations, and localization files in German and English have been updated with the new options.

Changes

Files Change Summary
apps/frontend-manage/src/components/courses/IndividualLeaderboard.tsx
apps/frontend-manage/src/components/courses/SuspendedCourseLeaderboard.tsx
Expanded leaderboardType options to include '7rolling' and '14rolling'; updated type definitions, UI component options, and associated conditional logic.
packages/graphql/src/schema/query.ts Updated getCourseLeaderboard method signature to add new required arguments: rollingSelection, customSelection, startDate, endDate, and days.
packages/graphql/src/services/courses.ts Introduced the new async function computeRollingLeaderboardEntries for calculating rolling leaderboard entries and modified getCourseLeaderboard to integrate it.
packages/i18n/messages/de.ts
packages/i18n/messages/en.ts
Added new localization entries for rolling leaderboard types (rolling7 and rolling14) in both German and English language files.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant F as Frontend
    participant G as GraphQL API
    participant S as Course Service

    U->>F: Select leaderboard type ('7rolling'/'14rolling')
    F->>G: Request getCourseLeaderboard (with rollingSelection flag and days)
    G->>S: Forward request with parameters
    alt Rolling leaderboard selected
        S->>S: Execute computeRollingLeaderboardEntries
    else Other leaderboard type
        S->>S: Execute existing leaderboard logic
    end
    S-->>G: Return leaderboard data
    G-->>F: Respond with data
    F-->>U: Display updated leaderboard
Loading

Possibly related PRs

Suggested labels

size:XXL

Suggested reviewers

  • rschlaefli
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot bot added the enhancement label Feb 20, 2025
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/graphql/src/services/courses.ts (1)

628-629: Enhance code consistency for 'biweekly' mode.

The mode === 'biweekly' branch now correctly leverages computeRollingLeaderboardEntries with a fixed 14-day range. Consider unifying or consolidating modes like 'biweekly' and '14rolling' to avoid logic duplication if they serve the same purpose.

apps/frontend-manage/src/components/courses/SuspendedCourseLeaderboard.tsx (1)

150-156: Consider recompute option for rolling leaderboards.

Right now, the “Recompute” button only triggers timeline updates for 'weekly' and 'custom'. You might want to clarify or extend this feature for '7rolling' and '14rolling' as well, in case a manual refresh of data is desired.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17df6c0 and 1ffe3d3.

⛔ Files ignored due to path filters (6)
  • packages/graphql/src/graphql/ops/QGetCourseLeaderboard.graphql is excluded by !**/**/graphql/ops/**
  • packages/graphql/src/ops.schema.json is excluded by !**/**/ops.schema.json
  • packages/graphql/src/ops.ts is excluded by !**/**/ops.ts
  • packages/graphql/src/public/client.json is excluded by !**/**/public/**
  • packages/graphql/src/public/schema.graphql is excluded by !**/**/public/**
  • packages/graphql/src/public/server.json is excluded by !**/**/public/**
📒 Files selected for processing (6)
  • apps/frontend-manage/src/components/courses/IndividualLeaderboard.tsx (2 hunks)
  • apps/frontend-manage/src/components/courses/SuspendedCourseLeaderboard.tsx (5 hunks)
  • packages/graphql/src/schema/query.ts (1 hunks)
  • packages/graphql/src/services/courses.ts (4 hunks)
  • packages/i18n/messages/de.ts (1 hunks)
  • packages/i18n/messages/en.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: cypress-run
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: check
🔇 Additional comments (9)
packages/graphql/src/services/courses.ts (2)

351-526: Validate date range logic and random ID generation.

  1. The function uses (days - 1) when filtering out certain quizzes while using days for timeline entries. This leads to slightly different boundary intervals between live quizzes and timeline entries. Please confirm if this staggering of dates (one day difference) is intentional or if you want both intervals to match.
  2. The random ID (Math.floor(random(1000000000))) could potentially collide when the dataset grows large. Consider using a more robust unique identifier or simply omit the ID if it's only used for display purposes.
  3. While the current approach may suffice for smaller datasets, you may want to move part of the aggregation logic to database queries for efficiency if the leaderboard grows over time.
    [verify, refactor_suggestion_good_to_have]

1107-1112: Rolling leaderboard parameters introduced.

The added rollingSelection and days parameters cleanly extend the leaderboard functionality. However, note that the code if (!days) return null silently fails instead of throwing a more descriptive error for missing days. Consider warning or throwing an explicit message for better debugging.

apps/frontend-manage/src/components/courses/SuspendedCourseLeaderboard.tsx (2)

42-49: Check default fallback for non-rolling leaderboard.

Currently, days defaults to 14 unless explicitly set to 7 for '7rolling'. For other leaderboard types, this extra value does no harm because rollingSelection is false. Ensure that logic is clear to future maintainers, or conditionally pass days only when rollingSelection is true for extra clarity.


71-81: Align displayed rolling date range with backend logic.

When the leaderboard type is '7rolling' or '14rolling', the displayed date range in the UI is computed with dayjs(data.getCourseLeaderboard.computedAt).subtract(...). Meanwhile, the backend uses (days - 1) for certain queries and days for timeline entries. Consider verifying these offsets to ensure the displayed range fully matches the server’s data range.

Also applies to: 123-147

apps/frontend-manage/src/components/courses/IndividualLeaderboard.tsx (2)

41-42: Expanded leaderboard type state.

The new '7rolling' and '14rolling' options correctly extend the existing types. No immediate issues noted.


81-85: Additional rolling options and trigger width.

  1. Adding '7rolling' and '14rolling' nicely integrates rolling leaderboards into the UI.
  2. Widening the select trigger (w-52) could affect layout; ensure that the rest of the page still aligns as intended.
packages/graphql/src/schema/query.ts (1)

504-508: LGTM! The new arguments for rolling leaderboard are well-defined.

The addition of rollingSelection and days arguments to the getCourseLeaderboard query is well-structured:

  • rollingSelection is correctly marked as required to explicitly enable rolling leaderboard calculation
  • days is correctly marked as optional since it's only needed when rollingSelection is true
packages/i18n/messages/en.ts (1)

1895-1896: LGTM! The localization entries for rolling leaderboard options are well-defined.

The new entries for 7-day and 14-day rolling leaderboards are:

  • Added in the correct location within the course section
  • Follow consistent naming and labeling patterns
  • Match the functionality described in the AI summary
packages/i18n/messages/de.ts (1)

1927-1928: LGTM! The new leaderboard type translations are well-implemented.

The added German translations for rolling 7-day and 14-day leaderboard types are accurate, consistent with the existing translations, and properly convey the rolling nature of the new leaderboard views.

@sjschlapbach sjschlapbach merged commit e8baacc into v3-student-timeline Feb 20, 2025
14 of 15 checks passed
@sjschlapbach sjschlapbach deleted the rolling-leaderboards-lecturer branch February 20, 2025 14:20
Copy link

cypress bot commented Feb 20, 2025

klicker-uzh    Run #4379

Run Properties:  status check passed Passed #4379  •  git commit 3b4aa12454 ℹ️: Merge 1ffe3d3628489eb9cd29bfc3387ae23a719b2411 into 17df6c041e1ff29326d9555567a5...
Project klicker-uzh
Branch Review rolling-leaderboards-lecturer
Run status status check passed Passed #4379
Run duration 26m 44s
Commit git commit 3b4aa12454 ℹ️: Merge 1ffe3d3628489eb9cd29bfc3387ae23a719b2411 into 17df6c041e1ff29326d9555567a5...
Committer Julius Schlapbach
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 349
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement size:L This PR changes 100-499 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

1 participant