Skip to content

feat: new level calculations and score in leaderboard #1931

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

Merged
merged 4 commits into from
Mar 28, 2025

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Mar 27, 2025

PR-Codex overview

This PR focuses on refactoring the JurorCard component and related files to incorporate a new Score feature, which calculates and displays a juror's coherence score. It also modifies various components to accommodate this new feature and updates the user level calculation logic.

Detailed summary

  • Added Score component to display the coherence score.
  • Updated JurorCard to include coherenceScore and removed totalResolvedDisputes.
  • Modified JurorLevel to use coherenceScore instead of voting totals.
  • Adjusted tooltip and layout styles across several components.
  • Changed user level calculation to use coherenceScore instead of percentage.
  • Updated user level data to reflect new coherence score criteria.
  • Refactored MobileCard and DesktopCard to utilize the new Score component.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced a fresh scoring display across juror cards and header views.
    • Added a new juror guide entry ("Juror Level 0: Diogenes") along with updated level descriptions.
  • Refactor

    • Consolidated multiple vote metrics into a single, unified coherence score.
    • Enhanced labels, tooltips, and layout adjustments for clearer and more consistent information presentation.
  • Bug Fixes

    • Corrected tooltip messages to accurately reflect the coherence score and its significance.

@kemuru kemuru requested a review from a team as a code owner March 27, 2025 12:59
Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

Walkthrough

The pull request refines the juror level evaluation by introducing a coherence score, replacing multiple vote metrics with a unified metric. A new juror level ("Diogenes") is added, and existing levels are updated with revised coherence score ranges. User interface components are modified to reflect these changes, including updated text, tooltips, and layout adjustments. New Score components are introduced for displaying score-related information across both desktop and mobile views, and interfaces throughout the codebase are updated to support the new coherenceScore-based logic.

Changes

File(s) Change Summary
web/src/components/Popup/MiniGuides/JurorLevels.tsx
web/src/pages/Home/TopJurors/JurorLevel.tsx
web/src/pages/Profile/JurorInfo/index.tsx
web/src/utils/userLevelCalculation.ts
Updated juror levels and evaluation criteria: added new "Diogenes" level; replaced vote count and dispute properties with unified coherenceScore and revised score ranges in level determination.
web/src/pages/Home/TopJurors/Header/Coherence.tsx
web/src/pages/Home/TopJurors/Header/DesktopHeader.tsx
Adjusted text and layout: updated tooltip and pseudo-element texts from "Coherence" to "Coherent Votes"; revised grid column definitions, spacing, and replaced component ordering.
web/src/pages/Home/TopJurors/Header/Score.tsx
web/src/pages/Home/TopJurors/JurorCard/Score.tsx
Introduced new Score components that render the coherence score using styled-components and tooltips with explanatory messages.
web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx
web/src/pages/Home/TopJurors/JurorCard/index.tsx
Updated interfaces and component props: removed totalResolvedDisputes and integrated new coherenceScore field for consistency between mobile and desktop cards.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant PI as Profile/JurorInfo
    participant GL as getUserLevelData
    participant JL as JurorLevel Component
    participant SC as Score Component

    U->>PI: Provide coherenceScore data
    PI->>GL: Call getUserLevelData(coherenceScore)
    GL-->>PI: Return level data (via score ranges)
    PI->>JL: Render juror level based on coherenceScore
    JL->>SC: Pass coherenceScore for display
    SC->>U: Display score and tooltip on hover
Loading

Possibly related PRs

Suggested labels

Type: Enhancement :sparkles:, Package: Web

Suggested reviewers

  • alcercu

Poem

I’m the rabbit on the run,
Hopping through a code-filled sun,
With a flick of my ear and a cheerful beat,
Coherence scores now make our updates neat.
Bugs scatter as our features shine bright! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 66d12b8 and 0c85e69.

📒 Files selected for processing (2)
  • web/src/pages/Home/TopJurors/Header/DesktopHeader.tsx (3 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/pages/Home/TopJurors/Header/DesktopHeader.tsx
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)

🪧 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 or @coderabbitai title 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.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67e5f9dd920fd7758611d7ad
😎 Deploy Preview https://deploy-preview-1931--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit 0c85e69
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67e5dcc28d11980008c0e449
😎 Deploy Preview https://deploy-preview-1931--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 0c85e69
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67e5dcc2e86a03000882097b
😎 Deploy Preview https://deploy-preview-1931--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67e5f8cde5f9377531f5063e
😎 Deploy Preview https://deploy-preview-1931--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (3)
web/src/pages/Home/TopJurors/Header/Score.tsx (1)

10-25: Consider avoiding !important in CSS rules.

Using !important in CSS (line 12) breaks the natural cascade of styles and makes maintenance more difficult. It's generally better to structure your selectors with higher specificity if you need to override styles.

- font-size: 12px !important;
+ font-size: 12px;

And similarly on line 21:

- font-size: 14px !important;
+ font-size: 14px;
web/src/pages/Home/TopJurors/JurorCard/Score.tsx (2)

15-17: Consider using number instead of string for coherenceScore.

The coherenceScore is typed as a string, which works for display purposes, but might require conversion if calculations are needed elsewhere. Consider using a number type and formatting it for display within the component.

interface IScore {
-  coherenceScore: string;
+  coherenceScore: number;
}

const Score: React.FC<IScore> = ({ coherenceScore }) => {
  return (
    <Container>
-      <Tooltip text={coherenceScore}>{coherenceScore}</Tooltip>
+      <Tooltip text={coherenceScore.toString()}>{coherenceScore.toString()}</Tooltip>
    </Container>
  );
};

1-27: Potential confusion with duplicate Score components.

There are now two different Score components in different directories:

  1. web/src/pages/Home/TopJurors/Header/Score.tsx
  2. web/src/pages/Home/TopJurors/JurorCard/Score.tsx (this file)

This could lead to confusion for developers. Consider consolidating these into a single, reusable component or using more specific naming to differentiate their purposes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a26fe61 and d0b6c7c.

📒 Files selected for processing (12)
  • web/src/components/Popup/MiniGuides/JurorLevels.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/Header/Coherence.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/Header/DesktopHeader.tsx (3 hunks)
  • web/src/pages/Home/TopJurors/Header/Score.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/Coherence.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (3 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/Score.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/index.tsx (1 hunks)
  • web/src/pages/Profile/JurorInfo/index.tsx (1 hunks)
  • web/src/utils/userLevelCalculation.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
web/src/pages/Home/TopJurors/Header/Coherence.tsx (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2025-03-27T13:00:21.271Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.
web/src/pages/Home/TopJurors/JurorCard/index.tsx (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2025-03-27T13:00:21.271Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.
web/src/pages/Home/TopJurors/JurorCard/Coherence.tsx (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1739
File: web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx:22-26
Timestamp: 2025-03-27T13:00:21.271Z
Learning: In the `Coherency` component (`web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx`), `totalResolvedVotes` is always greater than or equal to `totalCoherentVotes`. When both are zero, `0/0` results in `NaN`, which is acceptable in this context.
🧬 Code Definitions (3)
web/src/pages/Profile/JurorInfo/index.tsx (1)
web/src/utils/userLevelCalculation.ts (1)
  • getUserLevelData (16-23)
web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx (1)
web/src/utils/userLevelCalculation.ts (1)
  • getUserLevelData (16-23)
web/src/pages/Home/TopJurors/JurorCard/Coherence.tsx (1)
web/src/utils/getCoherencePercent.tsx (1)
  • getCoherencePercent (1-4)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
🔇 Additional comments (31)
web/src/pages/Home/TopJurors/JurorCard/Coherence.tsx (1)

27-29: LGTM! Improved tooltip display logic.

This change improves the user experience by displaying the raw vote ratio (e.g., "3/4") as the main content and showing the percentage (e.g., "75%") in the tooltip when hovering. This is more intuitive than the previous implementation.

web/src/pages/Profile/JurorInfo/index.tsx (2)

48-49: LGTM! Simplified user level calculation logic.

This change improves the code architecture by:

  1. Using a unified coherenceScore directly from the user data
  2. Simplifying the getUserLevelData function to accept just one parameter
  3. Removing unnecessary calculations in this component

This aligns with the broader refactoring to focus on coherence scores rather than multiple voting metrics.


48-49:

❓ Verification inconclusive

Verify coherenceScore is always available in user data.

Make sure that the coherenceScore field is reliably available in the user data returned by the API to prevent potential undefined values.

Run the following script to check if all users have coherenceScore:


🏁 Script executed:

#!/bin/bash
# Check if coherenceScore exists in GraphQL schema and sample responses

# Check schema definition
echo "Checking GraphQL schema for coherenceScore field..."
fd --type f --extension graphql | xargs grep -l "type User" | xargs cat

# Check any sample query responses if available
echo "Checking sample responses..."
fd --type f --name "*.json" --exec grep -l "user" {} \; | xargs grep "coherenceScore"

Length of output: 9424


Action: Confirm Coherence Score Field Consistency

The GraphQL schema definitively requires the coherenceScore field on the User entity (defined as a non-null BigInt), which means it should always be present when user data is provided. Note, however, that our automated sample response check did not return output due to command issues. Please manually verify that all API responses include the coherenceScore field, and if any anomalies are found, consider adding additional runtime validations.

web/src/pages/Home/TopJurors/Header/Coherence.tsx (2)

14-14: Improved label for better user clarity

Changing "Coherence" to "Coherent\u00a0Votes" makes the purpose of this component clearer to users. The non-breaking space ensures the label stays together on the same line.


27-31: Enhanced tooltip explanation

The updated tooltip message provides a more comprehensive explanation of the coherence ratio, with clear instructions about hovering to see the percentage. This improves user understanding of the metric being displayed.

web/src/pages/Home/TopJurors/JurorCard/index.tsx (2)

9-9: New coherenceScore property added to interface

Adding the coherenceScore property to the IJurorCard interface aligns with the PR objective of refactoring juror level evaluation to use a unified coherence score.


14-15: Updated component parameters to include coherenceScore

The JurorCard component correctly incorporates the new coherenceScore parameter and passes it to child components via allProps. This ensures the coherence score is available throughout the component hierarchy.

web/src/pages/Home/TopJurors/Header/DesktopHeader.tsx (3)

19-19: Added Score component import

The import of the new Score component is consistent with the PR objectives to display coherence scores prominently in the UI.


35-37: Refined grid layout for better component spacing

The grid layout has been updated with more precise fractional widths instead of min-content and repeat. This provides better control over column widths to accommodate the new Score component while maintaining responsiveness.


67-69: Logical component ordering in the header

The Score component is now rendered before Coherence, followed by Rewards. This ordering creates a natural flow from general score to specific metrics (coherence and rewards), improving the user experience.

web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (3)

85-85: Added coherenceScore to MobileCard interface

The coherenceScore property has been added to the IMobileCard interface, aligning with the PR objective of refactoring to use a unified coherence score system.


93-94: Updated component parameters to include coherenceScore

The MobileCard component correctly incorporates the new coherenceScore parameter, ensuring it's available for use within the component.


102-102: Simplified JurorLevel props with coherenceScore

The JurorLevel component now receives only the coherenceScore (converted from string to number) instead of multiple metrics. This simplification aligns with the PR objective of using a unified coherence score for level calculations.

web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (5)

13-13: New Score component imported

The addition of the Score component aligns with the coherence score refactoring seen across the codebase.


29-30: Layout adjustment looks good

The grid template columns have been updated to use fixed fractions instead of responsive sizes, and the column gap has been adjusted. This change supports the new layout requirements for displaying the coherence score.


42-42: Interface update for coherence score

The addition of the coherenceScore property to the interface aligns with the PR objective of using a unified coherence scoring system.


50-51: Props updated for coherence score

The component props now include coherenceScore, which aligns with the interface changes.


60-63: Updated component usage with coherence score

The implementation now uses the new Score component to display the coherence score and passes the numeric coherence score to the JurorLevel component. These changes align with the new coherence score-based approach.

web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx (2)

42-42: Simplified interface to use coherence score only

The interface has been streamlined to only require the coherenceScore property, which aligns with the PR objective of unifying juror evaluation around a coherence score.


45-46: Simplified component implementation

The component now directly uses the coherenceScore to determine the user level, which is more straightforward than the previous approach that required multiple vote metrics.

web/src/utils/userLevelCalculation.ts (4)

4-5: Updated interface for coherence score-based evaluation

The interface now uses minCoherenceScore and maxCoherenceScore instead of the previous metrics, which aligns with the PR objective of using a unified coherence score.


9-13: Updated level criteria with new Diogenes level

The level criteria now include a new level 0 (Diogenes) for lower coherence scores and updated ranges for existing levels. This provides a more granular approach to categorizing jurors based on their performance.


16-18: Simplified getUserLevelData function

The function now accepts coherenceScore directly as a number and checks if it falls within the defined ranges for each level. This is more straightforward than the previous approach.


22-22: Default to lowest level if no match

The function now returns the lowest level (Diogenes) if no matching criteria are found, which is a reasonable default.

web/src/components/Popup/MiniGuides/JurorLevels.tsx (7)

34-40: Added description for new Diogenes level

The addition of the Diogenes level description with a coherence score below 25 aligns with the updated level criteria in userLevelCalculation.ts.


44-45: Updated Pythagoras level description

The description now uses coherence score range (25-49) instead of previous metrics, which is consistent with the new scoring approach.


51-52: Updated Socrates level description

The description now uses coherence score range (50-69) instead of previous metrics, which is consistent with the new scoring approach.


58-59: Updated Plato level description

The description now uses coherence score range (70-89) instead of previous metrics, which is consistent with the new scoring approach.


65-66: Updated Aristotle level description

The description now uses coherence score range (90-100) instead of previous metrics, which is consistent with the new scoring approach.


72-77: Added data for new Diogenes level

The userLevelData array now includes an entry for the Diogenes level with appropriate coherent and resolved vote counts. This provides example data for the new level in the mini-guide.


82-82: Updated vote counts for existing levels

The coherent and resolved vote counts for existing levels have been updated to better represent the new coherence score ranges. For example, Aristotle now has 90 coherent votes out of 90 resolved votes, representing a perfect 100% coherence score.

Also applies to: 87-88, 93-94, 99-100

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 27, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 27, 2025
Copy link

codeclimate bot commented Mar 27, 2025

Code Climate has analyzed commit e4d1246 and detected 8 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 6
Style 2

View more on Code Climate.

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu merged commit 89c1bda into dev Mar 28, 2025
22 of 26 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