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

Fix Joined On info in Clubs/Players endpoint #68

Merged
merged 1 commit into from
Jun 16, 2024

Conversation

felipeall
Copy link
Owner

@felipeall felipeall commented Jun 16, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced player data extraction to include joining dates, improving the accuracy of player information.
  • Bug Fixes

    • Adjusted the logic for retrieving player joining dates, resolving inconsistencies in displayed data.

Copy link

coderabbitai bot commented Jun 16, 2024

Walkthrough

The recent updates enhance the players' service within the clubs module and improve the handling of XPath queries. These changes primarily focus on logging player information and refining how players' joining dates are extracted and processed from HTML content.

Changes

File Change Summary
app/services/clubs/players.py Added logging for self.past, updated the population of page_players_joined_on, and refined extraction of players_joined_on.
app/utils/xpath.py Added JOINED_ON and PAGE_JOINED_ON attributes to the Players class and its nested Present and Past classes.

Sequence Diagram(s)

sequenceDiagram
    participant Service as PlayersService
    participant XPathUtils as XPathUtilities
    participant Logger as Logger
    participant Page as PageContent

    Service->>XPathUtils: Get `page_players_joined_on`
    XPathUtils-->>Service: Return joined_on XPath data
    Service->>Logger: Log value of `self.past`
    Service->>Page: Extract `players_joined_on` data
    Page-->>Service: Return players' joining dates
Loading

Poem

Amidst the code, a change was born,
Players' paths now newly worn.
With logs and dates from deep within,
We trace their steps where they begin.
In data's flow, a clearer sight,
Club's history brought to light. 🌟🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@felipeall felipeall merged commit 64079fe into main Jun 16, 2024
1 check passed
@felipeall felipeall deleted the fix/club-players-joined-on branch June 16, 2024 21:10
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3555d4f and fedfbce.

Files selected for processing (2)
  • app/services/clubs/players.py (3 hunks)
  • app/utils/xpath.py (1 hunks)
Additional comments not posted (3)
app/services/clubs/players.py (1)

78-78: Ensure that the xpath expression used in the list comprehension correctly extracts the 'joined_on' data as intended.

Verification successful

The JOINED_ON xpath is defined as ".//text()" in app/utils/xpath.py, and the page_players_joined_on variable is populated using the xpath expressions Clubs.Players.Past.PAGE_SIGNED_FROM or Clubs.Players.Present.PAGE_SIGNED_FROM, which are defined as //div[@id='yw1']//td[8] and //div[@id='yw1']//td[9] respectively. This indicates that the xpath expressions used should correctly extract the 'joined_on' data as intended.

  • JOINED_ON is defined as ".//text()" in app/utils/xpath.py.
  • page_players_joined_on is populated using Clubs.Players.Past.PAGE_SIGNED_FROM or Clubs.Players.Present.PAGE_SIGNED_FROM.
  • PAGE_SIGNED_FROM is defined as //div[@id='yw1']//td[8] and //div[@id='yw1']//td[9].

These definitions align correctly with the intended data extraction for 'joined_on'.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the xpath used in the 'joined_on' extraction returns expected results.

# Test: Run a sample extraction using the xpath to ensure correct data is retrieved.
ast-grep --lang python --pattern $'self.page.xpath(Clubs.Players.JOINED_ON)'

Length of output: 77



Script:

#!/bin/bash
# Locate the definition of 'JOINED_ON' within the 'Clubs.Players' context
ast-grep --lang python --pattern $'JOINED_ON = $_' --search 'Clubs.Players'

Length of output: 274



Script:

#!/bin/bash
# Locate the definition of 'JOINED_ON' within the 'Clubs.Players' context
ast-grep --lang python --pattern $'JOINED_ON = $_' 'Clubs/Players'

Length of output: 126



Script:

#!/bin/bash
# Locate the definition of 'JOINED_ON' in the entire codebase
ast-grep --lang python --pattern $'JOINED_ON = $_'

Length of output: 108



Script:

#!/bin/bash
# Locate the definition and usage of 'page_players_joined_on' in the codebase
ast-grep --lang python --pattern $'page_players_joined_on = $_'

Length of output: 335



Script:

#!/bin/bash
# Locate the definitions of 'PAGE_SIGNED_FROM' in the codebase
ast-grep --lang python --pattern $'PAGE_SIGNED_FROM = $_'

Length of output: 222

app/utils/xpath.py (2)

152-152: Adding the 'JOINED_ON' xpath at the top level of the 'Players' class is a good practice for reusability across different methods.


156-156: Ensure the newly added xpath attributes for 'PAGE_JOINED_ON' are correct and match the actual HTML structure of the page.

Also applies to: 163-163

@@ -38,6 +38,7 @@ def __update_season_id(self):
def __update_past_flag(self) -> None:
"""Check if the season is the current or if it's a past one and update the flag accordingly."""
self.past = "Current club" in self.get_list_by_xpath(Clubs.Players.PAST_FLAG)
print(f"{self.past=}")
Copy link

Choose a reason for hiding this comment

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

Consider replacing the print statement with a proper logging mechanism for better control over log levels and outputs.

Comment on lines +55 to +57
page_players_joined_on = self.page.xpath(
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
)
Copy link

Choose a reason for hiding this comment

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

It appears there is a copy-paste error here. The xpath should be for 'JOINED_ON' instead of reusing 'SIGNED_FROM'.

- page_players_joined_on = self.page.xpath(
-     Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
- )
+ page_players_joined_on = self.page.xpath(
+     Clubs.Players.Past.PAGE_JOINED_ON if self.past else Clubs.Players.Present.PAGE_JOINED_ON,
+ )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
page_players_joined_on = self.page.xpath(
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
)
page_players_joined_on = self.page.xpath(
Clubs.Players.Past.PAGE_JOINED_ON if self.past else Clubs.Players.Present.PAGE_JOINED_ON,
)

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