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

Double out match scheduling #135

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

cp-sidhdhi-p
Copy link
Collaborator

@cp-sidhdhi-p cp-sidhdhi-p commented Nov 13, 2024

  • schedule double out type matches.
  • remove gully, mixed and other type.
  • add custom type and let user schedule match as they want.
  • Round 1 represents winner bracket, round 2 represents loser bracket.
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-13.at.11.48.53.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a new tournament type: "Custom," allowing for flexible tournament structures.
    • Enhanced match scheduling for custom tournaments and double elimination formats.
  • Bug Fixes

    • Resolved handling of unsupported match types by allowing scheduling of custom matches without exceptions.
  • Documentation

    • Updated localization files to reflect changes in tournament types and descriptions.

These updates improve user experience in tournament creation and management, providing more tailored options.

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request modifies the TournamentType enum in the tournament_model.dart file by removing the values gully and mixed, and adding a new value custom. Corresponding changes are made in the serialization logic in tournament_model.g.dart, localization strings in app_en.arb, and the TournamentType extension methods in enum_extensions.dart. Additionally, the MatchScheduler class in match_scheduler.dart is updated to handle the new custom tournament type, enhancing match scheduling functionality.

Changes

File Path Change Summary
data/lib/api/tournament/tournament_model.dart Removed enum values gully (7) and mixed (8); added custom (7) with minTeamReq unchanged.
data/lib/api/tournament/tournament_model.g.dart Removed entries for TournamentType.gully, TournamentType.mixed, and TournamentType.other; added TournamentType.custom with value 7.
khelo/assets/locales/app_en.arb Removed tournament types "Gully", "Mixed", and "Other"; added "Custom" with its description.
khelo/lib/domain/extensions/enum_extensions.dart Updated getString and getDescriptionString methods to remove cases for gully, mixed, and other; added case for custom.
khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart Added handling for TournamentType.custom in scheduleMatchesByType; renamed and restructured scheduleDoubleEliminationMatches to scheduleDoubleOutMatches; added scheduleSingleBracketTeams.

Possibly related PRs

  • Implement tournament detail #119: The changes in this PR involve modifications to the TournamentModel and TournamentMember classes, which are directly related to the TournamentType enum changes in the main PR, as both involve tournament categorization and member management.
  • Add team in tournament #120: This PR adds functionality for team selection within tournaments, which is relevant to the changes in tournament types and member management in the main PR, as it impacts how tournaments are structured and managed.
  • Implement tournament overview tab #121: The introduction of a tournament overview tab in this PR relates to the overall tournament structure and categorization, which is impacted by the changes in the TournamentType enum in the main PR.
  • Implement tournament teams tab #122: This PR implements a matches tab that includes filtering options, which ties into the tournament structure and types defined in the main PR, as it affects how matches are categorized and displayed.
  • Implement tournament detail stats tab #124: The addition of a stats tab for tournaments is relevant as it builds on the tournament structure and member statistics, which are influenced by the changes in the main PR regarding tournament types.
  • Implement tournament detail members #128: This PR focuses on managing tournament members, which is directly related to the changes in the TournamentType enum and the overall tournament structure outlined in the main PR.
  • Show match group tag #134: The display of match group tags in the tournament detail overview is relevant as it enhances the presentation of tournament matches, which are categorized by the TournamentType enum in the main PR.

🐰 In the fields where tournaments play,
A new type has come to stay.
Gully and mixed have hopped away,
Custom's here to lead the way!
With matches planned, oh what a sight,
Let’s cheer for tournaments, day and night! 🎉


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

@cp-sidhdhi-p cp-sidhdhi-p marked this pull request as ready for review November 13, 2024 06:34
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: 1

🧹 Outside diff range and nitpick comments (4)
data/lib/api/tournament/tournament_model.g.dart (1)

63-63: Consider data migration and backwards compatibility.

The removal of tournament types (gully, mixed, other) raises some concerns:

  1. Existing tournaments using these types will need a migration strategy
  2. Database queries and filters may need updates
  3. API consumers might need to handle the changes

Consider:

  • Adding a data migration plan
  • Implementing backwards compatibility for API consumers
  • Documenting the changes in API documentation
  • Adding validation to handle legacy tournament types gracefully
data/lib/api/tournament/tournament_model.dart (1)

79-79: Document the custom tournament type configuration

The new custom type needs clear documentation about:

  • What configurations are supported
  • How it integrates with double out match scheduling
  • Any limitations or requirements

Add documentation comments above the enum value:

+  /// Custom tournament type that allows flexible configuration
+  /// Supports double out match scheduling with:
+  /// - Winner bracket (Round 1)
+  /// - Loser bracket (Round 2)
+  /// Minimum requirement: 2 teams
  custom(7, minTeamReq: 2);
khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (2)

598-599: Ensure the team list is not empty before accessing teams.first

In line 598, you're assigning teams.first to teamToReturn:

teamToReturn = teams.first;

Although teams.length == 1 is checked, it's good practice to ensure that teams is not empty before accessing the first element to prevent potential exceptions in future modifications.


576-607: Add documentation for scheduleSingleBracketTeams method

The scheduleSingleBracketTeams method contains complex logic for scheduling teams in a bracket. Adding a documentation comment explaining the purpose, parameters, and return value of the method would enhance code readability and maintainability.

Consider adding documentation like:

/// Schedules teams in a single-elimination bracket.
/// 
/// Processes finished and unfinished matches to determine loser teams,
/// schedules new matches, and returns a winning team if applicable.
/// 
/// - Parameters:
///   - matches: The list of existing matches.
///   - teams: The list of teams to schedule.
///   - isWinBracket: A boolean indicating if this is the winner's bracket.
/// - Returns: The winning team if determined; otherwise, null.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1ad7a and 21b0f59.

📒 Files selected for processing (6)
  • data/lib/api/tournament/tournament_model.dart (1 hunks)
  • data/lib/api/tournament/tournament_model.g.dart (1 hunks)
  • data/lib/service/tournament/tournament_service.dart (1 hunks)
  • khelo/assets/locales/app_en.arb (1 hunks)
  • khelo/lib/domain/extensions/enum_extensions.dart (2 hunks)
  • khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (3 hunks)
🔇 Additional comments (10)
data/lib/api/tournament/tournament_model.g.dart (1)

63-63: ⚠️ This is a generated file - modifications should be made to the source.

While the addition of TournamentType.custom: 7 is correct, remember that this is a generated file. Any changes should be made to the source file tournament_model.dart instead.

Let's verify the enum values are unique and sequential:

✅ Verification successful

✅ Generated enum map is correct and consistent with source

The enum values in the generated file perfectly match the source enum definition in tournament_model.dart. The values are unique, sequential (1-7), and TournamentType.custom: 7 is correctly generated from the source enum's custom(7, minTeamReq: 2) definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for uniqueness and sequentiality of enum values in tournament_model.dart

# Find and display the TournamentType enum definition
ast-grep --pattern 'enum TournamentType {
  $$$
}'

# Check for any duplicate values in the generated enum map
rg -A 10 '_\$TournamentTypeEnumMap = {' | grep -E ':[[:space:]]*[0-9]+' | sort -t':' -k2 -n | uniq -d -f1

Length of output: 428


Script:

#!/bin/bash
# Let's try a different approach to find and analyze the enum values

# Find the enum definition and its values
rg -A 15 "enum TournamentType" data/lib/api/tournament/tournament_model.dart

# Find the generated enum map
rg -A 10 "const _\\\$TournamentTypeEnumMap" data/lib/api/tournament/tournament_model.g.dart

Length of output: 838

data/lib/api/tournament/tournament_model.dart (2)

79-79: Verify enum value assignments

The custom type reuses the value 7 that was previously assigned to gully. While this maintains enum compactness, it could cause issues if the serialized value is used directly in the database or API.

Let's check for direct usage of enum values:

#!/bin/bash
# Search for direct usage of enum values
echo "Checking for hardcoded enum values..."
rg -A 3 "(?:type|tournament.*type).*=.*7" --type dart

# Check serialization logic
echo "Checking tournament type serialization..."
ast-grep --pattern 'TournamentType.$$$' tournament_model.g.dart

79-79: Verify data migration plan for removed tournament types

The removal of gully and mixed tournament types could impact existing tournaments in the database. Ensure there's a migration strategy in place.

Let's check for usage of the removed tournament types:

Consider adding a database migration script to:

  1. Identify tournaments with removed types
  2. Convert them to appropriate new types
  3. Log the migration results for verification
data/lib/service/tournament/tournament_service.dart (1)

189-191: Verify alignment with double out scheduling requirements

While changing the default type to knockOut aligns with removing the other type, please verify if this default aligns with the double out match scheduling requirements mentioned in the PR objectives.

Consider the following:

  1. Should we default to custom type instead to support double out scheduling?
  2. The hardcoded one-day duration (end_date: DateTime.now().add(const Duration(days: 1))) might not be suitable for all tournament types, especially double out tournaments that require multiple rounds.

Let's verify the tournament type usage:

khelo/lib/domain/extensions/enum_extensions.dart (2)

309-310: LGTM: Custom tournament type string handling added correctly.

The new case for TournamentType.custom follows the established pattern and properly uses localization.


328-329: LGTM: Custom tournament type description handling added correctly.

The new case for TournamentType.custom correctly includes the minTeamReq parameter and follows the localization pattern consistently with other tournament types.

khelo/assets/locales/app_en.arb (2)

304-304: LGTM! New tournament type added correctly.

The new custom tournament type is properly added and aligns with the PR objectives to streamline tournament options.


312-312: LGTM! Description is clear and consistent.

The description for the custom tournament type:

  • Clearly explains its flexible nature
  • Maintains consistency with other tournament type descriptions
  • Correctly includes the minimum teams placeholder

Let's verify the removal of old tournament types:

✅ Verification successful

Let me generate additional scripts to verify the tournament types more comprehensively.

This will help us:

  1. See all tournament type strings in the English locale file
  2. Check if there are other locale files where we need to verify consistency

Tournament types have been properly updated and cleaned

The verification confirms that:

  • All old tournament types (gully, mixed, other) have been completely removed
  • There is a clean, consistent set of new tournament types (knock_out, mini_robin, box_league, double_out, super_over, best_of, custom)
  • Each type has both a title and matching description with the required teams placeholder
  • Only English locale file exists, so no consistency issues with other languages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify complete removal of old tournament types

# Test: Search for removed tournament types. Expect: No matches.
rg -i "gully|mixed|other" khelo/assets/locales/app_en.arb

# Note: Excluding "other" from common strings
rg "tournament_type_(gully|mixed|other)" khelo/assets/locales/app_en.arb

Length of output: 2380


Script:

#!/bin/bash
# Let's check all tournament type related strings to ensure completeness
rg "tournament_type_" khelo/assets/locales/app_en.arb

# Also check if there are any other locale files to verify consistency
fd "app_.+\.arb$" khelo/assets/locales/

Length of output: 1566

khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (2)

66-67: Verify handling of TournamentType.custom in match scheduling

The addition of the TournamentType.custom case returns scheduledMatches directly. Please confirm that this behavior aligns with the intended functionality for custom tournaments. Ensure that any custom scheduling logic is properly handled elsewhere, and that scheduledMatches contains the correct matches for custom tournaments.


323-339: Ensure correct scheduling of finals in double elimination

When both win and los are not null, the code schedules a finals match between these teams. Please verify that this logic correctly schedules the final match and that it doesn't introduce any duplicate matches. Ensure that the isMatchAdded check accurately detects existing matches.

@canopas canopas deleted a comment from coderabbitai bot Nov 14, 2024
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: 3

🧹 Outside diff range and nitpick comments (1)
khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (1)

Line range hint 1-607: Consider splitting MatchScheduler into smaller, focused classes

The MatchScheduler class is handling multiple tournament types with complex logic for each. Consider:

  1. Creating separate scheduler classes for each tournament type
  2. Extracting common scheduling logic into a base class
  3. Using the Strategy pattern to select the appropriate scheduler

This would improve:

  • Testability: Each scheduler can be tested in isolation
  • Maintainability: Changes to one tournament type won't affect others
  • Readability: Logic for each tournament type would be self-contained
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 21b0f59 and cd66a79.

📒 Files selected for processing (1)
  • khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (8 hunks)
🔇 Additional comments (1)
khelo/lib/ui/flow/tournament/match_selection/match_scheduler.dart (1)

61-61: LGTM: Changes align with PR objectives

The modifications correctly implement the custom tournament type and update the double out match scheduling call.

Also applies to: 66-67

@canopas canopas deleted a comment from coderabbitai bot Nov 14, 2024
@canopas canopas deleted a comment from coderabbitai bot Nov 14, 2024
@canopas canopas deleted a comment from coderabbitai bot Nov 14, 2024
@cp-mayank cp-mayank merged commit bf53f2c into main Nov 14, 2024
2 checks passed
@cp-mayank cp-mayank deleted the sidhdhi/schedule-double-out-matches branch November 14, 2024 10:50
@coderabbitai coderabbitai bot mentioned this pull request Nov 25, 2024
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